Skip to main content

ModifierNode

Trait ModifierNode 

Source
pub trait ModifierNode: Any + DelegatableNode {
Show 15 methods // Provided methods fn on_attach(&mut self, _context: &mut dyn ModifierNodeContext) { ... } fn on_detach(&mut self) { ... } fn on_reset(&mut self) { ... } fn as_draw_node(&self) -> Option<&dyn DrawModifierNode> { ... } fn as_draw_node_mut(&mut self) -> Option<&mut dyn DrawModifierNode> { ... } fn as_pointer_input_node(&self) -> Option<&dyn PointerInputNode> { ... } fn as_pointer_input_node_mut(&mut self) -> Option<&mut dyn PointerInputNode> { ... } fn as_semantics_node(&self) -> Option<&dyn SemanticsNode> { ... } fn as_semantics_node_mut(&mut self) -> Option<&mut dyn SemanticsNode> { ... } fn as_focus_node(&self) -> Option<&dyn FocusNode> { ... } fn as_focus_node_mut(&mut self) -> Option<&mut dyn FocusNode> { ... } fn as_layout_node(&self) -> Option<&dyn LayoutModifierNode> { ... } fn as_layout_node_mut(&mut self) -> Option<&mut dyn LayoutModifierNode> { ... } fn for_each_delegate<'b>( &'b self, _visitor: &mut dyn FnMut(&'b dyn ModifierNode), ) { ... } fn for_each_delegate_mut<'b>( &'b mut self, _visitor: &mut dyn FnMut(&'b mut dyn ModifierNode), ) { ... }
}
Expand description

Core trait implemented by modifier nodes.

§Capability-Driven Architecture

This trait follows Jetpack Compose’s Modifier.Node pattern where nodes declare their capabilities via NodeCapabilities and implement specialized traits (DrawModifierNode, PointerInputNode, SemanticsNode, FocusNode, etc.) to participate in specific pipeline stages.

§How to Implement a Modifier Node

  1. Declare capabilities in your ModifierNodeElement::capabilities() implementation
  2. Implement specialized traits for the capabilities you declared
  3. Use helper macros to reduce boilerplate (recommended)

§Example: Draw Node

use cranpose_foundation::*;

struct MyDrawNode {
    state: NodeState,
    color: Color,
}

impl DelegatableNode for MyDrawNode {
    fn node_state(&self) -> &NodeState {
        &self.state
    }
}

impl ModifierNode for MyDrawNode {
    // Use the helper macro instead of manual as_* implementations
    impl_modifier_node!(draw);
}

impl DrawModifierNode for MyDrawNode {
    fn draw(&mut self, _context: &mut dyn ModifierNodeContext, draw_scope: &mut dyn DrawScope) {
        // Drawing logic here
    }
}

§Example: Multi-Capability Node

impl ModifierNode for MyComplexNode {
    // This node participates in draw, pointer input, and semantics
    impl_modifier_node!(draw, pointer_input, semantics);
}

§Lifecycle Callbacks

Nodes receive lifecycle callbacks when they attach to or detach from a composition and may optionally react to resets triggered by the runtime (for example, when reusing nodes across modifier list changes).

Provided Methods§

Source

fn on_attach(&mut self, _context: &mut dyn ModifierNodeContext)

Source

fn on_detach(&mut self)

Source

fn on_reset(&mut self)

Source

fn as_draw_node(&self) -> Option<&dyn DrawModifierNode>

Returns this node as a draw modifier if it implements the trait.

Source

fn as_draw_node_mut(&mut self) -> Option<&mut dyn DrawModifierNode>

Returns this node as a mutable draw modifier if it implements the trait.

Source

fn as_pointer_input_node(&self) -> Option<&dyn PointerInputNode>

Returns this node as a pointer-input modifier if it implements the trait.

Source

fn as_pointer_input_node_mut(&mut self) -> Option<&mut dyn PointerInputNode>

Returns this node as a mutable pointer-input modifier if it implements the trait.

Source

fn as_semantics_node(&self) -> Option<&dyn SemanticsNode>

Returns this node as a semantics modifier if it implements the trait.

Source

fn as_semantics_node_mut(&mut self) -> Option<&mut dyn SemanticsNode>

Returns this node as a mutable semantics modifier if it implements the trait.

Source

fn as_focus_node(&self) -> Option<&dyn FocusNode>

Returns this node as a focus modifier if it implements the trait.

Source

fn as_focus_node_mut(&mut self) -> Option<&mut dyn FocusNode>

Returns this node as a mutable focus modifier if it implements the trait.

Source

fn as_layout_node(&self) -> Option<&dyn LayoutModifierNode>

Returns this node as a layout modifier if it implements the trait.

Source

fn as_layout_node_mut(&mut self) -> Option<&mut dyn LayoutModifierNode>

Returns this node as a mutable layout modifier if it implements the trait.

Source

fn for_each_delegate<'b>( &'b self, _visitor: &mut dyn FnMut(&'b dyn ModifierNode), )

Visits every delegate node owned by this modifier.

Source

fn for_each_delegate_mut<'b>( &'b mut self, _visitor: &mut dyn FnMut(&'b mut dyn ModifierNode), )

Visits every delegate node mutably.

Implementations§

Source§

impl dyn ModifierNode

Source

pub fn as_any(&self) -> &dyn Any

Source

pub fn as_any_mut(&mut self) -> &mut dyn Any

Trait Implementations§

Source§

impl Debug for dyn ModifierNode

Source§

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

Formats the value using the given formatter. Read more

Implementors§