Skip to main content

Module tree

Module tree 

Source
Expand description

The retained widget tree, backed by tree_arena.

tree_arena gives O(1) access to any node with simultaneous mutable access to a node’s value and its children — the proven answer to the borrow-checker fights a widget tree otherwise causes. All direct use of the arena is confined to this module; the rest of the crate speaks in WidgetId/WidgetPod terms.

v0 is single-root (the app has one root widget), but the API is written in terms of insert-into-list / find so container support drops in without reshaping this layer.

§Introspection

WidgetTree::roots / WidgetTree::children / WidgetTree::inspect make the arena enumerable for read-only tooling. tree_arena 0.2 does expose root_ids/child_ids, but both iterate a HashMap in arbitrary order, which is useless for an inspector that has to show siblings the way the app declared them. The tree therefore keeps a parallel insertion-order index (root_order/child_order) updated at the two mutation points that exist (WidgetTree::insert_root and WidgetTree::insert_child) and uses it only to order what the arena reports — the arena stays the single source of truth for membership, so a stale index entry can never surface a dangling id.

Containers own their children as ChildPods rather than as arena nodes (see that type’s docs), so the arena itself holds little more than the root pod. WidgetTree::inspect therefore walks both: a node’s arena children first, then the pods its widget hands to Widget::visit_children — so the snapshot is the real retained hierarchy rather than the arena’s contents. Only inspect descends that way; WidgetTree::children stays strictly arena-scoped, since it answers “what does the arena hold under this id”.

The descent needs no cycle check: a pod owns its widget, ownership is a tree, and the visitor only ever hands out &ChildPods the widget itself owns (see Widget::visit_children).

Structs§

InspectNode
One node of a read-only widget-tree snapshot, as produced by WidgetTree::inspect.
WidgetPod
A retained widget plus its layout results and dirty state.
WidgetTree
The widget tree: a thin, typed wrapper over tree_arena::TreeArena.