Skip to main content

NodeData

Struct NodeData 

Source
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: NodeType

div, p, img, etc.

§dataset: OptionRefAny

data-* attributes for this node, useful to store UI-related data on the node itself.

§ids_and_classes: IdOrClassVec

Stores all ids and classes as one vec - size optimization since most nodes don’t have any classes or IDs.

§attributes: AttributeVec

Strongly-typed HTML attributes (aria-*, href, alt, etc.)

§callbacks: CoreCallbackDataVec

Callbacks attached to this node:

On::MouseUp -> Callback(my_button_click_handler)

§css_props: CssPropertyWithConditionsVec

Conditional 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: OptionTabIndex

Tab index (commonly used property).

§contenteditable: bool

Whether this node is contenteditable (accepts text input). Equivalent to HTML contenteditable="true" attribute.

Implementations§

Source§

impl NodeData

Source

pub const fn create_node(node_type: NodeType) -> Self

Creates a new NodeData instance from a given NodeType.

Source

pub const fn create_body() -> Self

Shorthand for NodeData::create_node(NodeType::Body).

Source

pub const fn create_div() -> Self

Shorthand for NodeData::create_node(NodeType::Div).

Source

pub const fn create_br() -> Self

Shorthand for NodeData::create_node(NodeType::Br).

Source

pub fn create_text<S: Into<AzString>>(value: S) -> Self

Shorthand for NodeData::create_node(NodeType::Text(value.into())).

Source

pub fn create_image(image: ImageRef) -> Self

Shorthand for NodeData::create_node(NodeType::Image(image_id)).

Source

pub fn create_iframe(data: RefAny, callback: impl Into<IFrameCallback>) -> Self

Source

pub fn is_node_type(&self, searched_type: NodeType) -> bool

Checks whether this node is of the given node type (div, image, text).

Source

pub fn has_id(&self, id: &str) -> bool

Checks whether this node has the searched ID attached.

Source

pub fn has_class(&self, class: &str) -> bool

Checks whether this node has the searched class attached.

Source

pub fn has_context_menu(&self) -> bool

Source

pub fn is_text_node(&self) -> bool

Source

pub fn is_iframe_node(&self) -> bool

Source

pub const fn get_node_type(&self) -> &NodeType

Source

pub fn get_dataset_mut(&mut self) -> &mut OptionRefAny

Source

pub const fn get_dataset(&self) -> &OptionRefAny

Source

pub const fn get_ids_and_classes(&self) -> &IdOrClassVec

Source

pub const fn get_callbacks(&self) -> &CoreCallbackDataVec

Source

pub const fn get_css_props(&self) -> &CssPropertyWithConditionsVec

Source

pub fn get_clip_mask(&self) -> Option<&ImageMask>

Source

pub fn get_tab_index(&self) -> Option<&TabIndex>

Source

pub fn get_accessibility_info(&self) -> Option<&Box<AccessibilityInfo>>

Source

pub fn get_menu_bar(&self) -> Option<&Box<Menu>>

Source

pub fn get_context_menu(&self) -> Option<&Box<Menu>>

Source

pub fn is_anonymous(&self) -> bool

Returns whether this node is an anonymous box generated for table layout.

Source

pub fn set_node_type(&mut self, node_type: NodeType)

Source

pub fn set_dataset(&mut self, data: OptionRefAny)

Source

pub fn set_ids_and_classes(&mut self, ids_and_classes: IdOrClassVec)

Source

pub fn set_callbacks(&mut self, callbacks: CoreCallbackDataVec)

Source

pub fn set_css_props(&mut self, css_props: CssPropertyWithConditionsVec)

Source

pub fn set_clip_mask(&mut self, clip_mask: ImageMask)

Source

pub fn set_tab_index(&mut self, tab_index: TabIndex)

Source

pub fn set_contenteditable(&mut self, contenteditable: bool)

Source

pub fn is_contenteditable(&self) -> bool

Source

pub fn set_accessibility_info(&mut self, accessibility_info: AccessibilityInfo)

Source

pub fn set_anonymous(&mut self, is_anonymous: bool)

Marks this node as an anonymous box (generated for table layout).

Source

pub fn set_menu_bar(&mut self, menu_bar: Menu)

Source

pub fn set_context_menu(&mut self, context_menu: Menu)

Source

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");
Source

pub fn get_key(&self) -> Option<u64>

Gets the key for this node, if set.

Source

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);
Source

