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
impl LayoutTree
Sourcepub fn validate_node_id(&self, id: LayoutNodeId) -> GuiResult<()>
pub fn validate_node_id(&self, id: LayoutNodeId) -> GuiResult<()>
Validates that id corresponds to an active node in the tree.
Sourcepub fn node(&self, id: LayoutNodeId) -> GuiResult<&LayoutNode>
pub fn node(&self, id: LayoutNodeId) -> GuiResult<&LayoutNode>
Returns a reference to the node with the given ID.
Sourcepub fn node_mut(&mut self, id: LayoutNodeId) -> GuiResult<&mut LayoutNode>
pub fn node_mut(&mut self, id: LayoutNodeId) -> GuiResult<&mut LayoutNode>
Returns a mutable reference to the node with the given ID.
Sourcepub fn create_node(&mut self, style: Style) -> LayoutNodeId
pub fn create_node(&mut self, style: Style) -> LayoutNodeId
Creates a new node with the specified style, returning its stable generational ID.
Sourcepub fn attach_child(
&mut self,
parent: LayoutNodeId,
child: LayoutNodeId,
) -> GuiResult<()>
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.
Sourcepub fn reparent_child(
&mut self,
new_parent: LayoutNodeId,
child: LayoutNodeId,
) -> GuiResult<()>
pub fn reparent_child( &mut self, new_parent: LayoutNodeId, child: LayoutNodeId, ) -> GuiResult<()>
Reparents child under new_parent, safely detaching from old parent first.
Sourcepub fn detach_child(&mut self, child: LayoutNodeId) -> GuiResult<()>
pub fn detach_child(&mut self, child: LayoutNodeId) -> GuiResult<()>
Detaches child from its parent without deleting the child node.
Sourcepub fn detach_all_children(
&mut self,
parent: LayoutNodeId,
) -> GuiResult<Vec<LayoutNodeId>>
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.
Sourcepub fn remove_node(&mut self, node: LayoutNodeId) -> GuiResult<()>
pub fn remove_node(&mut self, node: LayoutNodeId) -> GuiResult<()>
Removes a node and its entire subtree, invalidating all associated IDs.
Sourcepub fn set_style(&mut self, node: LayoutNodeId, style: Style) -> GuiResult<()>
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.
Sourcepub fn style(&self, node: LayoutNodeId) -> GuiResult<&Style>
pub fn style(&self, node: LayoutNodeId) -> GuiResult<&Style>
Returns the style of a node.
Sourcepub fn children(&self, node: LayoutNodeId) -> GuiResult<&[LayoutNodeId]>
pub fn children(&self, node: LayoutNodeId) -> GuiResult<&[LayoutNodeId]>
Returns the children of a node.
Sourcepub fn parent(&self, node: LayoutNodeId) -> GuiResult<Option<LayoutNodeId>>
pub fn parent(&self, node: LayoutNodeId) -> GuiResult<Option<LayoutNodeId>>
Returns the parent of a node, or None if it is a root.
Sourcepub fn is_dirty(&self, node: LayoutNodeId) -> GuiResult<bool>
pub fn is_dirty(&self, node: LayoutNodeId) -> GuiResult<bool>
Returns whether a node is marked dirty.
Sourcepub fn mark_dirty(&mut self, node: LayoutNodeId) -> GuiResult<()>
pub fn mark_dirty(&mut self, node: LayoutNodeId) -> GuiResult<()>
Manually marks a node dirty and propagates the dirty bit up to its root.
Sourcepub fn set_measurement_revision(
&mut self,
node: LayoutNodeId,
revision: u64,
) -> GuiResult<()>
pub fn set_measurement_revision( &mut self, node: LayoutNodeId, revision: u64, ) -> GuiResult<()>
Updates the measurement revision for a node and marks it dirty.
Sourcepub fn layout(&self, node: LayoutNodeId) -> GuiResult<LayoutRect>
pub fn layout(&self, node: LayoutNodeId) -> GuiResult<LayoutRect>
Returns the computed layout rectangle for a node in layout-root-relative coordinates.
Sourcepub fn unrounded_layout(&self, node: LayoutNodeId) -> GuiResult<LayoutRect>
pub fn unrounded_layout(&self, node: LayoutNodeId) -> GuiResult<LayoutRect>
Returns the unrounded rectangle in layout-root-relative coordinates.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of active nodes in the tree.
Sourcepub fn contains(&self, node: LayoutNodeId) -> bool
pub fn contains(&self, node: LayoutNodeId) -> bool
Returns true if node is an active node in the tree.
Sourcepub fn roots(&self) -> &[LayoutNodeId]
pub fn roots(&self) -> &[LayoutNodeId]
Returns the list of active root node IDs.
Sourcepub fn is_root(&self, node: LayoutNodeId) -> GuiResult<bool>
pub fn is_root(&self, node: LayoutNodeId) -> GuiResult<bool>
Returns true if node is a root node (has no parent).
Sourcepub fn root_for(&self, node: LayoutNodeId) -> GuiResult<LayoutNodeId>
pub fn root_for(&self, node: LayoutNodeId) -> GuiResult<LayoutNodeId>
Resolves the root ancestor for node.
Sourcepub fn metrics(&self) -> &LayoutMetrics
pub fn metrics(&self) -> &LayoutMetrics
Returns a reference to layout operation metrics.
Sourcepub fn reset_metrics(&mut self)
pub fn reset_metrics(&mut self)
Resets layout operation metrics.
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clears the layout cache.
Sourcepub fn cache_len(&self) -> usize
pub fn cache_len(&self) -> usize
Returns the number of entries currently stored in the layout cache.
Sourcepub fn compute_layout(
&mut self,
root: LayoutNodeId,
available_space: Size<AvailableSpace>,
) -> GuiResult<LayoutRect>
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.
Sourcepub fn compute_layout_with_measure<F>(
&mut self,
root: LayoutNodeId,
available_space: Size<AvailableSpace>,
measure_fn: F,
) -> GuiResult<LayoutRect>
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.