pub struct Taffy { /* private fields */ }Expand description
A tree of UI Nodes, suitable for UI layout
Implementations§
source§impl Taffy
impl Taffy
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new Taffy 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) -> TaffyResult<Node>
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
sourcepub fn new_leaf_with_measure(
&mut self,
layout: Style,
measure: MeasureFunc
) -> TaffyResult<Node>
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
sourcepub fn new_with_children(
&mut self,
layout: Style,
children: &[Node]
) -> TaffyResult<Node>
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
sourcepub fn remove(&mut self, node: Node) -> TaffyResult<Node>
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.
sourcepub fn set_measure(
&mut self,
node: Node,
measure: Option<MeasureFunc>
) -> TaffyResult<()>
pub fn set_measure( &mut self, node: Node, measure: Option<MeasureFunc> ) -> TaffyResult<()>
Sets the MeasureFunc of the associated node
sourcepub fn add_child(&mut self, parent: Node, child: Node) -> TaffyResult<()>
pub fn add_child(&mut self, parent: Node, child: Node) -> TaffyResult<()>
Adds a child Node under the supplied parent
sourcepub fn set_children(
&mut self,
parent: Node,
children: &[Node]
) -> TaffyResult<()>
pub fn set_children( &mut self, parent: Node, children: &[Node] ) -> TaffyResult<()>
Directly sets the children of the supplied parent
sourcepub fn remove_child(&mut self, parent: Node, child: Node) -> TaffyResult<Node>
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.
sourcepub fn remove_child_at_index(
&mut self,
parent: Node,
child_index: usize
) -> TaffyResult<Node>
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.
sourcepub fn replace_child_at_index(
&mut self,
parent: Node,
child_index: usize,
new_child: Node
) -> TaffyResult<Node>
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.
sourcepub fn child_at_index(
&self,
parent: Node,
child_index: usize
) -> TaffyResult<Node>
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
sourcepub fn child_count(&self, parent: Node) -> TaffyResult<usize>
pub fn child_count(&self, parent: Node) -> TaffyResult<usize>
Returns the number of children of the parent Node
sourcepub fn children(&self, parent: Node) -> TaffyResult<Vec<Node>>
pub fn children(&self, parent: Node) -> TaffyResult<Vec<Node>>
Returns a list of children that belong to the parent Node
sourcepub fn set_style(&mut self, node: Node, style: Style) -> TaffyResult<()>
pub fn set_style(&mut self, node: Node, style: Style) -> TaffyResult<()>
Sets the Style of the provided node
sourcepub fn layout(&self, node: Node) -> TaffyResult<&Layout>
pub fn layout(&self, node: Node) -> TaffyResult<&Layout>
Return this node layout relative to its parent
sourcepub fn dirty(&self, node: Node) -> TaffyResult<bool>
pub fn dirty(&self, node: Node) -> TaffyResult<bool>
Indicates whether the layout of this node (and its children) need to be recomputed
sourcepub fn compute_layout(
&mut self,
node: Node,
available_space: Size<AvailableSpace>
) -> Result<(), TaffyError>
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