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) -> TaffyTree<NodeContext>
pub fn with_capacity(capacity: usize) -> TaffyTree<NodeContext>
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) -> 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
Sourcepub 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
Sourcepub 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
Sourcepub 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.
Sourcepub 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
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 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.
Sourcepub 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
Sourcepub 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.
Sourcepub 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
Sourcepub 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.
Sourcepub 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.
Sourcepub fn remove_children_range<R>(
&mut self,
parent: NodeId,
range: R,
) -> Result<(), TaffyError>where
R: RangeBounds<usize>,
pub fn remove_children_range<R>(
&mut self,
parent: NodeId,
range: R,
) -> Result<(), TaffyError>where
R: RangeBounds<usize>,
Removes children at the given range from the parent
Children are not removed from the tree entirely, they are simply no longer attached to their previous parent.
Function will panic if given range is invalid. See core::slice::range
Sourcepub 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.
Sourcepub 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
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 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
Sourcepub 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
Sourcepub 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
Sourcepub fn style(&self, node: NodeId) -> Result<&Style, TaffyError>
pub fn style(&self, node: NodeId) -> Result<&Style, TaffyError>
Gets the Style of the provided node
Sourcepub 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
Sourcepub fn unrounded_layout(&self, node: NodeId) -> &Layout
pub fn unrounded_layout(&self, node: NodeId) -> &Layout
Returns this node layout with unrounded values relative to its parent.
Sourcepub fn detailed_layout_info(&self, node_id: NodeId) -> &DetailedLayoutInfo
pub fn detailed_layout_info(&self, node_id: NodeId) -> &DetailedLayoutInfo
Get the “detailed layout info” for a node.
Currently this is only implemented for CSS Grid containers where it contains the computed size of each grid track and the computed placement of each grid item
Sourcepub fn mark_dirty(&mut self, node: NodeId) -> Result<(), TaffyError>
pub fn mark_dirty(&mut self, node: NodeId) -> Result<(), TaffyError>
Marks the layout of this node and its ancestors as outdated
Sourcepub fn dirty(&self, node: NodeId) -> Result<bool, TaffyError>
pub fn dirty(&self, node: NodeId) -> Result<bool, TaffyError>
Indicates whether the layout of this node needs 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
Trait Implementations§
Source§impl<NodeContext> CacheTree for TaffyTree<NodeContext>
impl<NodeContext> CacheTree for TaffyTree<NodeContext>
Source§fn cache_get(
&self,
node_id: NodeId,
known_dimensions: Size<Option<f32>>,
available_space: Size<AvailableSpace>,
run_mode: RunMode,
) -> Option<LayoutOutput>
fn cache_get( &self, node_id: NodeId, known_dimensions: Size<Option<f32>>, available_space: Size<AvailableSpace>, run_mode: RunMode, ) -> Option<LayoutOutput>
Source§fn cache_store(
&mut self,
node_id: NodeId,
known_dimensions: Size<Option<f32>>,
available_space: Size<AvailableSpace>,
run_mode: RunMode,
layout_output: LayoutOutput,
)
fn cache_store( &mut self, node_id: NodeId, known_dimensions: Size<Option<f32>>, available_space: Size<AvailableSpace>, run_mode: RunMode, layout_output: LayoutOutput, )
Source§fn cache_clear(&mut self, node_id: NodeId)
fn cache_clear(&mut self, node_id: NodeId)
Source§impl<NodeContext> PrintTree for TaffyTree<NodeContext>
impl<NodeContext> PrintTree for TaffyTree<NodeContext>
Source§fn get_debug_label(&self, node_id: NodeId) -> &'static str
fn get_debug_label(&self, node_id: NodeId) -> &'static str
Source§fn get_final_layout(&self, node_id: NodeId) -> Layout
fn get_final_layout(&self, node_id: NodeId) -> Layout
Source§impl<NodeContext> TraversePartialTree for TaffyTree<NodeContext>
impl<NodeContext> TraversePartialTree for TaffyTree<NodeContext>
Source§type ChildIter<'a> = TaffyTreeChildIter<'a>
where
TaffyTree<NodeContext>: 'a
type ChildIter<'a> = TaffyTreeChildIter<'a> where TaffyTree<NodeContext>: 'a
Source§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<'_>
Source§fn child_count(&self, parent_node_id: NodeId) -> usize
fn child_count(&self, parent_node_id: NodeId) -> usize
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>
impl<NodeContext = ()> !Sync for TaffyTree<NodeContext>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.