pub struct Node {
pub id: NodeId,
pub rect: Cell<Rect>,
pub dirty: Dirty,
pub parent: Option<NodeId>,
pub component: Box<dyn Component>,
pub children: Vec<Node>,
}Expand description
Fields§
§id: NodeIdUnique identifier for this node.
rect: Cell<Rect>The layout rectangle assigned to this node (interior-mutable for borrow-splitting during layout and render).
dirty: DirtyPer-node dirty flags.
parent: Option<NodeId>Parent node id, if any.
component: Box<dyn Component>The boxed component that owns the logic for this node.
children: Vec<Node>Child nodes in display order.
Implementations§
Source§impl Node
impl Node
Sourcepub fn new(component: impl Component + 'static) -> Self
pub fn new(component: impl Component + 'static) -> Self
Creates a new leaf node wrapping the given component.
The node receives a fresh NodeId via NodeId::new.
Sourcepub fn root(component: impl Component + 'static) -> Self
pub fn root(component: impl Component + 'static) -> Self
Creates the root node with NodeId::ROOT.
Sourcepub fn render(&self, buffer: &mut Buffer, focused_id: Option<NodeId>)
pub fn render(&self, buffer: &mut Buffer, focused_id: Option<NodeId>)
Renders this subtree into buffer, clipping to this node’s rect.
Sourcepub fn render_with_clip(
&self,
buffer: &mut Buffer,
focused_id: Option<NodeId>,
clip_rect: Option<Rect>,
)
pub fn render_with_clip( &self, buffer: &mut Buffer, focused_id: Option<NodeId>, clip_rect: Option<Rect>, )
Renders this subtree with an optional clip rectangle.
Sourcepub fn render_with_clip_and_wrap(
&self,
buffer: &mut Buffer,
focused_id: Option<NodeId>,
clip_rect: Option<Rect>,
wrap: TextWrap,
truncate: TextTruncate,
align: TextAlign,
)
pub fn render_with_clip_and_wrap( &self, buffer: &mut Buffer, focused_id: Option<NodeId>, clip_rect: Option<Rect>, wrap: TextWrap, truncate: TextTruncate, align: TextAlign, )
Renders this subtree with full text-flow control.
Sourcepub fn render_with_parent(
&self,
buffer: &mut Buffer,
focused_id: Option<NodeId>,
clip_rect: Option<Rect>,
wrap: TextWrap,
truncate: TextTruncate,
align: TextAlign,
parent_style: Option<&Style>,
)
pub fn render_with_parent( &self, buffer: &mut Buffer, focused_id: Option<NodeId>, clip_rect: Option<Rect>, wrap: TextWrap, truncate: TextTruncate, align: TextAlign, parent_style: Option<&Style>, )
Renders this subtree, merging style values inherited from a parent.
Sourcepub fn render_inner(
&self,
buffer: &mut Buffer,
focused_id: Option<NodeId>,
clip_rect: Option<Rect>,
wrap: TextWrap,
truncate: TextTruncate,
align: TextAlign,
sheet: Option<&StyleSheet>,
parent_style: Option<&Style>,
)
pub fn render_inner( &self, buffer: &mut Buffer, focused_id: Option<NodeId>, clip_rect: Option<Rect>, wrap: TextWrap, truncate: TextTruncate, align: TextAlign, sheet: Option<&StyleSheet>, parent_style: Option<&Style>, )
Core render entry-point.
Resolves the effective style from the stylesheet, parent inheritance,
and the component’s own style, then calls Component::render.
Sourcepub fn event(
&mut self,
event: &Event,
global_dirty: &mut Dirty,
quit: &mut bool,
task_tx: Option<Sender<String>>,
)
pub fn event( &mut self, event: &Event, global_dirty: &mut Dirty, quit: &mut bool, task_tx: Option<Sender<String>>, )
Dispatches an event to this node and (if not stopped) its children.
Calls Component::update before Component::event.
Sourcepub fn measure(&self, constraint: Constraint) -> Size
pub fn measure(&self, constraint: Constraint) -> Size
Measures the intrinsic size of this node’s subtree given constraint.
Sourcepub fn mount(
&mut self,
global_dirty: &mut Dirty,
quit: &mut bool,
task_tx: Option<Sender<String>>,
)
pub fn mount( &mut self, global_dirty: &mut Dirty, quit: &mut bool, task_tx: Option<Sender<String>>, )
Recursively calls Component::mount on this node and its children.
Sourcepub fn debug_render(&self, buffer: &mut Buffer, focused_id: Option<NodeId>)
pub fn debug_render(&self, buffer: &mut Buffer, focused_id: Option<NodeId>)
Recursively draws border outlines and type-name labels for every node.
The currently focused node is drawn with a double border; others use
rounded borders. This is toggled by the d key in debug mode.
Sourcepub fn unmount(
&mut self,
global_dirty: &mut Dirty,
quit: &mut bool,
task_tx: Option<Sender<String>>,
)
pub fn unmount( &mut self, global_dirty: &mut Dirty, quit: &mut bool, task_tx: Option<Sender<String>>, )
Recursively calls Component::unmount on children (reverse order),
then on this node.
Sourcepub fn layout(&mut self, rect: Rect)
pub fn layout(&mut self, rect: Rect)
Runs layout for this subtree.
Sets this node’s rect, assigns parent links to direct children, then
calls Component::layout so the component can size and position its
children.
Sourcepub fn find_path_to(&self, target_id: NodeId) -> Option<Vec<NodeId>>
pub fn find_path_to(&self, target_id: NodeId) -> Option<Vec<NodeId>>
Returns the path of node ids from self down to target_id, inclusive.
Returns None if target_id is not in this subtree.
Sourcepub fn any_needs_paint(&self) -> bool
pub fn any_needs_paint(&self) -> bool
Returns true if this node or any descendant has Dirty::PAINT set.
Sourcepub fn any_needs_layout(&self) -> bool
pub fn any_needs_layout(&self) -> bool
Returns true if this node or any descendant has Dirty::LAYOUT set.
Sourcepub fn clear_dirty(&mut self)
pub fn clear_dirty(&mut self)
Resets all dirty flags on this node to Dirty::NONE.
Does not recurse into children — the caller is responsible for clearing the full tree if needed.
Sourcepub fn collect_focusable(&self, ids: &mut Vec<NodeId>)
pub fn collect_focusable(&self, ids: &mut Vec<NodeId>)
Collects ids of all focusable nodes in this subtree into ids.
Sourcepub fn hit_test(&self, pos: Pos) -> Option<NodeId>
pub fn hit_test(&self, pos: Pos) -> Option<NodeId>
Performs a hit-test against the layout rects in this subtree.
Returns the deepest node whose rect contains pos, or None if no
node matches.
Sourcepub fn send_event(
&mut self,
target_id: NodeId,
event: &Event,
global_dirty: &mut Dirty,
quit: &mut bool,
phase: EventPhase,
stopped: &mut bool,
task_tx: Option<Sender<String>>,
) -> bool
pub fn send_event( &mut self, target_id: NodeId, event: &Event, global_dirty: &mut Dirty, quit: &mut bool, phase: EventPhase, stopped: &mut bool, task_tx: Option<Sender<String>>, ) -> bool
Dispatches an event to a specific target node in this subtree.
Used by the runtime for capture and bubble phases. Returns true if
the target was found, false otherwise.