Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn grid_align_items_baseline_complex() {
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 node10 = taffy
16 .new_leaf(taffy::style::Style {
17 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
18 ..Default::default()
19 })
20 .unwrap();
21 let node1 = taffy
22 .new_with_children(
23 taffy::style::Style {
24 size: taffy::geometry::Size {
25 width: taffy::style::Dimension::Length(20f32),
26 height: taffy::style::Dimension::Length(20f32),
27 },
28 ..Default::default()
29 },
30 &[node10],
31 )
32 .unwrap();
33 let node20 = taffy
34 .new_leaf(taffy::style::Style {
35 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
36 ..Default::default()
37 })
38 .unwrap();
39 let node2 = taffy
40 .new_with_children(
41 taffy::style::Style {
42 size: taffy::geometry::Size {
43 width: taffy::style::Dimension::Length(20f32),
44 height: taffy::style::Dimension::Length(20f32),
45 },
46 ..Default::default()
47 },
48 &[node20],
49 )
50 .unwrap();
51 let node3 = 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 node4 = 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 node5 = 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 node60 = taffy
79 .new_leaf(taffy::style::Style {
80 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
81 ..Default::default()
82 })
83 .unwrap();
84 let node6 = taffy
85 .new_with_children(
86 taffy::style::Style {
87 size: taffy::geometry::Size {
88 width: taffy::style::Dimension::Length(20f32),
89 height: taffy::style::Dimension::Length(20f32),
90 },
91 ..Default::default()
92 },
93 &[node60],
94 )
95 .unwrap();
96 let node70 = taffy
97 .new_leaf(taffy::style::Style {
98 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(5f32) },
99 ..Default::default()
100 })
101 .unwrap();
102 let node7 = taffy
103 .new_with_children(
104 taffy::style::Style {
105 size: taffy::geometry::Size {
106 width: taffy::style::Dimension::Length(20f32),
107 height: taffy::style::Dimension::Length(20f32),
108 },
109 ..Default::default()
110 },
111 &[node70],
112 )
113 .unwrap();
114 let node8 = taffy
115 .new_leaf(taffy::style::Style {
116 size: taffy::geometry::Size {
117 width: taffy::style::Dimension::Length(20f32),
118 height: taffy::style::Dimension::Length(20f32),
119 },
120 ..Default::default()
121 })
122 .unwrap();
123 let node = taffy
124 .new_with_children(
125 taffy::style::Style {
126 display: taffy::style::Display::Grid,
127 align_items: Some(taffy::style::AlignItems::Baseline),
128 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
129 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
130 size: taffy::geometry::Size {
131 width: taffy::style::Dimension::Length(120f32),
132 height: taffy::style::Dimension::Length(120f32),
133 },
134 ..Default::default()
135 },
136 &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
137 )
138 .unwrap();
139 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
140 println!("\nComputed tree:");
141 taffy.print_tree(node);
142 println!();
143 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
144 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
145 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
146 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
147 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
148 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
149 #[cfg(feature = "content_size")]
150 assert_eq!(
151 layout.scroll_width(),
152 0f32,
153 "scroll_width of node {:?}. Expected {}. Actual {}",
154 node,
155 0f32,
156 layout.scroll_width()
157 );
158 #[cfg(feature = "content_size")]
159 assert_eq!(
160 layout.scroll_height(),
161 0f32,
162 "scroll_height of node {:?}. Expected {}. Actual {}",
163 node,
164 0f32,
165 layout.scroll_height()
166 );
167 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
168 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
169 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
170 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
171 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
172 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
173 #[cfg(feature = "content_size")]
174 assert_eq!(
175 layout.scroll_width(),
176 0f32,
177 "scroll_width of node {:?}. Expected {}. Actual {}",
178 node0,
179 0f32,
180 layout.scroll_width()
181 );
182 #[cfg(feature = "content_size")]
183 assert_eq!(
184 layout.scroll_height(),
185 0f32,
186 "scroll_height of node {:?}. Expected {}. Actual {}",
187 node0,
188 0f32,
189 layout.scroll_height()
190 );
191 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
192 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
193 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
194 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
195 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
196 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
197 #[cfg(feature = "content_size")]
198 assert_eq!(
199 layout.scroll_width(),
200 0f32,
201 "scroll_width of node {:?}. Expected {}. Actual {}",
202 node1,
203 0f32,
204 layout.scroll_width()
205 );
206 #[cfg(feature = "content_size")]
207 assert_eq!(
208 layout.scroll_height(),
209 0f32,
210 "scroll_height of node {:?}. Expected {}. Actual {}",
211 node1,
212 0f32,
213 layout.scroll_height()
214 );
215 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
216 let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
217 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node10, 0f32, size.width);
218 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
219 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
220 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
221 #[cfg(feature = "content_size")]
222 assert_eq!(
223 layout.scroll_width(),
224 0f32,
225 "scroll_width of node {:?}. Expected {}. Actual {}",
226 node10,
227 0f32,
228 layout.scroll_width()
229 );
230 #[cfg(feature = "content_size")]
231 assert_eq!(
232 layout.scroll_height(),
233 0f32,
234 "scroll_height of node {:?}. Expected {}. Actual {}",
235 node10,
236 0f32,
237 layout.scroll_height()
238 );
239 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
240 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
241 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
242 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
243 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node2, 80f32, location.x);
244 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node2, 10f32, location.y);
245 #[cfg(feature = "content_size")]
246 assert_eq!(
247 layout.scroll_width(),
248 0f32,
249 "scroll_width of node {:?}. Expected {}. Actual {}",
250 node2,
251 0f32,
252 layout.scroll_width()
253 );
254 #[cfg(feature = "content_size")]
255 assert_eq!(
256 layout.scroll_height(),
257 0f32,
258 "scroll_height of node {:?}. Expected {}. Actual {}",
259 node2,
260 0f32,
261 layout.scroll_height()
262 );
263 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
264 let layout @ Layout { size, location, .. } = taffy.layout(node20).unwrap();
265 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node20, 0f32, size.width);
266 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20, 10f32, size.height);
267 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node20, 0f32, location.x);
268 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20, 0f32, location.y);
269 #[cfg(feature = "content_size")]
270 assert_eq!(
271 layout.scroll_width(),
272 0f32,
273 "scroll_width of node {:?}. Expected {}. Actual {}",
274 node20,
275 0f32,
276 layout.scroll_width()
277 );
278 #[cfg(feature = "content_size")]
279 assert_eq!(
280 layout.scroll_height(),
281 0f32,
282 "scroll_height of node {:?}. Expected {}. Actual {}",
283 node20,
284 0f32,
285 layout.scroll_height()
286 );
287 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
288 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
289 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
290 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
291 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
292 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
293 #[cfg(feature = "content_size")]
294 assert_eq!(
295 layout.scroll_width(),
296 0f32,
297 "scroll_width of node {:?}. Expected {}. Actual {}",
298 node3,
299 0f32,
300 layout.scroll_width()
301 );
302 #[cfg(feature = "content_size")]
303 assert_eq!(
304 layout.scroll_height(),
305 0f32,
306 "scroll_height of node {:?}. Expected {}. Actual {}",
307 node3,
308 0f32,
309 layout.scroll_height()
310 );
311 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
312 let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
313 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
314 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4, 20f32, size.height);
315 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node4, 40f32, location.x);
316 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
317 #[cfg(feature = "content_size")]
318 assert_eq!(
319 layout.scroll_width(),
320 0f32,
321 "scroll_width of node {:?}. Expected {}. Actual {}",
322 node4,
323 0f32,
324 layout.scroll_width()
325 );
326 #[cfg(feature = "content_size")]
327 assert_eq!(
328 layout.scroll_height(),
329 0f32,
330 "scroll_height of node {:?}. Expected {}. Actual {}",
331 node4,
332 0f32,
333 layout.scroll_height()
334 );
335 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
336 let layout @ Layout { size, location, .. } = taffy.layout(node5).unwrap();
337 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
338 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node5, 20f32, size.height);
339 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node5, 80f32, location.x);
340 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
341 #[cfg(feature = "content_size")]
342 assert_eq!(
343 layout.scroll_width(),
344 0f32,
345 "scroll_width of node {:?}. Expected {}. Actual {}",
346 node5,
347 0f32,
348 layout.scroll_width()
349 );
350 #[cfg(feature = "content_size")]
351 assert_eq!(
352 layout.scroll_height(),
353 0f32,
354 "scroll_height of node {:?}. Expected {}. Actual {}",
355 node5,
356 0f32,
357 layout.scroll_height()
358 );
359 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
360 let layout @ Layout { size, location, .. } = taffy.layout(node6).unwrap();
361 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6, 20f32, size.width);
362 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6, 20f32, size.height);
363 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
364 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node6, 90f32, location.y);
365 #[cfg(feature = "content_size")]
366 assert_eq!(
367 layout.scroll_width(),
368 0f32,
369 "scroll_width of node {:?}. Expected {}. Actual {}",
370 node6,
371 0f32,
372 layout.scroll_width()
373 );
374 #[cfg(feature = "content_size")]
375 assert_eq!(
376 layout.scroll_height(),
377 0f32,
378 "scroll_height of node {:?}. Expected {}. Actual {}",
379 node6,
380 0f32,
381 layout.scroll_height()
382 );
383 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
384 let layout @ Layout { size, location, .. } = taffy.layout(node60).unwrap();
385 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node60, 0f32, size.width);
386 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node60, 10f32, size.height);
387 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node60, 0f32, location.x);
388 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node60, 0f32, location.y);
389 #[cfg(feature = "content_size")]
390 assert_eq!(
391 layout.scroll_width(),
392 0f32,
393 "scroll_width of node {:?}. Expected {}. Actual {}",
394 node60,
395 0f32,
396 layout.scroll_width()
397 );
398 #[cfg(feature = "content_size")]
399 assert_eq!(
400 layout.scroll_height(),
401 0f32,
402 "scroll_height of node {:?}. Expected {}. Actual {}",
403 node60,
404 0f32,
405 layout.scroll_height()
406 );
407 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
408 let layout @ Layout { size, location, .. } = taffy.layout(node7).unwrap();
409 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node7, 20f32, size.width);
410 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node7, 20f32, size.height);
411 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7, 40f32, location.x);
412 assert_eq!(location.y, 95f32, "y of node {:?}. Expected {}. Actual {}", node7, 95f32, location.y);
413 #[cfg(feature = "content_size")]
414 assert_eq!(
415 layout.scroll_width(),
416 0f32,
417 "scroll_width of node {:?}. Expected {}. Actual {}",
418 node7,
419 0f32,
420 layout.scroll_width()
421 );
422 #[cfg(feature = "content_size")]
423 assert_eq!(
424 layout.scroll_height(),
425 0f32,
426 "scroll_height of node {:?}. Expected {}. Actual {}",
427 node7,
428 0f32,
429 layout.scroll_height()
430 );
431 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
432 let layout @ Layout { size, location, .. } = taffy.layout(node70).unwrap();
433 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node70, 0f32, size.width);
434 assert_eq!(size.height, 5f32, "height of node {:?}. Expected {}. Actual {}", node70, 5f32, size.height);
435 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node70, 0f32, location.x);
436 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node70, 0f32, location.y);
437 #[cfg(feature = "content_size")]
438 assert_eq!(
439 layout.scroll_width(),
440 0f32,
441 "scroll_width of node {:?}. Expected {}. Actual {}",
442 node70,
443 0f32,
444 layout.scroll_width()
445 );
446 #[cfg(feature = "content_size")]
447 assert_eq!(
448 layout.scroll_height(),
449 0f32,
450 "scroll_height of node {:?}. Expected {}. Actual {}",
451 node70,
452 0f32,
453 layout.scroll_height()
454 );
455 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
456 let layout @ Layout { size, location, .. } = taffy.layout(node8).unwrap();
457 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node8, 20f32, size.width);
458 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node8, 20f32, size.height);
459 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node8, 80f32, location.x);
460 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node8, 80f32, location.y);
461 #[cfg(feature = "content_size")]
462 assert_eq!(
463 layout.scroll_width(),
464 0f32,
465 "scroll_width of node {:?}. Expected {}. Actual {}",
466 node8,
467 0f32,
468 layout.scroll_width()
469 );
470 #[cfg(feature = "content_size")]
471 assert_eq!(
472 layout.scroll_height(),
473 0f32,
474 "scroll_height of node {:?}. Expected {}. Actual {}",
475 node8,
476 0f32,
477 layout.scroll_height()
478 );
479}