Struct taffy::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 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 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

source

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

Indicates whether the layout of this node (and its children) need 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 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>

§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.