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§
§impl<NodeContext> TaffyTree<NodeContext>
impl<NodeContext> TaffyTree<NodeContext>
pub fn with_capacity(capacity: usize) -> TaffyTree<NodeContext>
pub fn with_capacity(capacity: usize) -> TaffyTree<NodeContext>
Creates a new TaffyTree
that can store capacity
nodes before reallocation
pub fn enable_rounding(&mut self)
pub fn enable_rounding(&mut self)
Enable rounding of layout values. Rounding is enabled by default.
pub fn disable_rounding(&mut self)
pub fn disable_rounding(&mut self)
Disable rounding of layout values. Rounding is enabled by default.
pub fn new_leaf(&mut self, layout: Style) -> Result<NodeId, TaffyError>
pub fn new_leaf(&mut self, layout: Style) -> Result<NodeId, TaffyError>
Creates and adds a new unattached leaf node to the tree, and returns the node of the new node
pub fn new_leaf_with_context(
&mut self,
layout: Style,
context: NodeContext,
) -> Result<NodeId, TaffyError>
pub fn new_leaf_with_context( &mut self, layout: Style, context: NodeContext, ) -> Result<NodeId, TaffyError>
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
pub fn new_with_children(
&mut self,
layout: Style,
children: &[NodeId],
) -> Result<NodeId, TaffyError>
pub fn new_with_children( &mut self, layout: Style, children: &[NodeId], ) -> Result<NodeId, TaffyError>
Creates and adds a new node, which may have any number of children
pub fn clear(&mut self)
pub fn clear(&mut self)
Drops all nodes in the tree
pub fn remove(&mut self, node: NodeId) -> Result<NodeId, TaffyError>
pub fn remove(&mut self, node: NodeId) -> Result<NodeId, TaffyError>
Remove a specific node from the tree and drop it
Returns the id of the node removed.
pub fn set_node_context(
&mut self,
node: NodeId,
measure: Option<NodeContext>,
) -> Result<(), TaffyError>
pub fn set_node_context( &mut self, node: NodeId, measure: Option<NodeContext>, ) -> Result<(), TaffyError>
Sets the context data associated with the node
pub 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
pub 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
pub fn get_disjoint_node_context_mut<const N: usize>(
&mut self,
keys: [NodeId; N],
) -> Option<[&mut NodeContext; N]>
pub fn get_disjoint_node_context_mut<const N: usize>( &mut self, keys: [NodeId; N], ) -> Option<[&mut NodeContext; N]>
Gets mutable references to the the context data associated with the nodes. All keys must be valid and disjoint, otherwise None is returned.
pub fn add_child(
&mut self,
parent: NodeId,
child: NodeId,
) -> Result<(), TaffyError>
pub fn add_child( &mut self, parent: NodeId, child: NodeId, ) -> Result<(), TaffyError>
Adds a child
node under the supplied parent
pub fn insert_child_at_index(
&mut self,
parent: NodeId,
child_index: usize,
child: NodeId,
) -> Result<(), TaffyError>
pub fn insert_child_at_index( &mut self, parent: NodeId, child_index: usize, child: NodeId, ) -> Result<(), TaffyError>
Inserts a child
node at the given child_index
under the supplied parent
, shifting all children after it to the right.
pub fn set_children(
&mut self,
parent: NodeId,
children: &[NodeId],
) -> Result<(), TaffyError>
pub fn set_children( &mut self, parent: NodeId, children: &[NodeId], ) -> Result<(), TaffyError>
Directly sets the children
of the supplied parent
pub fn remove_child(
&mut self,
parent: NodeId,
child: NodeId,
) -> Result<NodeId, TaffyError>
pub fn remove_child( &mut self, parent: NodeId, child: NodeId, ) -> Result<NodeId, TaffyError>
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.
pub fn remove_child_at_index(
&mut self,
parent: NodeId,
child_index: usize,
) -> Result<NodeId, TaffyError>
pub fn remove_child_at_index( &mut self, parent: NodeId, child_index: usize, ) -> Result<NodeId, TaffyError>
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.
pub fn replace_child_at_index(
&mut self,
parent: NodeId,
child_index: usize,
new_child: NodeId,
) -> Result<NodeId, TaffyError>
pub fn replace_child_at_index( &mut self, parent: NodeId, child_index: usize, new_child: NodeId, ) -> Result<NodeId, TaffyError>
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.
pub fn child_at_index(
&self,
parent: NodeId,
child_index: usize,
) -> Result<NodeId, TaffyError>
pub fn child_at_index( &self, parent: NodeId, child_index: usize, ) -> Result<NodeId, TaffyError>
Returns the child node of the parent node
at the provided child_index
pub fn total_node_count(&self) -> usize
pub fn total_node_count(&self) -> usize
Returns the total number of nodes in the tree
pub fn parent(&self, child_id: NodeId) -> Option<NodeId>
pub fn parent(&self, child_id: NodeId) -> Option<NodeId>
Returns the NodeId
of the parent node of the specified node (if it exists)
- Return None if the specified node has no parent
- Panics if the specified node does not exist
pub fn children(&self, parent: NodeId) -> Result<Vec<NodeId>, TaffyError>
pub fn children(&self, parent: NodeId) -> Result<Vec<NodeId>, TaffyError>
Returns a list of children that belong to the parent node
pub fn set_style(
&mut self,
node: NodeId,
style: Style,
) -> Result<(), TaffyError>
pub fn set_style( &mut self, node: NodeId, style: Style, ) -> Result<(), TaffyError>
Sets the Style
of the provided node
pub fn layout(&self, node: NodeId) -> Result<&Layout, TaffyError>
pub fn layout(&self, node: NodeId) -> Result<&Layout, TaffyError>
Return this node layout relative to its parent
pub fn mark_dirty(&mut self, node: NodeId) -> Result<(), TaffyError>
pub fn mark_dirty(&mut self, node: NodeId) -> Result<(), TaffyError>
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
pub fn dirty(&self, node: NodeId) -> Result<bool, TaffyError>
pub fn dirty(&self, node: NodeId) -> Result<bool, TaffyError>
Indicates whether the layout of this node (and its children) need to be recomputed
pub 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
pub 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
pub fn print_tree(&mut self, root: NodeId)
pub fn print_tree(&mut self, root: NodeId)
Prints a debug representation of the tree’s layout
Trait Implementations§
§impl<NodeContext> PrintTree for TaffyTree<NodeContext>
impl<NodeContext> PrintTree for TaffyTree<NodeContext>
§fn get_debug_label(&self, node_id: NodeId) -> &'static str
fn get_debug_label(&self, node_id: NodeId) -> &'static str
§fn get_final_layout(&self, node_id: NodeId) -> &Layout
fn get_final_layout(&self, node_id: NodeId) -> &Layout
§impl<NodeContext> TraversePartialTree for TaffyTree<NodeContext>
impl<NodeContext> TraversePartialTree for TaffyTree<NodeContext>
§type ChildIter<'a> = TaffyTreeChildIter<'a>
where
TaffyTree<NodeContext>: 'a
type ChildIter<'a> = TaffyTreeChildIter<'a> where TaffyTree<NodeContext>: 'a
§fn child_ids(
&self,
parent_node_id: NodeId,
) -> <TaffyTree<NodeContext> as TraversePartialTree>::ChildIter<'_>
fn child_ids( &self, parent_node_id: NodeId, ) -> <TaffyTree<NodeContext> as TraversePartialTree>::ChildIter<'_>
§fn child_count(&self, parent_node_id: NodeId) -> usize
fn child_count(&self, parent_node_id: NodeId) -> usize
§fn get_child_id(&self, parent_node_id: NodeId, id: usize) -> NodeId
fn get_child_id(&self, parent_node_id: NodeId, id: usize) -> NodeId
impl<NodeContext> TraverseTree for TaffyTree<NodeContext>
Auto Trait Implementations§
impl<NodeContext> Freeze for TaffyTree<NodeContext>
impl<NodeContext> RefUnwindSafe for TaffyTree<NodeContext>where
NodeContext: RefUnwindSafe,
impl<NodeContext> Send for TaffyTree<NodeContext>where
NodeContext: Send,
impl<NodeContext> Sync for TaffyTree<NodeContext>where
NodeContext: Sync,
impl<NodeContext> Unpin for TaffyTree<NodeContext>where
NodeContext: Unpin,
impl<NodeContext> UnwindSafe for TaffyTree<NodeContext>where
NodeContext: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more