1use crate::geometry::{AbsoluteAxis, Line, Size};
4use crate::style::{AvailableSpace, Style};
5
6mod cache;
8pub use cache::Cache;
9mod node;
10#[cfg(feature = "taffy_tree")]
11use node::NodeData;
12pub use node::NodeId;
13#[cfg(feature = "taffy_tree")]
14mod taffy_tree;
15#[cfg(feature = "taffy_tree")]
16pub use taffy_tree::{TaffyError, TaffyResult, TaffyTree};
17mod layout;
18pub use layout::{CollapsibleMarginSet, Layout, LayoutInput, LayoutOutput, RequestedAxis, RunMode, SizingMode};
19
20pub trait PartialLayoutTree {
26 type ChildIter<'a>: Iterator<Item = NodeId>
28 where
29 Self: 'a;
30
31 fn child_ids(&self, parent_node_id: NodeId) -> Self::ChildIter<'_>;
33
34 fn child_count(&self, parent_node_id: NodeId) -> usize;
36
37 fn get_child_id(&self, parent_node_id: NodeId, child_index: usize) -> NodeId;
39
40 fn get_style(&self, node_id: NodeId) -> &Style;
42
43 fn set_unrounded_layout(&mut self, node_id: NodeId, layout: &Layout);
45
46 fn get_cache_mut(&mut self, node_id: NodeId) -> &mut Cache;
48
49 fn compute_child_layout(&mut self, node_id: NodeId, inputs: LayoutInput) -> LayoutOutput;
51}
52
53pub trait LayoutTree: PartialLayoutTree {
56 fn get_unrounded_layout(&self, node_id: NodeId) -> &Layout;
58 fn get_final_layout(&self, node_id: NodeId) -> &Layout;
60 fn set_final_layout(&mut self, node_id: NodeId, layout: &Layout);
62}
63
64pub(crate) trait PartialLayoutTreeExt: PartialLayoutTree {
67 #[inline(always)]
69 #[allow(clippy::too_many_arguments)]
70 fn measure_child_size(
71 &mut self,
72 node_id: NodeId,
73 known_dimensions: Size<Option<f32>>,
74 parent_size: Size<Option<f32>>,
75 available_space: Size<AvailableSpace>,
76 sizing_mode: SizingMode,
77 axis: AbsoluteAxis,
78 vertical_margins_are_collapsible: Line<bool>,
79 ) -> f32 {
80 self.compute_child_layout(
81 node_id,
82 LayoutInput {
83 known_dimensions,
84 parent_size,
85 available_space,
86 sizing_mode,
87 axis: axis.into(),
88 run_mode: RunMode::ComputeSize,
89 vertical_margins_are_collapsible,
90 },
91 )
92 .size
93 .get_abs(axis)
94 }
95
96 #[inline(always)]
98 fn perform_child_layout(
99 &mut self,
100 node_id: NodeId,
101 known_dimensions: Size<Option<f32>>,
102 parent_size: Size<Option<f32>>,
103 available_space: Size<AvailableSpace>,
104 sizing_mode: SizingMode,
105 vertical_margins_are_collapsible: Line<bool>,
106 ) -> LayoutOutput {
107 self.compute_child_layout(
108 node_id,
109 LayoutInput {
110 known_dimensions,
111 parent_size,
112 available_space,
113 sizing_mode,
114 axis: RequestedAxis::Both,
115 run_mode: RunMode::PerformLayout,
116 vertical_margins_are_collapsible,
117 },
118 )
119 }
120}
121
122impl<T: PartialLayoutTree> PartialLayoutTreeExt for T {}