Remove duplicate types definitions (`Layout`, `RunMode`, `SizingMode`, `SizeAndBaselines`) (#469)
1//! Contains both [a high-level interface to Taffy](crate::Taffy) using a ready-made node tree, and [a trait for defining a custom node trees](crate::tree::LayoutTree) / utility types to help with that.
2
3use crate::geometry::Size;
4use crate::style::{AvailableSpace, Style};
5
6// Submodules
7mod cache;
8pub use cache::{Cache, CacheEntry};
9mod measure_func;
10pub use measure_func::{Measurable, MeasureFunc};
11mod node;
12#[cfg(feature = "taffy_tree")]
13pub(self) use node::NodeData;
14pub use node::NodeId;
15#[cfg(feature = "taffy_tree")]
16mod taffy_tree;
17#[cfg(feature = "taffy_tree")]
18pub use taffy_tree::{Taffy, TaffyChildIter, TaffyError, TaffyResult};
19mod layout;
20pub use layout::{Layout, RunMode, SizeAndBaselines, SizingMode};
21
22/// Any item that implements the LayoutTree can be layed out using Taffy's algorithms.
23///
24/// Generally, Taffy expects your Node tree to be indexable by stable indices. A "stable" index means that the Node's ID
25/// remains the same between re-layouts.
26pub trait LayoutTree {
27 /// Type representing an iterator of the children of a node
28 type ChildIter<'a>: Iterator<Item = NodeId>
29 where
30 Self: 'a;
31
32 /// Get the list of children IDs for the given node
33 fn children(&self, node: NodeId) -> Self::ChildIter<'_>;
34
35 /// Get the number of children for the given node
36 fn child_count(&self, node: NodeId) -> usize;
37
38 /// Get a specific child of a node, where the index represents the nth child
39 fn child(&self, node: NodeId, index: usize) -> NodeId;
40
41 /// Get the [`Style`] for this node.
42 fn style(&self, node: NodeId) -> &Style;
43
44 /// Get a reference to the node's output layout
45 fn layout(&self, node: NodeId) -> &Layout;
46
47 /// Modify the node's output layout
48 fn layout_mut(&mut self, node: NodeId) -> &mut Layout;
49
50 /// Compute the size of the node given the specified constraints
51 fn measure_child_size(
52 &mut self,
53 node: NodeId,
54 known_dimensions: Size<Option<f32>>,
55 parent_size: Size<Option<f32>>,
56 available_space: Size<AvailableSpace>,
57 sizing_mode: SizingMode,
58 ) -> Size<f32>;
59
60 /// Perform a full layout on the node given the specified constraints
61 fn perform_child_layout(
62 &mut self,
63 node: NodeId,
64 known_dimensions: Size<Option<f32>>,
65 parent_size: Size<Option<f32>>,
66 available_space: Size<AvailableSpace>,
67 sizing_mode: SizingMode,
68 ) -> SizeAndBaselines;
69}