pub fn get_merge_callback(&self) -> Option<DatasetMergeCallback>

Gets the merge callback for this node, if set.

Source

pub fn with_menu_bar(self, menu_bar: Menu) -> Self

Source

pub fn with_context_menu(self, context_menu: Menu) -> Self

Source

pub fn add_callback<C: Into<CoreCallback>>( &mut self, event: EventFilter, data: RefAny, callback: C, )

Source

pub fn add_id(&mut self, s: AzString)

Source

pub fn add_class(&mut self, s: AzString)

Source

pub fn add_css_property(&mut self, p: CssProperty)

Add an unconditional CSS property (always applies)

Source

pub fn add_hover_css_property(&mut self, p: CssProperty)

Add a CSS property that applies only on hover

Source

pub fn add_active_css_property(&mut self, p: CssProperty)

Add a CSS property that applies only when active (clicked)

Source

pub fn add_focus_css_property(&mut self, p: CssProperty)

Add a CSS property that applies only when focused

Source

pub fn calculate_node_data_hash(&self) -> DomNodeHash

Calculates a deterministic node hash for this node.

Source

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.

Source

pub fn with_tab_index(self, tab_index: TabIndex) -> Self

Source

pub fn with_contenteditable(self, contenteditable: bool) -> Self

Source

pub fn with_node_type(self, node_type: NodeType) -> Self

Source

pub fn with_callback<C: Into<CoreCallback>>( self, event: EventFilter, data: RefAny, callback: C, ) -> Self

Source

pub fn with_dataset(self, data: OptionRefAny) -> Self

Source

pub fn with_ids_and_classes(self, ids_and_classes: IdOrClassVec) -> Self

Source

pub fn with_callbacks(self, callbacks: CoreCallbackDataVec) -> Self

Source

pub fn with_css_props(self, css_props: CssPropertyWithConditionsVec) -> Self

Source

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")
Source

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)
Source

pub fn set_inline_style(&mut self, style: &str)

Parse CSS from a string and add as unconditional properties

Source

pub fn with_inline_style(self, style: &str) -> Self

Builder method for setting inline CSS styles for the normal state

Source

pub fn set_inline_hover_style(&mut self, style: &str)

Sets inline CSS styles for the hover state, parsing from a CSS string

Source

pub fn with_inline_hover_style(self, style: &str) -> Self

Builder method for setting inline CSS styles for the hover state

Source

pub fn set_inline_active_style(&mut self, style: &str)

Sets inline CSS styles for the active state, parsing from a CSS string

Source

pub fn with_inline_active_style(self, style: &str) -> Self

Builder method for setting inline CSS styles for the active state

Source

pub fn set_inline_focus_style(&mut self, style: &str)

Sets inline CSS styles for the focus state, parsing from a CSS string

Source

pub fn with_inline_focus_style(self, style: &str) -> Self

Builder method for setting inline CSS styles for the focus state

Source

pub fn swap_with_default(&mut self) -> Self

Source

pub fn copy_special(&self) -> Self

Source

pub fn is_focusable(&self) -> bool

Source

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

Source

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).

Source

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 Tab
  • Some(0): In natural tab order
  • Some(n > 0): In tab order with priority n (higher = later)
Source

pub fn get_iframe_node(&mut self) -> Option<&mut IFrameNode>

Source

pub fn get_render_image_callback_node<'a>( &'a mut self, ) -> Option<(&'a mut CoreImageCallback, ImageRefHash)>

Source

pub fn debug_print_start( &self, css_cache: &CssPropertyCache, node_id: &NodeId, node_state: &StyledNodeState, ) -> String

Source

pub fn debug_print_end(&self) -> String

Trait Implementations§

Source§

impl Clone for NodeData

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NodeData

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for NodeData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Extend<NodeData> for NodeDataVec

Source§

fn extend<T: IntoIterator<Item = NodeData>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<NodeData> for NodeDataVec

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = NodeData>,

Creates a value from an iterator. Read more
Source§

impl Hash for NodeData

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for NodeData

Source§

fn cmp(&self, other: &NodeData) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for NodeData

Source§

fn eq(&self, other: &NodeData) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for NodeData

Source§

fn partial_cmp(&self, other: &NodeData) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for NodeData

Source§

impl Send for NodeData

Source§

impl StructuralPartialEq for NodeData

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> GetHash for T
where T: Hash,

Source§

fn get_hash(&self) -> u64

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.