tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Definitions

⎇ 0.4.x tests/generated/grid/grid_auto_columns_fixed_width.rs Rust · 452 lines · 19.6 KB History Who touched what raw

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

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