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.
Sourcepub fn inspect_layout_dirty(&self) -> Vec<(WidgetId, bool)>
pub fn inspect_layout_dirty(&self) -> Vec<(WidgetId, bool)>
Per-node layout-dirty state for tooling and tests, read-only: one
(id, layout_dirty) pair for every node WidgetTree::inspect reports,
in exactly its pre-order and with exactly its ids, so the two zip.
A ChildPod reports ChildPod::is_layout_dirty — whether its next
ChildPod::layout_child must lay it out whatever its constraints. An
arena WidgetPod always reports false: it sits in no ChildPod, and
the root lays it out on every pass unconditionally, so there is no skip
state to report. Kept beside inspect rather than inside
InspectNode so that plain struct’s shape — which consumers construct
literally — does not change.
Sourcepub fn inspect_paint_dirty(&self) -> Vec<(WidgetId, bool)>
pub fn inspect_paint_dirty(&self) -> Vec<(WidgetId, bool)>
Per-node paint-dirty state for tooling and tests: the exact twin of
WidgetTree::inspect_layout_dirty (same order, same ids) reporting
ChildPod::is_paint_dirty. An arena WidgetPod reports false.