tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 735HTML 687Markdown 12TOML 62433 Definitions

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/align_content_stretch_row_with_flex.rs Rust · 201 lines · 11.1 KB History Who touched what raw

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn align_content_stretch_row_with_flex__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
10            ..Default::default()
11        })
12        .unwrap();
13    let node1 = taffy
14        .new_leaf(taffy::style::Style {
15            flex_grow: 1f32,
16            flex_shrink: 1f32,
17            flex_basis: taffy::style::Dimension::from_percent(0f32),
18            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
19            ..Default::default()
20        })
21        .unwrap();
22    let node2 = taffy
23        .new_leaf(taffy::style::Style {
24            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
25            ..Default::default()
26        })
27        .unwrap();
28    let node3 = taffy
29        .new_leaf(taffy::style::Style {
30            flex_grow: 1f32,
31            flex_shrink: 1f32,
32            flex_basis: taffy::style::Dimension::from_percent(0f32),
33            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
34            ..Default::default()
35        })
36        .unwrap();
37    let node4 = taffy
38        .new_leaf(taffy::style::Style {
39            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
40            ..Default::default()
41        })
42        .unwrap();
43    let node = taffy
44        .new_with_children(
45            taffy::style::Style {
46                flex_wrap: taffy::style::FlexWrap::Wrap,
47                align_content: Some(taffy::style::AlignContent::Stretch),
48                size: taffy::geometry::Size {
49                    width: taffy::style::Dimension::from_length(150f32),
50                    height: taffy::style::Dimension::from_length(100f32),
51                },
52                ..Default::default()
53            },
54            &[node0, node1, node2, node3, node4],
55        )
56        .unwrap();
57    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
58    println!("\nComputed tree:");
59    taffy.print_tree(node);
60    println!();
61    let layout = taffy.layout(node).unwrap();
62    let Layout { size, location, .. } = layout;
63    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
64    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
65    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
66    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
67    let layout = taffy.layout(node0).unwrap();
68    let Layout { size, location, .. } = layout;
69    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
70    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
73    let layout = taffy.layout(node1).unwrap();
74    let Layout { size, location, .. } = layout;
75    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1, 0f32, size.width);
76    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
77    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
78    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
79    let layout = taffy.layout(node2).unwrap();
80    let Layout { size, location, .. } = layout;
81    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
82    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
83    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node2, 50f32, location.x);
84    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
85    let layout = taffy.layout(node3).unwrap();
86    let Layout { size, location, .. } = layout;
87    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node3, 0f32, size.width);
88    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node3, 100f32, size.height);
89    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node3, 100f32, location.x);
90    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
91    let layout = taffy.layout(node4).unwrap();
92    let Layout { size, location, .. } = layout;
93    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
94    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node4, 100f32, size.height);
95    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node4, 100f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
97}
98
99#[test]
100#[allow(non_snake_case)]
101fn align_content_stretch_row_with_flex__content_box() {
102    #[allow(unused_imports)]
103    use taffy::{prelude::*, Layout};
104    let mut taffy = crate::new_test_tree();
105    let node0 = taffy
106        .new_leaf(taffy::style::Style {
107            box_sizing: taffy::style::BoxSizing::ContentBox,
108            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
109            ..Default::default()
110        })
111        .unwrap();
112    let node1 = taffy
113        .new_leaf(taffy::style::Style {
114            box_sizing: taffy::style::BoxSizing::ContentBox,
115            flex_grow: 1f32,
116            flex_shrink: 1f32,
117            flex_basis: taffy::style::Dimension::from_percent(0f32),
118            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
119            ..Default::default()
120        })
121        .unwrap();
122    let node2 = taffy
123        .new_leaf(taffy::style::Style {
124            box_sizing: taffy::style::BoxSizing::ContentBox,
125            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
126            ..Default::default()
127        })
128        .unwrap();
129    let node3 = taffy
130        .new_leaf(taffy::style::Style {
131            box_sizing: taffy::style::BoxSizing::ContentBox,
132            flex_grow: 1f32,
133            flex_shrink: 1f32,
134            flex_basis: taffy::style::Dimension::from_percent(0f32),
135            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
136            ..Default::default()
137        })
138        .unwrap();
139    let node4 = taffy
140        .new_leaf(taffy::style::Style {
141            box_sizing: taffy::style::BoxSizing::ContentBox,
142            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
143            ..Default::default()
144        })
145        .unwrap();
146    let node = taffy
147        .new_with_children(
148            taffy::style::Style {
149                box_sizing: taffy::style::BoxSizing::ContentBox,
150                flex_wrap: taffy::style::FlexWrap::Wrap,
151                align_content: Some(taffy::style::AlignContent::Stretch),
152                size: taffy::geometry::Size {
153                    width: taffy::style::Dimension::from_length(150f32),
154                    height: taffy::style::Dimension::from_length(100f32),
155                },
156                ..Default::default()
157            },
158            &[node0, node1, node2, node3, node4],
159        )
160        .unwrap();
161    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
162    println!("\nComputed tree:");
163    taffy.print_tree(node);
164    println!();
165    let layout = taffy.layout(node).unwrap();
166    let Layout { size, location, .. } = layout;
167    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
168    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
169    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
170    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
171    let layout = taffy.layout(node0).unwrap();
172    let Layout { size, location, .. } = layout;
173    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
174    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
175    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
176    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
177    let layout = taffy.layout(node1).unwrap();
178    let Layout { size, location, .. } = layout;
179    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1, 0f32, size.width);
180    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
181    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
182    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
183    let layout = taffy.layout(node2).unwrap();
184    let Layout { size, location, .. } = layout;
185    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
186    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
187    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node2, 50f32, location.x);
188    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
189    let layout = taffy.layout(node3).unwrap();
190    let Layout { size, location, .. } = layout;
191    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node3, 0f32, size.width);
192    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node3, 100f32, size.height);
193    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node3, 100f32, location.x);
194    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
195    let layout = taffy.layout(node4).unwrap();
196    let Layout { size, location, .. } = layout;
197    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
198    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node4, 100f32, size.height);
199    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node4, 100f32, location.x);
200    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
201}