tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definiciones

⎇ 82b3fc7e42222239eb09e2ae4c242ed3efc5aa0e src/tree.rs Rust · 53 líneas · 2.0 KB Historia Quién tocó qué crudo

Improve working and correctness of doc-comment (#256) 82b3fc7e4 · Andreas Weibye ·

1//! The baseline requirements of any UI Tree so Taffy can efficiently calculate the layout
2
3use crate::{
4    error::TaffyResult,
5    layout::{AvailableSpace, Cache, Layout},
6    prelude::*,
7};
8
9/// Any item that implements the LayoutTree can be layed out using Taffy's algorithms.
10///
11/// Generally, Taffy expects your Node tree to be indexable by stable indices. A "stable" index means that the Node's ID
12/// remains the same between re-layouts.
13pub trait LayoutTree {
14    /// Get the list of children IDs for the given node
15    fn children(&self, node: Node) -> &[Node];
16
17    /// Get a specific child of a node, where the index represents the nth child
18    fn child(&self, node: Node, index: usize) -> Node;
19
20    /// Get any available parent for this node
21    fn parent(&self, node: Node) -> Option<Node>;
22
23    // todo: allow abstractions over this so we don't prescribe how layout works
24    // for reference, CSS cascades require context, and storing a full flexbox layout for each node could be inefficient
25    //
26    /// Get the [`Style`] for this Node.
27    fn style(&self, node: Node) -> &Style;
28
29    /// Get the node's output "Final Layout"
30    fn layout(&self, node: Node) -> &Layout;
31
32    /// Modify the node's output layout
33    fn layout_mut(&mut self, node: Node) -> &mut Layout;
34
35    /// Mark a node as dirty to tell Taffy that something has changed and it needs to be recomputed.
36    ///
37    /// Commonly done if the style of the node has changed.
38    fn mark_dirty(&mut self, node: Node) -> TaffyResult<()>;
39
40    /// Measure a node. Taffy uses this to force reflows of things like text and overflowing content.
41    fn measure_node(
42        &self,
43        node: Node,
44        known_dimensions: Size<Option<f32>>,
45        available_space: Size<AvailableSpace>,
46    ) -> Size<f32>;
47
48    /// Node needs to be measured
49    fn needs_measure(&self, node: Node) -> bool;
50
51    /// Get a cache entry for this Node by index
52    fn cache_mut(&mut self, node: Node, index: usize) -> &mut Option<Cache>;
53}