pub struct NodeData {
pub node_type: NodeType,
pub dataset: OptionRefAny,
pub ids_and_classes: IdOrClassVec,
pub attributes: AttributeVec,
pub callbacks: CoreCallbackDataVec,
pub css_props: CssPropertyWithConditionsVec,
pub tab_index: OptionTabIndex,
pub contenteditable: bool,
/* private fields */
}Expand description
Represents all data associated with a single DOM node, such as its type, classes, IDs, callbacks, and inline styles.
Fields§
§node_type: NodeTypediv, p, img, etc.
dataset: OptionRefAnydata-* attributes for this node, useful to store UI-related data on the node itself.
ids_and_classes: IdOrClassVecStores all ids and classes as one vec - size optimization since most nodes don’t have any classes or IDs.
attributes: AttributeVecStrongly-typed HTML attributes (aria-*, href, alt, etc.)
callbacks: CoreCallbackDataVecCallbacks attached to this node:
On::MouseUp -> Callback(my_button_click_handler)
css_props: CssPropertyWithConditionsVecConditional CSS properties with dynamic selectors. These are evaluated at runtime based on OS, viewport, container, theme, and pseudo-state. Uses “last wins” semantics - properties are evaluated in order, last match wins.
tab_index: OptionTabIndexTab index (commonly used property).
contenteditable: boolWhether this node is contenteditable (accepts text input).
Equivalent to HTML contenteditable="true" attribute.
Implementations§
Source§impl NodeData
impl NodeData
Sourcepub const fn create_node(node_type: NodeType) -> Self
pub const fn create_node(node_type: NodeType) -> Self
Creates a new NodeData instance from a given NodeType.
Sourcepub const fn create_body() -> Self
pub const fn create_body() -> Self
Shorthand for NodeData::create_node(NodeType::Body).
Sourcepub const fn create_div() -> Self
pub const fn create_div() -> Self
Shorthand for NodeData::create_node(NodeType::Div).
Sourcepub fn create_text<S: Into<AzString>>(value: S) -> Self
pub fn create_text<S: Into<AzString>>(value: S) -> Self
Shorthand for NodeData::create_node(NodeType::Text(value.into())).
Sourcepub fn create_image(image: ImageRef) -> Self
pub fn create_image(image: ImageRef) -> Self
Shorthand for NodeData::create_node(NodeType::Image(image_id)).
pub fn create_iframe(data: RefAny, callback: impl Into<IFrameCallback>) -> Self
Sourcepub fn is_node_type(&self, searched_type: NodeType) -> bool
pub fn is_node_type(&self, searched_type: NodeType) -> bool
Checks whether this node is of the given node type (div, image, text).
Sourcepub fn has_class(&self, class: &str) -> bool
pub fn has_class(&self, class: &str) -> bool
Checks whether this node has the searched class attached.
pub fn is_text_node(&self) -> bool
pub fn is_iframe_node(&self) -> bool
pub const fn get_node_type(&self) -> &NodeType
pub fn get_dataset_mut(&mut self) -> &mut OptionRefAny
pub const fn get_dataset(&self) -> &OptionRefAny
pub const fn get_ids_and_classes(&self) -> &IdOrClassVec
pub const fn get_callbacks(&self) -> &CoreCallbackDataVec
pub const fn get_css_props(&self) -> &CssPropertyWithConditionsVec
pub fn get_clip_mask(&self) -> Option<&ImageMask>
pub fn get_tab_index(&self) -> Option<&TabIndex>
pub fn get_accessibility_info(&self) -> Option<&Box<AccessibilityInfo>>
Sourcepub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Returns whether this node is an anonymous box generated for table layout.
pub fn set_node_type(&mut self, node_type: NodeType)
pub fn set_dataset(&mut self, data: OptionRefAny)
pub fn set_ids_and_classes(&mut self, ids_and_classes: IdOrClassVec)
pub fn set_callbacks(&mut self, callbacks: CoreCallbackDataVec)
pub fn set_css_props(&mut self, css_props: CssPropertyWithConditionsVec)
pub fn set_clip_mask(&mut self, clip_mask: ImageMask)
pub fn set_tab_index(&mut self, tab_index: TabIndex)
pub fn set_contenteditable(&mut self, contenteditable: bool)
pub fn is_contenteditable(&self) -> bool
pub fn set_accessibility_info(&mut self, accessibility_info: AccessibilityInfo)
Sourcepub fn set_anonymous(&mut self, is_anonymous: bool)
pub fn set_anonymous(&mut self, is_anonymous: bool)
Marks this node as an anonymous box (generated for table layout).
Sourcepub fn set_key<K: Hash>(&mut self, key: K)
pub fn set_key<K: Hash>(&mut self, key: K)
Sets a stable key for this node used in reconciliation.
This key is used to track node identity across DOM updates, enabling the framework to distinguish between “moving” a node and “destroying/creating” one. This is crucial for correct lifecycle events when lists are reordered.
§Example
node_data.set_key("user-123");Sourcepub fn set_merge_callback<C: Into<DatasetMergeCallback>>(&mut self, callback: C)
pub fn set_merge_callback<C: Into<DatasetMergeCallback>>(&mut self, callback: C)
Sets a dataset merge callback for this node.
The merge callback is invoked during reconciliation when a node from the previous frame is matched with a node in the new frame. It allows heavy resources (video decoders, GL textures, network connections) to be transferred from the old node to the new node instead of being destroyed.
§Type Safety
The callback stores the TypeId of T. During execution, both the old
and new datasets must match this type, otherwise the merge is skipped.
§Example
struct VideoPlayer {
url: String,
decoder: Option<DecoderHandle>,
}
extern "C" fn merge_video(new_data: RefAny, old_data: RefAny) -> RefAny {
// Transfer the heavy decoder handle from old to new
if let (Some(mut new), Some(old)) = (
new_data.downcast_mut::<VideoPlayer>(),
old_data.downcast_ref::<VideoPlayer>()
) {
new.decoder = old.decoder.take();
}
new_data
}
node_data.set_merge_callback(merge_video);Sourcepub fn get_merge_callback(&self) -> Option<DatasetMergeCallback>
pub fn get_merge_callback(&self) -> Option<DatasetMergeCallback>
Gets the merge callback for this node, if set.
pub fn add_callback<C: Into<CoreCallback>>( &mut self, event: EventFilter, data: RefAny, callback: C, )
pub fn add_id(&mut self, s: AzString)
pub fn add_class(&mut self, s: AzString)
Sourcepub fn add_css_property(&mut self, p: CssProperty)
pub fn add_css_property(&mut self, p: CssProperty)
Add an unconditional CSS property (always applies)
Sourcepub fn add_hover_css_property(&mut self, p: CssProperty)
pub fn add_hover_css_property(&mut self, p: CssProperty)
Add a CSS property that applies only on hover
Sourcepub fn add_active_css_property(&mut self, p: CssProperty)
pub fn add_active_css_property(&mut self, p: CssProperty)
Add a CSS property that applies only when active (clicked)
Sourcepub fn add_focus_css_property(&mut self, p: CssProperty)
pub fn add_focus_css_property(&mut self, p: CssProperty)
Add a CSS property that applies only when focused
Sourcepub fn calculate_node_data_hash(&self) -> DomNodeHash
pub fn calculate_node_data_hash(&self) -> DomNodeHash
Calculates a deterministic node hash for this node.
Sourcepub fn calculate_structural_hash(&self) -> DomNodeHash
pub fn calculate_structural_hash(&self) -> DomNodeHash
Calculates a structural hash for DOM reconciliation that ignores text content.
This hash is used for matching nodes across DOM frames where the text content may have changed (e.g., contenteditable text being edited). It hashes:
- Node type discriminant (but NOT the text content for Text nodes)
- IDs and classes
- Attributes (but NOT contenteditable state which may change with focus)
- Callback events and types
This allows a Text(“Hello”) node to match Text(“Hello World”) during reconciliation, preserving cursor position and selection state.
pub fn with_tab_index(self, tab_index: TabIndex) -> Self
pub fn with_contenteditable(self, contenteditable: bool) -> Self
pub fn with_node_type(self, node_type: NodeType) -> Self
pub fn with_callback<C: Into<CoreCallback>>( self, event: EventFilter, data: RefAny, callback: C, ) -> Self
pub fn with_dataset(self, data: OptionRefAny) -> Self
pub fn with_ids_and_classes(self, ids_and_classes: IdOrClassVec) -> Self
pub fn with_callbacks(self, callbacks: CoreCallbackDataVec) -> Self
pub fn with_css_props(self, css_props: CssPropertyWithConditionsVec) -> Self
Sourcepub fn with_key<K: Hash>(self, key: K) -> Self
pub fn with_key<K: Hash>(self, key: K) -> Self
Assigns a stable key to this node for reconciliation.
This is crucial for performance and correct state preservation when lists of items change order or items are inserted/removed. Without keys, the reconciliation algorithm falls back to hash-based matching.
§Example
NodeData::create_div()
.with_key("user-avatar-123")Sourcepub fn with_merge_callback<C: Into<DatasetMergeCallback>>(
self,
callback: C,
) -> Self
pub fn with_merge_callback<C: Into<DatasetMergeCallback>>( self, callback: C, ) -> Self
Registers a callback to merge dataset state from the previous frame.
This is used for components that maintain heavy internal state (video players, WebGL contexts, network connections) that should not be destroyed and recreated on every render frame.
The callback receives both datasets as RefAny (cheap shallow clones) and
returns the RefAny that should be used for the new node.
§Example
struct VideoPlayer {
url: String,
decoder_handle: Option<DecoderHandle>,
}
extern "C" fn merge_video(new_data: RefAny, old_data: RefAny) -> RefAny {
if let (Some(mut new), Some(old)) = (
new_data.downcast_mut::<VideoPlayer>(),
old_data.downcast_ref::<VideoPlayer>()
) {
new.decoder_handle = old.decoder_handle.take();
}
new_data
}
NodeData::create_div()
.with_dataset(RefAny::new(VideoPlayer::new("movie.mp4")).into())
.with_merge_callback(merge_video)Sourcepub fn set_inline_style(&mut self, style: &str)
pub fn set_inline_style(&mut self, style: &str)
Parse CSS from a string and add as unconditional properties
Sourcepub fn with_inline_style(self, style: &str) -> Self
pub fn with_inline_style(self, style: &str) -> Self
Builder method for setting inline CSS styles for the normal state
Sourcepub fn set_inline_hover_style(&mut self, style: &str)
pub fn set_inline_hover_style(&mut self, style: &str)
Sets inline CSS styles for the hover state, parsing from a CSS string
Sourcepub fn with_inline_hover_style(self, style: &str) -> Self
pub fn with_inline_hover_style(self, style: &str) -> Self
Builder method for setting inline CSS styles for the hover state
Sourcepub fn set_inline_active_style(&mut self, style: &str)
pub fn set_inline_active_style(&mut self, style: &str)
Sets inline CSS styles for the active state, parsing from a CSS string
Sourcepub fn with_inline_active_style(self, style: &str) -> Self
pub fn with_inline_active_style(self, style: &str) -> Self
Builder method for setting inline CSS styles for the active state
Sourcepub fn set_inline_focus_style(&mut self, style: &str)
pub fn set_inline_focus_style(&mut self, style: &str)
Sets inline CSS styles for the focus state, parsing from a CSS string
Sourcepub fn with_inline_focus_style(self, style: &str) -> Self
pub fn with_inline_focus_style(self, style: &str) -> Self
Builder method for setting inline CSS styles for the focus state
pub fn swap_with_default(&mut self) -> Self
pub fn copy_special(&self) -> Self
pub fn is_focusable(&self) -> bool
Sourcepub fn has_activation_behavior(&self) -> bool
pub fn has_activation_behavior(&self) -> bool
Returns true if this element has “activation behavior” per HTML5 spec.
Elements with activation behavior can be activated via Enter or Space key when focused, which generates a synthetic click event.
Per HTML5 spec, elements with activation behavior include:
- Button elements
- Input elements (submit, button, reset, checkbox, radio)
- Anchor elements with href
- Any element with a click callback (implicit activation)
See: https://html.spec.whatwg.org/multipage/interaction.html#activation-behavior
Sourcepub fn is_activatable(&self) -> bool
pub fn is_activatable(&self) -> bool
Returns true if this element is currently activatable.
An element is activatable if it has activation behavior AND is not disabled. This checks for common disability patterns (aria-disabled, disabled attribute).
Sourcepub fn get_effective_tabindex(&self) -> Option<i32>
pub fn get_effective_tabindex(&self) -> Option<i32>
Returns the tab index for this element.
Tab index determines keyboard navigation order:
None: Not in tab order (unless naturally focusable)Some(-1): Focusable programmatically but not via TabSome(0): In natural tab orderSome(n > 0): In tab order with priority n (higher = later)
pub fn get_iframe_node(&mut self) -> Option<&mut IFrameNode>
pub fn get_render_image_callback_node<'a>( &'a mut self, ) -> Option<(&'a mut CoreImageCallback, ImageRefHash)>
pub fn debug_print_start( &self, css_cache: &CssPropertyCache, node_id: &NodeId, node_state: &StyledNodeState, ) -> String
pub fn debug_print_end(&self) -> String
Trait Implementations§
Source§impl Extend<NodeData> for NodeDataVec
impl Extend<NodeData> for NodeDataVec
Source§fn extend<T: IntoIterator<Item = NodeData>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = NodeData>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<NodeData> for NodeDataVec
impl FromIterator<NodeData> for NodeDataVec
Source§impl Ord for NodeData
impl Ord for NodeData
Source§impl PartialOrd for NodeData
impl PartialOrd for NodeData
impl Eq for NodeData
impl Send for NodeData
impl StructuralPartialEq for NodeData
Auto Trait Implementations§
impl Freeze for NodeData
impl RefUnwindSafe for NodeData
impl Sync for NodeData
impl Unpin for NodeData
impl UnwindSafe for NodeData
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more