DrawModifierNode

Trait DrawModifierNode 

Source
pub trait DrawModifierNode: ModifierNode {
    // Provided methods
    fn draw(&self, _draw_scope: &mut dyn DrawScope) { ... }
    fn create_draw_closure(
        &self,
    ) -> Option<Rc<dyn Fn(Size) -> Vec<DrawPrimitive>>> { ... }
}
Expand description

Marker trait for draw-specific modifier nodes.

Draw nodes participate in the draw pass of the render pipeline. They can intercept and modify the drawing operations of their wrapped content.

Following Jetpack Compose’s design, draw() is called during the actual render pass with a live DrawScope, not during layout/slice collection.

Provided Methods§

Source

fn draw(&self, _draw_scope: &mut dyn DrawScope)

Draws this modifier node into the provided DrawScope.

This is called during the render pass for each node with DRAW capability. The node should draw directly into the scope using methods like draw_scope.draw_rect_at().

Takes &self to work with immutable chain iteration - use interior mutability (RefCell) for any state that needs mutation during draw.

Source

fn create_draw_closure(&self) -> Option<Rc<dyn Fn(Size) -> Vec<DrawPrimitive>>>

Creates a closure for deferred drawing that will be evaluated at render time.

This is the preferred method for nodes with dynamic content like:

  • Blinking cursors (visibility changes over time)
  • Live selection during drag (selection changes during mouse move)

The returned closure captures the node’s internal state (via Rc) and evaluates at render time, not at slice collection time.

Returns None by default. Override for nodes needing deferred draw.

Implementors§