tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Definitions

⎇ b746ac4f346dde8a2b6f85d3a428c02a2342f099 tests/generated/flex/align_content_flex_end.rs Rust · 437 lines · 17.4 KB History Who touched what raw

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

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