Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn align_content_stretch_column() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node00 = taffy
7 .new_leaf(taffy::style::Style {
8 flex_grow: 1f32,
9 flex_shrink: 1f32,
10 flex_basis: taffy::style::Dimension::Percent(0f32),
11 ..Default::default()
12 })
13 .unwrap();
14 let node0 = taffy
15 .new_with_children(
16 taffy::style::Style {
17 flex_direction: taffy::style::FlexDirection::Column,
18 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(50f32) },
19 ..Default::default()
20 },
21 &[node00],
22 )
23 .unwrap();
24 let node1 = taffy
25 .new_leaf(taffy::style::Style {
26 flex_grow: 1f32,
27 flex_shrink: 1f32,
28 flex_basis: taffy::style::Dimension::Percent(0f32),
29 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(50f32) },
30 ..Default::default()
31 })
32 .unwrap();
33 let node2 = taffy
34 .new_leaf(taffy::style::Style {
35 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(50f32) },
36 ..Default::default()
37 })
38 .unwrap();
39 let node3 = taffy
40 .new_leaf(taffy::style::Style {
41 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(50f32) },
42 ..Default::default()
43 })
44 .unwrap();
45 let node4 = taffy
46 .new_leaf(taffy::style::Style {
47 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(50f32) },
48 ..Default::default()
49 })
50 .unwrap();
51 let node = taffy
52 .new_with_children(
53 taffy::style::Style {
54 flex_direction: taffy::style::FlexDirection::Column,
55 flex_wrap: taffy::style::FlexWrap::Wrap,
56 align_content: Some(taffy::style::AlignContent::Stretch),
57 size: taffy::geometry::Size {
58 width: taffy::style::Dimension::Length(100f32),
59 height: taffy::style::Dimension::Length(150f32),
60 },
61 ..Default::default()
62 },
63 &[node0, node1, node2, node3, node4],
64 )
65 .unwrap();
66 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
67 println!("\nComputed tree:");
68 taffy.print_tree(node);
69 println!();
70 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
71 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
72 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
73 assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node, 150f32, size.height);
74 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
75 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
76 #[cfg(feature = "content_size")]
77 assert_eq!(
78 layout.scroll_width(),
79 0f32,
80 "scroll_width of node {:?}. Expected {}. Actual {}",
81 node,
82 0f32,
83 layout.scroll_width()
84 );
85 #[cfg(feature = "content_size")]
86 assert_eq!(
87 layout.scroll_height(),
88 0f32,
89 "scroll_height of node {:?}. Expected {}. Actual {}",
90 node,
91 0f32,
92 layout.scroll_height()
93 );
94 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
95 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
96 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
97 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
98 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
99 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
100 #[cfg(feature = "content_size")]
101 assert_eq!(
102 layout.scroll_width(),
103 0f32,
104 "scroll_width of node {:?}. Expected {}. Actual {}",
105 node0,
106 0f32,
107 layout.scroll_width()
108 );
109 #[cfg(feature = "content_size")]
110 assert_eq!(
111 layout.scroll_height(),
112 0f32,
113 "scroll_height of node {:?}. Expected {}. Actual {}",
114 node0,
115 0f32,
116 layout.scroll_height()
117 );
118 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
119 let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
120 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
121 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
122 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
123 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
124 #[cfg(feature = "content_size")]
125 assert_eq!(
126 layout.scroll_width(),
127 0f32,
128 "scroll_width of node {:?}. Expected {}. Actual {}",
129 node00,
130 0f32,
131 layout.scroll_width()
132 );
133 #[cfg(feature = "content_size")]
134 assert_eq!(
135 layout.scroll_height(),
136 0f32,
137 "scroll_height of node {:?}. Expected {}. Actual {}",
138 node00,
139 0f32,
140 layout.scroll_height()
141 );
142 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
143 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
144 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
145 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
146 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
147 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
148 #[cfg(feature = "content_size")]
149 assert_eq!(
150 layout.scroll_width(),
151 0f32,
152 "scroll_width of node {:?}. Expected {}. Actual {}",
153 node1,
154 0f32,
155 layout.scroll_width()
156 );
157 #[cfg(feature = "content_size")]
158 assert_eq!(
159 layout.scroll_height(),
160 0f32,
161 "scroll_height of node {:?}. Expected {}. Actual {}",
162 node1,
163 0f32,
164 layout.scroll_height()
165 );
166 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
167 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
168 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
169 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
170 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
171 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
172 #[cfg(feature = "content_size")]
173 assert_eq!(
174 layout.scroll_width(),
175 0f32,
176 "scroll_width of node {:?}. Expected {}. Actual {}",
177 node2,
178 0f32,
179 layout.scroll_width()
180 );
181 #[cfg(feature = "content_size")]
182 assert_eq!(
183 layout.scroll_height(),
184 0f32,
185 "scroll_height of node {:?}. Expected {}. Actual {}",
186 node2,
187 0f32,
188 layout.scroll_height()
189 );
190 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
191 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
192 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
193 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3, 50f32, size.height);
194 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
195 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node3, 100f32, location.y);
196 #[cfg(feature = "content_size")]
197 assert_eq!(
198 layout.scroll_width(),
199 0f32,
200 "scroll_width of node {:?}. Expected {}. Actual {}",
201 node3,
202 0f32,
203 layout.scroll_width()
204 );
205 #[cfg(feature = "content_size")]
206 assert_eq!(
207 layout.scroll_height(),
208 0f32,
209 "scroll_height of node {:?}. Expected {}. Actual {}",
210 node3,
211 0f32,
212 layout.scroll_height()
213 );
214 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
215 let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
216 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
217 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node4, 50f32, size.height);
218 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node4, 50f32, location.x);
219 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
220 #[cfg(feature = "content_size")]
221 assert_eq!(
222 layout.scroll_width(),
223 0f32,
224 "scroll_width of node {:?}. Expected {}. Actual {}",
225 node4,
226 0f32,
227 layout.scroll_width()
228 );
229 #[cfg(feature = "content_size")]
230 assert_eq!(
231 layout.scroll_height(),
232 0f32,
233 "scroll_height of node {:?}. Expected {}. Actual {}",
234 node4,
235 0f32,
236 layout.scroll_height()
237 );
238}