Skip to main content

WidgetTree

Struct WidgetTree 

Source
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

Source

pub fn new(root_rect: Rect) -> Self

Create a new tree whose root covers root_rect.

Source

pub fn len(&self) -> usize

Total number of nodes (including the root).

Source

pub fn is_empty(&self) -> bool

Returns true if only the root node exists.

Source

pub fn get(&self, id: WidgetId) -> Option<&WidgetNode>

Borrow a node by id.

Source

pub fn get_mut(&mut self, id: WidgetId) -> Option<&mut WidgetNode>

Mutably borrow a node by id.

Source

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.

Source

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.

Source

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.

Source

pub fn is_descendant( &self, maybe_descendant: WidgetId, ancestor: WidgetId, ) -> bool

Returns true if maybe_descendant is in the subtree rooted at ancestor.

Source

pub fn depth(&self, id: WidgetId) -> Option<usize>

Depth of id from the root (root has depth 0). Returns None if missing.

Source

pub fn walk_dfs(&self, visit: impl FnMut(&WidgetNode, usize))

Visit every node in depth-first pre-order, invoking visit(node, depth).

Source

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.

Source

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.

Source

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

Collect the focusable nodes in DFS (tab) order.

Source

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.

Trait Implementations§

Source§

impl Debug for WidgetTree

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.