pub trait LayoutTree {
type ChildIter<'a>: Iterator<Item = &'a DefaultKey>
where Self: 'a;
// Required methods
fn children(&self, node: DefaultKey) -> Self::ChildIter<'_>;
fn child_count(&self, node: DefaultKey) -> usize;
fn is_childless(&self, node: DefaultKey) -> bool;
fn child(&self, node: DefaultKey, index: usize) -> DefaultKey;
fn parent(&self, node: DefaultKey) -> Option<DefaultKey>;
fn style(&self, node: DefaultKey) -> &Style;
fn layout(&self, node: DefaultKey) -> &Layout;
fn layout_mut(&mut self, node: DefaultKey) -> &mut Layout;
fn mark_dirty(&mut self, node: DefaultKey) -> Result<(), TaffyError>;
fn measure_node(
&self,
node: DefaultKey,
known_dimensions: Size<Option<f32>>,
available_space: Size<AvailableSpace>,
) -> Size<f32>;
fn needs_measure(&self, node: DefaultKey) -> bool;
fn cache_mut(
&mut self,
node: DefaultKey,
index: usize,
) -> &mut Option<Cache>;
}Expand description
Any item that implements the LayoutTree can be layed out using Taffy’s algorithms.
Generally, Taffy expects your Node tree to be indexable by stable indices. A “stable” index means that the Node’s ID remains the same between re-layouts.
Required Associated Types§
Sourcetype ChildIter<'a>: Iterator<Item = &'a DefaultKey>
where
Self: 'a
type ChildIter<'a>: Iterator<Item = &'a DefaultKey> where Self: 'a
Type representing an iterator of the children of a node
Required Methods§
Sourcefn children(&self, node: DefaultKey) -> Self::ChildIter<'_>
fn children(&self, node: DefaultKey) -> Self::ChildIter<'_>
Get the list of children IDs for the given node
Sourcefn child_count(&self, node: DefaultKey) -> usize
fn child_count(&self, node: DefaultKey) -> usize
Get the number of children for the given node
Sourcefn is_childless(&self, node: DefaultKey) -> bool
fn is_childless(&self, node: DefaultKey) -> bool
Returns true if the node has no children
Sourcefn child(&self, node: DefaultKey, index: usize) -> DefaultKey
fn child(&self, node: DefaultKey, index: usize) -> DefaultKey
Get a specific child of a node, where the index represents the nth child
Sourcefn parent(&self, node: DefaultKey) -> Option<DefaultKey>
fn parent(&self, node: DefaultKey) -> Option<DefaultKey>
Get any available parent for this node
Sourcefn style(&self, node: DefaultKey) -> &Style
fn style(&self, node: DefaultKey) -> &Style
Get the Style for this Node.
Sourcefn layout(&self, node: DefaultKey) -> &Layout
fn layout(&self, node: DefaultKey) -> &Layout
Get the node’s output “Final Layout”
Sourcefn layout_mut(&mut self, node: DefaultKey) -> &mut Layout
fn layout_mut(&mut self, node: DefaultKey) -> &mut Layout
Modify the node’s output layout
Sourcefn mark_dirty(&mut self, node: DefaultKey) -> Result<(), TaffyError>
fn mark_dirty(&mut self, node: DefaultKey) -> Result<(), TaffyError>
Mark a node as dirty to tell Taffy that something has changed and it needs to be recomputed.
Commonly done if the style of the node has changed.
Sourcefn measure_node(
&self,
node: DefaultKey,
known_dimensions: Size<Option<f32>>,
available_space: Size<AvailableSpace>,
) -> Size<f32>
fn measure_node( &self, node: DefaultKey, 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.
Sourcefn needs_measure(&self, node: DefaultKey) -> bool
fn needs_measure(&self, node: DefaultKey) -> bool
Node needs to be measured
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.