pub struct TaffyTree<NodeContext = ()> { /* private fields */ }
Expand description
An entire tree of UI nodes. The entry point to Taffy’s high-level API.
Allows you to build a tree of UI nodes, run Taffy’s layout algorithms over that tree, and then access the resultant layout.
Implementations§
source§impl<NodeContext> TaffyTree<NodeContext>
impl<NodeContext> TaffyTree<NodeContext>
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new TaffyTree
that can store capacity
nodes before reallocation
sourcepub fn enable_rounding(&mut self)
pub fn enable_rounding(&mut self)
Enable rounding of layout values. Rounding is enabled by default.
sourcepub fn disable_rounding(&mut self)
pub fn disable_rounding(&mut self)
Disable rounding of layout values. Rounding is enabled by default.
sourcepub fn new_leaf(&mut self, layout: Style) -> TaffyResult<NodeId>
pub fn new_leaf(&mut self, layout: Style) -> TaffyResult<NodeId>
Creates and adds a new unattached leaf node to the tree, and returns the node of the new node
sourcepub fn new_leaf_with_context(
&mut self,
layout: Style,
context: NodeContext,
) -> TaffyResult<NodeId>
pub fn new_leaf_with_context( &mut self, layout: Style, context: NodeContext, ) -> TaffyResult<NodeId>
Creates and adds a new unattached leaf node to the tree, and returns the NodeId
of the new node
Creates and adds a new leaf node with a supplied context
sourcepub fn new_with_children(
&mut self,
layout: Style,
children: &[NodeId],
) -> TaffyResult<NodeId>
pub fn new_with_children( &mut self, layout: Style, children: &[NodeId], ) -> TaffyResult<NodeId>
Creates and adds a new node, which may have any number of children
sourcepub fn remove(&mut self, node: NodeId) -> TaffyResult<NodeId>
pub fn remove(&mut self, node: NodeId) -> TaffyResult<NodeId>
Remove a specific node from the tree and drop it
Returns the id of the node removed.
sourcepub fn set_node_context(
&mut self,
node: NodeId,
measure: Option<NodeContext>,
) -> TaffyResult<()>
pub fn set_node_context( &mut self, node: NodeId, measure: Option<NodeContext>, ) -> TaffyResult<()>
Sets the context data associated with the node
sourcepub fn get_node_context(&self, node: NodeId) -> Option<&NodeContext>
pub fn get_node_context(&self, node: NodeId) -> Option<&NodeContext>
Gets a reference to the the context data associated with the node
sourcepub fn get_node_context_mut(&mut self, node: NodeId) -> Option<&mut NodeContext>
pub fn get_node_context_mut(&mut self, node: NodeId) -> Option<&mut NodeContext>
Gets a mutable reference to the the context data associated with the node
sourcepub fn add_child(&mut self, parent: NodeId, child: NodeId) -> TaffyResult<()>
pub fn add_child(&mut self, parent: NodeId, child: NodeId) -> TaffyResult<()>
Adds a child
node under the supplied parent
sourcepub fn insert_child_at_index(
&mut self,
parent: NodeId,
child_index: usize,
child: NodeId,
) -> TaffyResult<()>
pub fn insert_child_at_index( &mut self, parent: NodeId, child_index: usize, child: NodeId, ) -> TaffyResult<()>
Inserts a child
node at the given child_index
under the supplied parent
, shifting all children after it to the right.
sourcepub fn set_children(
&mut self,
parent: NodeId,
children: &[NodeId],
) -> TaffyResult<()>
pub fn set_children( &mut self, parent: NodeId, children: &[NodeId], ) -> TaffyResult<()>
Directly sets the children
of the supplied parent
sourcepub fn remove_child(
&mut self,
parent: NodeId,
child: NodeId,
) -> TaffyResult<NodeId>
pub fn remove_child( &mut self, parent: NodeId, child: NodeId, ) -> TaffyResult<NodeId>
Removes the child
of the parent node
The child is not removed from the tree entirely, it is simply no longer attached to its previous parent.
sourcepub fn remove_child_at_index(
&mut self,
parent: NodeId,
child_index: usize,
) -> TaffyResult<NodeId>
pub fn remove_child_at_index( &mut self, parent: NodeId, child_index: usize, ) -> TaffyResult<NodeId>
Removes the child at the given index
from the parent
The child is not removed from the tree entirely, it is simply no longer attached to its previous parent.
sourcepub fn replace_child_at_index(
&mut self,
parent: NodeId,
child_index: usize,
new_child: NodeId,
) -> TaffyResult<NodeId>
pub fn replace_child_at_index( &mut self, parent: NodeId, child_index: usize, new_child: NodeId, ) -> TaffyResult<NodeId>
Replaces the child at the given child_index
from the parent
node with the new child
node
The child is not removed from the tree entirely, it is simply no longer attached to its previous parent.
sourcepub fn child_at_index(
&self,
parent: NodeId,
child_index: usize,
) -> TaffyResult<NodeId>
pub fn child_at_index( &self, parent: NodeId, child_index: usize, ) -> TaffyResult<NodeId>
Returns the child node of the parent node
at the provided child_index
sourcepub fn total_node_count(&self) -> usize
pub fn total_node_count(&self) -> usize
Returns the total number of nodes in the tree
sourcepub fn child_count(&self, parent: NodeId) -> TaffyResult<usize>
pub fn child_count(&self, parent: NodeId) -> TaffyResult<usize>
Returns the number of children of the parent
node
sourcepub fn children(&self, parent: NodeId) -> TaffyResult<Vec<NodeId>>
pub fn children(&self, parent: NodeId) -> TaffyResult<Vec<NodeId>>
Returns a list of children that belong to the parent node
sourcepub fn set_style(&mut self, node: NodeId, style: Style) -> TaffyResult<()>
pub fn set_style(&mut self, node: NodeId, style: Style) -> TaffyResult<()>
Sets the Style
of the provided node
sourcepub fn layout(&self, node: NodeId) -> TaffyResult<&Layout>
pub fn layout(&self, node: NodeId) -> TaffyResult<&Layout>
Return this node layout relative to its parent
sourcepub fn mark_dirty(&mut self, node: NodeId) -> TaffyResult<()>
pub fn mark_dirty(&mut self, node: NodeId) -> TaffyResult<()>
Marks the layout computation of this node and its children as outdated
Performs a recursive depth-first search up the tree until the root node is reached
WARNING: this will stack-overflow if the tree contains a cycle
sourcepub fn dirty(&self, node: NodeId) -> TaffyResult<bool>
pub fn dirty(&self, node: NodeId) -> TaffyResult<bool>
Indicates whether the layout of this node (and its children) need to be recomputed
sourcepub fn compute_layout_with_measure<MeasureFunction>(
&mut self,
node_id: NodeId,
available_space: Size<AvailableSpace>,
measure_function: MeasureFunction,
) -> Result<(), TaffyError>
pub fn compute_layout_with_measure<MeasureFunction>( &mut self, node_id: NodeId, available_space: Size<AvailableSpace>, measure_function: MeasureFunction, ) -> Result<(), TaffyError>
Updates the stored layout of the provided node
and its children
sourcepub fn compute_layout(
&mut self,
node: NodeId,
available_space: Size<AvailableSpace>,
) -> Result<(), TaffyError>
pub fn compute_layout( &mut self, node: NodeId, available_space: Size<AvailableSpace>, ) -> Result<(), TaffyError>
Updates the stored layout of the provided node
and its children
sourcepub fn print_tree(&mut self, root: NodeId)
pub fn print_tree(&mut self, root: NodeId)
Prints a debug representation of the tree’s layout