plasmo

Trait LayoutTree

Source
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§

Source

type ChildIter<'a>: Iterator<Item = &'a DefaultKey> where Self: 'a

Type representing an iterator of the children of a node

Required Methods§

Source

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

Get the list of children IDs for the given node

Source

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

Get the number of children for the given node

Source

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

Returns true if the node has no children

Source

fn child(&self, node: DefaultKey, index: usize) -> DefaultKey

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

Source

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

Get any available parent for this node

Source

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

Get the Style for this Node.

Source

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

Get the node’s output “Final Layout”

Source

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

Modify the node’s output layout

Source

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.

Source

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.

Source

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

Node needs to be measured

Source

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

Get a cache entry for this Node by index

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.

Implementors§