Skip to main content

LayoutTree

Struct LayoutTree 

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

Original layout tree maintaining node hierarchy, mutation invariants, dirty propagation, and constraint-keyed caching.

Implementations§

Source§

impl LayoutTree

Source

pub fn new() -> Self

Creates a new, empty layout tree.

Source

pub fn validate_node_id(&self, id: LayoutNodeId) -> GuiResult<()>

Validates that id corresponds to an active node in the tree.

Source

pub fn node(&self, id: LayoutNodeId) -> GuiResult<&LayoutNode>

Returns a reference to the node with the given ID.

Source

pub fn node_mut(&mut self, id: LayoutNodeId) -> GuiResult<&mut LayoutNode>

Returns a mutable reference to the node with the given ID.

Source

pub fn create_node(&mut self, style: Style) -> LayoutNodeId

Creates a new node with the specified style, returning its stable generational ID.

Source

pub fn attach_child( &mut self, parent: LayoutNodeId, child: LayoutNodeId, ) -> GuiResult<()>

Attaches child as a child of parent.

Refuses stale/invalid IDs, self-attachment, and cyclic parentage without modifying the tree. Safely detaches child from any previous parent before attaching.

Source

pub fn reparent_child( &mut self, new_parent: LayoutNodeId, child: LayoutNodeId, ) -> GuiResult<()>

Reparents child under new_parent, safely detaching from old parent first.

Source

pub fn detach_child(&mut self, child: LayoutNodeId) -> GuiResult<()>

Detaches child from its parent without deleting the child node.

Source

pub fn detach_all_children( &mut self, parent: LayoutNodeId, ) -> GuiResult<Vec<LayoutNodeId>>

Detaches all children of parent in one pass without placing them into roots.

Source

pub fn remove_node(&mut self, node: LayoutNodeId) -> GuiResult<()>

Removes a node and its entire subtree, invalidating all associated IDs.

Source

pub fn set_style(&mut self, node: LayoutNodeId, style: Style) -> GuiResult<()>

Sets the layout style for a node after validating numeric constraints.

Refuses invalid numeric input without modifying the tree.

Source

pub fn style(&self, node: LayoutNodeId) -> GuiResult<&Style>

Returns the style of a node.

Source

pub fn children(&self, node: LayoutNodeId) -> GuiResult<&[LayoutNodeId]>

Returns the children of a node.

Source

pub fn parent(&self, node: LayoutNodeId) -> GuiResult<Option<LayoutNodeId>>

Returns the parent of a node, or None if it is a root.

Source

pub fn is_dirty(&self, node: LayoutNodeId) -> GuiResult<bool>

Returns whether a node is marked dirty.

Source

pub fn mark_dirty(&mut self, node: LayoutNodeId) -> GuiResult<()>

Manually marks a node dirty and propagates the dirty bit up to its root.

Source

pub fn set_measurement_revision( &mut self, node: LayoutNodeId, revision: u64, ) -> GuiResult<()>

Updates the measurement revision for a node and marks it dirty.

Source

pub fn layout(&self, node: LayoutNodeId) -> GuiResult<LayoutRect>

Returns the computed layout rectangle for a node in layout-root-relative coordinates.

Source

pub fn unrounded_layout(&self, node: LayoutNodeId) -> GuiResult<LayoutRect>

Returns the unrounded rectangle in layout-root-relative coordinates.

Source

pub fn node_count(&self) -> usize

Returns the number of active nodes in the tree.

Source

pub fn contains(&self, node: LayoutNodeId) -> bool

Returns true if node is an active node in the tree.

Source

pub fn roots(&self) -> &[LayoutNodeId]

Returns the list of active root node IDs.

Source

pub fn is_root(&self, node: LayoutNodeId) -> GuiResult<bool>

Returns true if node is a root node (has no parent).

Source

pub fn root_for(&self, node: LayoutNodeId) -> GuiResult<LayoutNodeId>

Resolves the root ancestor for node.

Source

pub fn metrics(&self) -> &LayoutMetrics

Returns a reference to layout operation metrics.

Source

pub fn reset_metrics(&mut self)

Resets layout operation metrics.

Source

pub fn clear_cache(&mut self)

Clears the layout cache.

Source

pub fn cache_len(&self) -> usize

Returns the number of entries currently stored in the layout cache.

Source

pub fn compute_layout( &mut self, root: LayoutNodeId, available_space: Size<AvailableSpace>, ) -> GuiResult<LayoutRect>

Computes layout for the given root node under available space constraints.

Source

pub fn compute_layout_with_measure<F>( &mut self, root: LayoutNodeId, available_space: Size<AvailableSpace>, measure_fn: F, ) -> GuiResult<LayoutRect>

Computes layout for the given root node using a custom intrinsic measurement closure.

The root cache is keyed by the node, the available space, and the node’s style/measurement revisions — not by the closure. The closure’s output must therefore be stable for a given measurement_revision; call Self::set_measurement_revision when the measurement policy or its inputs change, or a clean pass will reuse the layout produced by the previous closure.

Trait Implementations§

Source§

impl Clone for LayoutTree

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LayoutTree

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for LayoutTree

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.