pub struct WidgetTree { /* private fields */ }Expand description
A tree of WidgetNodes addressed by WidgetId.
Nodes are stored in a flat vector; parent/child relationships are tracked by
id. The tree always contains a root node (WidgetId::ROOT).
Implementations§
Source§impl WidgetTree
impl WidgetTree
Sourcepub fn get(&self, id: WidgetId) -> Option<&WidgetNode>
pub fn get(&self, id: WidgetId) -> Option<&WidgetNode>
Borrow a node by id.
Sourcepub fn get_mut(&mut self, id: WidgetId) -> Option<&mut WidgetNode>
pub fn get_mut(&mut self, id: WidgetId) -> Option<&mut WidgetNode>
Mutably borrow a node by id.
Sourcepub fn insert(&mut self, parent: WidgetId, rect: Rect) -> Option<WidgetId>
pub fn insert(&mut self, parent: WidgetId, rect: Rect) -> Option<WidgetId>
Insert a new child of parent covering rect. Returns the new id, or
None if parent does not exist.
Sourcepub fn remove(&mut self, id: WidgetId) -> usize
pub fn remove(&mut self, id: WidgetId) -> usize
Remove id and its entire subtree. The root cannot be removed.
Returns the number of nodes removed.
Sourcepub fn reparent(&mut self, id: WidgetId, new_parent: WidgetId) -> bool
pub fn reparent(&mut self, id: WidgetId, new_parent: WidgetId) -> bool
Move id to become a child of new_parent. Returns false if either
id is missing, if id is the root, or if the move would create a cycle.
Sourcepub fn is_descendant(
&self,
maybe_descendant: WidgetId,
ancestor: WidgetId,
) -> bool
pub fn is_descendant( &self, maybe_descendant: WidgetId, ancestor: WidgetId, ) -> bool
Returns true if maybe_descendant is in the subtree rooted at ancestor.
Sourcepub fn depth(&self, id: WidgetId) -> Option<usize>
pub fn depth(&self, id: WidgetId) -> Option<usize>
Depth of id from the root (root has depth 0). Returns None if missing.
Sourcepub fn walk_dfs(&self, visit: impl FnMut(&WidgetNode, usize))
pub fn walk_dfs(&self, visit: impl FnMut(&WidgetNode, usize))
Visit every node in depth-first pre-order, invoking visit(node, depth).
Sourcepub fn effective_clip(&self, id: WidgetId) -> Option<Rect>
pub fn effective_clip(&self, id: WidgetId) -> Option<Rect>
The effective clip rectangle for id: the intersection of its own
clip_rect (if any) with every ancestor’s clip_rect. Returns None
when no ancestor (and the node itself) clips — meaning “unclipped”.
If the accumulated clips do not overlap at all, returns
Some(Rect::ZERO) (a degenerate, empty clip) so callers treat the node
as fully clipped away.
Sourcepub fn hit_test(&self, point: Point) -> Option<WidgetId>
pub fn hit_test(&self, point: Point) -> Option<WidgetId>
Hit-test point, returning the front-most hit-testable node containing it.
Traversal is depth-first; among overlapping candidates the one with the
greatest combined (depth, z_index) paint order wins (i.e. the visually
front-most). Non-hit_testable nodes are skipped but their descendants
are still tested. A node is only a candidate when point lies within
both its rect and its effective_clip;
content outside an (ancestor) clip is not interactive.
Sourcepub fn focus_order(&self) -> Vec<WidgetId>
pub fn focus_order(&self) -> Vec<WidgetId>
Collect the focusable nodes in DFS (tab) order.
Sourcepub fn paint_order(&self) -> Vec<WidgetId>
pub fn paint_order(&self) -> Vec<WidgetId>
Collect every node id in back-to-front paint order.
Order is a stable sort by the key (depth, z_index): shallower nodes
paint first (behind), and within the same depth lower z_index paints
first. Painting nodes in this order means later draws correctly occlude
earlier ones. The sort is stable, so siblings with equal z_index
retain their tree (DFS) order, matching CSS source-order tie-breaking.