TaffyTree

Struct TaffyTree 

Source
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>

Source

pub fn new() -> Self

Creates a new TaffyTree

The default capacity of a TaffyTree is 16 nodes.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new TaffyTree that can store capacity nodes before reallocation

Source

pub fn enable_rounding(&mut self)

Enable rounding of layout values. Rounding is enabled by default.

Source

pub fn disable_rounding(&mut self)

Disable rounding of layout values. Rounding is enabled by default.

Source

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

Source

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

Source

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

Source

pub fn clear(&mut self)

Drops all nodes in the tree

Source

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.

Source

pub fn set_node_context( &mut self, node: NodeId, measure: Option<NodeContext>, ) -> TaffyResult<()>

Sets the context data associated with the node

Source

pub fn get_node_context(&self, node: NodeId) -> Option<&NodeContext>

Gets a reference to the the context data associated with the node

Source

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

Source

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.

Source

pub fn add_child(&mut self, parent: NodeId, child: NodeId) -> TaffyResult<()>

Adds a child node under the supplied parent

Source

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.

Source

pub fn set_children( &mut self, parent: NodeId, children: &[NodeId], ) -> TaffyResult<()>

Directly sets the children of the supplied parent

Source

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.

Source

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.

Source

pub fn remove_children_range<R>( &mut self, parent: NodeId, range: R, ) -> TaffyResult<()>
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

Source

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.

Source

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

Source

pub fn total_node_count(&self) -> usize

Returns the total number of nodes in the tree

Source

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
Source

pub fn children(&self, parent: NodeId) -> TaffyResult<Vec<NodeId>>

Returns a list of children that belong to the parent node

Source

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

Sets the Style of the provided node

Source

pub fn style(&self, node: NodeId) -> TaffyResult<&Style>

Gets the Style of the provided node

Source

pub fn layout(&self, node: NodeId) -> TaffyResult<&Layout>

Return this node layout relative to its parent

Source

pub fn unrounded_layout(&self, node: NodeId) -> &Layout

Returns this node layout with unrounded values relative to its parent.

Source

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

Source

pub fn mark_dirty(&mut self, node: NodeId) -> TaffyResult<()>

Marks the layout of this node and its ancestors as outdated

WARNING: this may stack-overflow if the tree contains a cycle

Source

pub fn dirty(&self, node: NodeId) -> TaffyResult<bool>

Indicates whether the layout of this node needs to be recomputed

Source

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

Source

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

Source

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>

Source§

fn cache_get( &self, node_id: NodeId, known_dimensions: Size<Option<f32>>, available_space: Size<AvailableSpace>, run_mode: RunMode, ) -> Option<LayoutOutput>

Try to retrieve a cached result from the cache
Source§

fn cache_store( &mut self, node_id: NodeId, known_dimensions: Size<Option<f32>>, available_space: Size<AvailableSpace>, run_mode: RunMode, layout_output: LayoutOutput, )

Store a computed size in the cache
Source§

fn cache_clear(&mut self, node_id: NodeId)

Clear all cache entries for the node
Source§

impl<NodeContext: Clone> Clone for TaffyTree<NodeContext>

Source§

fn clone(&self) -> TaffyTree<NodeContext>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<NodeContext: Debug> Debug for TaffyTree<NodeContext>

Source§

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

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

impl Default for TaffyTree

Source§

fn default() -> TaffyTree<()>

Returns the “default value” for a type. Read more
Source§

impl<NodeContext> PrintTree for TaffyTree<NodeContext>

Source§

fn get_debug_label(&self, node_id: NodeId) -> &'static str

Get a debug label for the node (typically the type of node: flexbox, grid, text, image, etc)
Source§

fn get_final_layout(&self, node_id: NodeId) -> &Layout

Get a reference to the node’s final layout
Source§

impl<NodeContext> TraversePartialTree for TaffyTree<NodeContext>

Source§

type ChildIter<'a> = TaffyTreeChildIter<'a> where Self: 'a

Type representing an iterator of the children of a node
Source§

fn child_ids(&self, parent_node_id: NodeId) -> Self::ChildIter<'_>

Get the list of children IDs for the given node
Source§

fn child_count(&self, parent_node_id: NodeId) -> usize

Get the number of children for the given node
Source§

fn get_child_id(&self, parent_node_id: NodeId, id: usize) -> NodeId

Get a specific child of a node, where the index represents the nth child
Source§

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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.