Skip to main content

Node

Struct Node 

Source
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

A node in the component tree.

Each Node owns a boxed Component, tracks its layout Rect, dirty flags, parent link, and child nodes. The tree is mutable — Node::add_child and the builder methods on container widgets grow the tree at construction time.

Fields§

§id: NodeId

Unique identifier for this node.

§rect: Cell<Rect>

The layout rectangle assigned to this node (interior-mutable for borrow-splitting during layout and render).

§dirty: Dirty

Per-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

Source

pub fn rect(&self) -> Rect

Returns the current layout rectangle of this node.

Source

pub fn set_rect(&self, r: Rect)

Updates the layout rectangle of this node.

Source

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.

Source

pub fn root(component: impl Component + 'static) -> Self

Creates the root node with NodeId::ROOT.

Source

pub fn add_child(&mut self, child: Node)

Appends a child node at the end of the children list.

Source

pub fn render(&self, buffer: &mut Buffer, focused_id: Option<NodeId>)

Renders this subtree into buffer, clipping to this node’s rect.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn measure(&self, constraint: Constraint) -> Size

Measures the intrinsic size of this node’s subtree given constraint.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn any_needs_paint(&self) -> bool

Returns true if this node or any descendant has Dirty::PAINT set.

Source

pub fn any_needs_layout(&self) -> bool

Returns true if this node or any descendant has Dirty::LAYOUT set.

Source

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.

Source

pub fn collect_focusable(&self, ids: &mut Vec<NodeId>)

Collects ids of all focusable nodes in this subtree into ids.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl !Freeze for Node

§

impl !RefUnwindSafe for Node

§

impl !Send for Node

§

impl !Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl !UnwindSafe for Node

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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