pub struct Element {
pub id: u32,
pub tag: &'static str,
pub class: Option<String>,
pub attrs: HashMap<&'static str, String>,
pub text: Option<String>,
pub children: Vec<Element>,
pub handlers: Vec<EventHandler>,
}Expand description
The fundamental UI node. Every tag in a view! block becomes one of these.
Fields§
§id: u32Unique ID for event routing back from Java → Rust.
tag: &'static strTag name: “h1”, “button”, “p”, “img”, “input”, “div”, etc.
class: Option<String>CSS class string.
attrs: HashMap<&'static str, String>Generic attributes (src, alt, placeholder, href, …).
text: Option<String>Text content for leaf nodes.
children: Vec<Element>Child elements.
handlers: Vec<EventHandler>Registered event handlers.
Implementations§
Source§impl Element
impl Element
Sourcepub fn attr(self, key: &'static str, value: impl Into<String>) -> Self
pub fn attr(self, key: &'static str, value: impl Into<String>) -> Self
Set a generic attribute.
Sourcepub fn on(self, handler: EventHandler) -> Self
pub fn on(self, handler: EventHandler) -> Self
Attach an event handler.
<button>
Sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
Serialise this element tree to JSON for the JNI bridge.
Produces:
{
"id": 1,
"tag": "button",
"class": "primary-btn",
"text": "Tap me",
"attrs": {},
"handlers": ["click"],
"children": []
}Sourcepub fn collect_handlers(&self, out: &mut Vec<(u32, EventHandler)>)
pub fn collect_handlers(&self, out: &mut Vec<(u32, EventHandler)>)
Collect all elements with their handlers into a flat list. Used by the event dispatcher to find the right handler by element ID.
Sourcepub fn debug_render(&self, indent: usize) -> String
pub fn debug_render(&self, indent: usize) -> String
Debug render as an indented tag tree (host mode only).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Element
impl !RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl UnsafeUnpin for Element
impl !UnwindSafe for Element
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more