Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn gap_column_gap_row_gap_wrapping() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node0 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size {
9 width: taffy::style::Dimension::Length(20f32),
10 height: taffy::style::Dimension::Length(20f32),
11 },
12 ..Default::default()
13 })
14 .unwrap();
15 let node1 = taffy
16 .new_leaf(taffy::style::Style {
17 size: taffy::geometry::Size {
18 width: taffy::style::Dimension::Length(20f32),
19 height: taffy::style::Dimension::Length(20f32),
20 },
21 ..Default::default()
22 })
23 .unwrap();
24 let node2 = taffy
25 .new_leaf(taffy::style::Style {
26 size: taffy::geometry::Size {
27 width: taffy::style::Dimension::Length(20f32),
28 height: taffy::style::Dimension::Length(20f32),
29 },
30 ..Default::default()
31 })
32 .unwrap();
33 let node3 = taffy
34 .new_leaf(taffy::style::Style {
35 size: taffy::geometry::Size {
36 width: taffy::style::Dimension::Length(20f32),
37 height: taffy::style::Dimension::Length(20f32),
38 },
39 ..Default::default()
40 })
41 .unwrap();
42 let node4 = taffy
43 .new_leaf(taffy::style::Style {
44 size: taffy::geometry::Size {
45 width: taffy::style::Dimension::Length(20f32),
46 height: taffy::style::Dimension::Length(20f32),
47 },
48 ..Default::default()
49 })
50 .unwrap();
51 let node5 = taffy
52 .new_leaf(taffy::style::Style {
53 size: taffy::geometry::Size {
54 width: taffy::style::Dimension::Length(20f32),
55 height: taffy::style::Dimension::Length(20f32),
56 },
57 ..Default::default()
58 })
59 .unwrap();
60 let node6 = taffy
61 .new_leaf(taffy::style::Style {
62 size: taffy::geometry::Size {
63 width: taffy::style::Dimension::Length(20f32),
64 height: taffy::style::Dimension::Length(20f32),
65 },
66 ..Default::default()
67 })
68 .unwrap();
69 let node7 = taffy
70 .new_leaf(taffy::style::Style {
71 size: taffy::geometry::Size {
72 width: taffy::style::Dimension::Length(20f32),
73 height: taffy::style::Dimension::Length(20f32),
74 },
75 ..Default::default()
76 })
77 .unwrap();
78 let node8 = taffy
79 .new_leaf(taffy::style::Style {
80 size: taffy::geometry::Size {
81 width: taffy::style::Dimension::Length(20f32),
82 height: taffy::style::Dimension::Length(20f32),
83 },
84 ..Default::default()
85 })
86 .unwrap();
87 let node = taffy
88 .new_with_children(
89 taffy::style::Style {
90 flex_wrap: taffy::style::FlexWrap::Wrap,
91 gap: taffy::geometry::Size {
92 width: taffy::style::LengthPercentage::Length(10f32),
93 height: taffy::style::LengthPercentage::Length(20f32),
94 },
95 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(80f32), height: auto() },
96 ..Default::default()
97 },
98 &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
99 )
100 .unwrap();
101 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
102 println!("\nComputed tree:");
103 taffy.print_tree(node);
104 println!();
105 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
106 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
107 assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node, 80f32, size.width);
108 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
109 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
110 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
111 #[cfg(feature = "content_size")]
112 assert_eq!(
113 layout.scroll_width(),
114 0f32,
115 "scroll_width of node {:?}. Expected {}. Actual {}",
116 node,
117 0f32,
118 layout.scroll_width()
119 );
120 #[cfg(feature = "content_size")]
121 assert_eq!(
122 layout.scroll_height(),
123 0f32,
124 "scroll_height of node {:?}. Expected {}. Actual {}",
125 node,
126 0f32,
127 layout.scroll_height()
128 );
129 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
130 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
131 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
132 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
133 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
134 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
135 #[cfg(feature = "content_size")]
136 assert_eq!(
137 layout.scroll_width(),
138 0f32,
139 "scroll_width of node {:?}. Expected {}. Actual {}",
140 node0,
141 0f32,
142 layout.scroll_width()
143 );
144 #[cfg(feature = "content_size")]
145 assert_eq!(
146 layout.scroll_height(),
147 0f32,
148 "scroll_height of node {:?}. Expected {}. Actual {}",
149 node0,
150 0f32,
151 layout.scroll_height()
152 );
153 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
154 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
155 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
156 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
157 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
158 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
159 #[cfg(feature = "content_size")]
160 assert_eq!(
161 layout.scroll_width(),
162 0f32,
163 "scroll_width of node {:?}. Expected {}. Actual {}",
164 node1,
165 0f32,
166 layout.scroll_width()
167 );
168 #[cfg(feature = "content_size")]
169 assert_eq!(
170 layout.scroll_height(),
171 0f32,
172 "scroll_height of node {:?}. Expected {}. Actual {}",
173 node1,
174 0f32,
175 layout.scroll_height()
176 );
177 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
178 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
179 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
180 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
181 assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
182 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
183 #[cfg(feature = "content_size")]
184 assert_eq!(
185 layout.scroll_width(),
186 0f32,
187 "scroll_width of node {:?}. Expected {}. Actual {}",
188 node2,
189 0f32,
190 layout.scroll_width()
191 );
192 #[cfg(feature = "content_size")]
193 assert_eq!(
194 layout.scroll_height(),
195 0f32,
196 "scroll_height of node {:?}. Expected {}. Actual {}",
197 node2,
198 0f32,
199 layout.scroll_height()
200 );
201 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
202 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
203 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
204 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
205 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
206 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
207 #[cfg(feature = "content_size")]
208 assert_eq!(
209 layout.scroll_width(),
210 0f32,
211 "scroll_width of node {:?}. Expected {}. Actual {}",
212 node3,
213 0f32,
214 layout.scroll_width()
215 );
216 #[cfg(feature = "content_size")]
217 assert_eq!(
218 layout.scroll_height(),
219 0f32,
220 "scroll_height of node {:?}. Expected {}. Actual {}",
221 node3,
222 0f32,
223 layout.scroll_height()
224 );
225 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
226 let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
227 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
228 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4, 20f32, size.height);
229 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4, 30f32, location.x);
230 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
231 #[cfg(feature = "content_size")]
232 assert_eq!(
233 layout.scroll_width(),
234 0f32,
235 "scroll_width of node {:?}. Expected {}. Actual {}",
236 node4,
237 0f32,
238 layout.scroll_width()
239 );
240 #[cfg(feature = "content_size")]
241 assert_eq!(
242 layout.scroll_height(),
243 0f32,
244 "scroll_height of node {:?}. Expected {}. Actual {}",
245 node4,
246 0f32,
247 layout.scroll_height()
248 );
249 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
250 let layout @ Layout { size, location, .. } = taffy.layout(node5).unwrap();
251 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
252 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node5, 20f32, size.height);
253 assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node5, 60f32, location.x);
254 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
255 #[cfg(feature = "content_size")]
256 assert_eq!(
257 layout.scroll_width(),
258 0f32,
259 "scroll_width of node {:?}. Expected {}. Actual {}",
260 node5,
261 0f32,
262 layout.scroll_width()
263 );
264 #[cfg(feature = "content_size")]
265 assert_eq!(
266 layout.scroll_height(),
267 0f32,
268 "scroll_height of node {:?}. Expected {}. Actual {}",
269 node5,
270 0f32,
271 layout.scroll_height()
272 );
273 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
274 let layout @ Layout { size, location, .. } = taffy.layout(node6).unwrap();
275 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6, 20f32, size.width);
276 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6, 20f32, size.height);
277 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
278 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, location.y);
279 #[cfg(feature = "content_size")]
280 assert_eq!(
281 layout.scroll_width(),
282 0f32,
283 "scroll_width of node {:?}. Expected {}. Actual {}",
284 node6,
285 0f32,
286 layout.scroll_width()
287 );
288 #[cfg(feature = "content_size")]
289 assert_eq!(
290 layout.scroll_height(),
291 0f32,
292 "scroll_height of node {:?}. Expected {}. Actual {}",
293 node6,
294 0f32,
295 layout.scroll_height()
296 );
297 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
298 let layout @ Layout { size, location, .. } = taffy.layout(node7).unwrap();
299 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node7, 20f32, size.width);
300 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node7, 20f32, size.height);
301 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node7, 30f32, location.x);
302 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, location.y);
303 #[cfg(feature = "content_size")]
304 assert_eq!(
305 layout.scroll_width(),
306 0f32,
307 "scroll_width of node {:?}. Expected {}. Actual {}",
308 node7,
309 0f32,
310 layout.scroll_width()
311 );
312 #[cfg(feature = "content_size")]
313 assert_eq!(
314 layout.scroll_height(),
315 0f32,
316 "scroll_height of node {:?}. Expected {}. Actual {}",
317 node7,
318 0f32,
319 layout.scroll_height()
320 );
321 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
322 let layout @ Layout { size, location, .. } = taffy.layout(node8).unwrap();
323 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node8, 20f32, size.width);
324 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node8, 20f32, size.height);
325 assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node8, 60f32, location.x);
326 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node8, 80f32, location.y);
327 #[cfg(feature = "content_size")]
328 assert_eq!(
329 layout.scroll_width(),
330 0f32,
331 "scroll_width of node {:?}. Expected {}. Actual {}",
332 node8,
333 0f32,
334 layout.scroll_width()
335 );
336 #[cfg(feature = "content_size")]
337 assert_eq!(
338 layout.scroll_height(),
339 0f32,
340 "scroll_height of node {:?}. Expected {}. Actual {}",
341 node8,
342 0f32,
343 layout.scroll_height()
344 );
345}