taffy

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 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 child_count(&self, parent: NodeId) -> TaffyResult<usize>

Returns the number of children of the parent node

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

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

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.