Skip to main content

WidgetTree

Struct WidgetTree 

Source
pub struct WidgetTree { /* private fields */ }
Expand description

The widget tree: a thin, typed wrapper over tree_arena::TreeArena.

Implementations§

Source§

impl WidgetTree

Source

pub fn new() -> Self

Create an empty tree.

Source

pub fn insert_root(&mut self, pod: WidgetPod) -> WidgetId

Insert pod as a root of the tree, returning its id.

Source

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.

Source

pub fn pod(&self, id: WidgetId) -> Option<&WidgetPod>

Shared access to the pod with the given id, anywhere in the tree.

Source

pub fn pod_mut(&mut self, id: WidgetId) -> Option<&mut WidgetPod>

Mutable access to the pod with the given id, anywhere in the tree.

Source

pub fn roots(&self) -> Vec<WidgetId>

The tree’s root ids, in insertion order.

O(roots). Read-only; nothing here mutates the arena.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for WidgetTree

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.