pub struct WidgetTree { /* private fields */ }Expand description
The widget tree: a thin, typed wrapper over tree_arena::TreeArena.
Implementations§
Source§impl WidgetTree
impl WidgetTree
Sourcepub fn insert_root(&mut self, pod: WidgetPod) -> WidgetId
pub fn insert_root(&mut self, pod: WidgetPod) -> WidgetId
Insert pod as a root of the tree, returning its id.
Sourcepub fn insert_child(
&mut self,
parent: WidgetId,
pod: WidgetPod,
) -> Option<WidgetId>
pub fn insert_child( &mut self, parent: WidgetId, pod: WidgetPod, ) -> Option<WidgetId>
Insert pod as a child of parent. Returns the child id, or None if
parent is not in the tree.
Exercises the tree_arena 0.2.0 ArenaMut / ArenaMutList handles: a
node’s value and its child list are borrowed disjointly, so this stays
borrow-checker-clean.
Sourcepub fn pod(&self, id: WidgetId) -> Option<&WidgetPod>
pub fn pod(&self, id: WidgetId) -> Option<&WidgetPod>
Shared access to the pod with the given id, anywhere in the tree.
Sourcepub fn pod_mut(&mut self, id: WidgetId) -> Option<&mut WidgetPod>
pub fn pod_mut(&mut self, id: WidgetId) -> Option<&mut WidgetPod>
Mutable access to the pod with the given id, anywhere in the tree.
Sourcepub fn roots(&self) -> Vec<WidgetId>
pub fn roots(&self) -> Vec<WidgetId>
The tree’s root ids, in insertion order.
O(roots). Read-only; nothing here mutates the arena.
Sourcepub fn children(&self, id: WidgetId) -> Vec<WidgetId>
pub fn children(&self, id: WidgetId) -> Vec<WidgetId>
The children of id, in insertion order — empty if id has no children
or is not in the tree.
O(depth) to find the parent, then O(children). Every id returned is live in the arena at call time.
Sourcepub fn inspect(&self) -> Vec<InspectNode>
pub fn inspect(&self) -> Vec<InspectNode>
A read-only snapshot of the whole retained tree in pre-order (a node precedes its descendants; siblings follow declaration order).
The walk covers both child mechanisms: the arena’s own children, then
the ChildPods a widget publishes through Widget::visit_children —
which is where nearly the whole hierarchy actually lives. A container
that does not override that seam reads as a leaf.
O(nodes) — one pass, one HashSet of sibling ids per arena parent, no
arena mutation and no bookkeeping left behind (a pod’s tooling id is
assigned once, on its first visit, and reused). Bounds come from what the
last layout pass recorded on each pod (WidgetPod::origin /
WidgetPod::size, ChildPod::origin / ChildPod::size),
accumulated into absolute window coordinates on the way down; call it
after a layout pass or the rects are all zero-sized.