Struct taffy::node::Taffy

source ·
pub struct Taffy { /* private fields */ }
Expand description

A tree of UI Nodes, suitable for UI layout

Implementations§

source§

impl Taffy

source

pub fn new() -> Self

Creates a new Taffy

The default capacity of a Taffy is 16 nodes.

source

pub fn with_capacity(capacity: usize) -> Self

Creates a new Taffy 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<Node>

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_measure( &mut self, layout: Style, measure: MeasureFunc ) -> TaffyResult<Node>

Creates and adds a new unattached leaf node to the tree, and returns the Node of the new node

Creates and adds a new leaf node with a supplied MeasureFunc

source

pub fn new_with_children( &mut self, layout: Style, children: &[Node] ) -> TaffyResult<Node>

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: Node) -> TaffyResult<Node>

Remove a specific Node from the tree and drops it

Returns the id of the node removed.

source

pub fn set_measure( &mut self, node: Node, measure: Option<MeasureFunc> ) -> TaffyResult<()>

Sets the MeasureFunc of the associated node

source

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

Adds a child Node under the supplied parent

source

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

Directly sets the children of the supplied parent

source

pub fn remove_child(&mut self, parent: Node, child: Node) -> TaffyResult<Node>

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: Node, child_index: usize ) -> TaffyResult<Node>

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: Node, child_index: usize, new_child: Node ) -> TaffyResult<Node>

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: Node, child_index: usize ) -> TaffyResult<Node>

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: Node) -> TaffyResult<usize>

Returns the number of children of the parent Node

source

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

Returns a list of children that belong to the parent Node

source

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

Sets the Style of the provided node

source

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

Gets the Style of the provided node

source

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

Return this node layout relative to its parent

source

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

Indicates whether the layout of this node (and its children) need to be recomputed

source

pub fn compute_layout( &mut self, node: Node, available_space: Size<AvailableSpace> ) -> Result<(), TaffyError>

Updates the stored layout of the provided node and its children

Trait Implementations§

source§

impl Default for Taffy

source§

fn default() -> Self

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

impl LayoutTree for Taffy

§

type ChildIter<'a> = Iter<'a, DefaultKey>

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

fn children(&self, node: Node) -> Self::ChildIter<'_>

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

fn child_count(&self, node: Node) -> usize

Get the number of children for the given node
source§

fn is_childless(&self, node: Node) -> bool

Returns true if the node has no children
source§

fn parent(&self, node: Node) -> Option<Node>

Get any available parent for this node
source§

fn style(&self, node: Node) -> &Style

Get the Style for this Node.
source§

fn layout(&self, node: Node) -> &Layout

Get the node’s output “Final Layout”
source§

fn layout_mut(&mut self, node: Node) -> &mut Layout

Modify the node’s output layout
source§

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

Mark a node as dirty to tell Taffy that something has changed and it needs to be recomputed. Read more
source§

fn measure_node( &self, node: Node, known_dimensions: Size<Option<f32>>, available_space: Size<AvailableSpace> ) -> Size<f32>

Measure a node. Taffy uses this to force reflows of things like text and overflowing content.
source§

fn needs_measure(&self, node: Node) -> bool

Node needs to be measured
source§

fn cache_mut(&mut self, node: Node, index: usize) -> &mut Option<Cache>

Get a cache entry for this Node by index
source§

fn child(&self, node: Node, id: usize) -> Node

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Taffy

§

impl Send for Taffy

§

impl Sync for Taffy

§

impl Unpin for Taffy

§

impl !UnwindSafe for Taffy

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.