tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/align_content_stretch_column.rs Rust · 234 siq'ikuna · 12.8 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2#[allow(non_snake_case)]
3fn align_content_stretch_column__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node00 = taffy
8        .new_leaf(taffy::style::Style {
9            flex_grow: 1f32,
10            flex_shrink: 1f32,
11            flex_basis: taffy::style::Dimension::from_percent(0f32),
12            ..Default::default()
13        })
14        .unwrap();
15    let node0 = taffy
16        .new_with_children(
17            taffy::style::Style {
18                flex_direction: taffy::style::FlexDirection::Column,
19                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
20                ..Default::default()
21            },
22            &[node00],
23        )
24        .unwrap();
25    let node1 = taffy
26        .new_leaf(taffy::style::Style {
27            flex_grow: 1f32,
28            flex_shrink: 1f32,
29            flex_basis: taffy::style::Dimension::from_percent(0f32),
30            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
31            ..Default::default()
32        })
33        .unwrap();
34    let node2 = taffy
35        .new_leaf(taffy::style::Style {
36            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
37            ..Default::default()
38        })
39        .unwrap();
40    let node3 = taffy
41        .new_leaf(taffy::style::Style {
42            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
43            ..Default::default()
44        })
45        .unwrap();
46    let node4 = taffy
47        .new_leaf(taffy::style::Style {
48            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
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::Stretch),
58                size: taffy::geometry::Size {
59                    width: taffy::style::Dimension::from_length(100f32),
60                    height: taffy::style::Dimension::from_length(150f32),
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    let layout = taffy.layout(node).unwrap();
72    let Layout { size, location, .. } = layout;
73    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
74    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node, 150f32, 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    let layout = taffy.layout(node0).unwrap();
78    let Layout { size, location, .. } = layout;
79    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
80    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
81    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
82    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
83    let layout = taffy.layout(node00).unwrap();
84    let Layout { size, location, .. } = layout;
85    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
86    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
87    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
88    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
89    let layout = taffy.layout(node1).unwrap();
90    let Layout { size, location, .. } = layout;
91    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
92    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
93    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
94    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
95    let layout = taffy.layout(node2).unwrap();
96    let Layout { size, location, .. } = layout;
97    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
98    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
99    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
100    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
101    let layout = taffy.layout(node3).unwrap();
102    let Layout { size, location, .. } = layout;
103    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
104    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3, 50f32, size.height);
105    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
106    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node3, 100f32, location.y);
107    let layout = taffy.layout(node4).unwrap();
108    let Layout { size, location, .. } = layout;
109    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
110    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node4, 50f32, size.height);
111    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node4, 50f32, location.x);
112    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
113}
114
115#[test]
116#[allow(non_snake_case)]
117fn align_content_stretch_column__content_box() {
118    #[allow(unused_imports)]
119    use taffy::{prelude::*, Layout};
120    let mut taffy = crate::new_test_tree();
121    let node00 = taffy
122        .new_leaf(taffy::style::Style {
123            box_sizing: taffy::style::BoxSizing::ContentBox,
124            flex_grow: 1f32,
125            flex_shrink: 1f32,
126            flex_basis: taffy::style::Dimension::from_percent(0f32),
127            ..Default::default()
128        })
129        .unwrap();
130    let node0 = taffy
131        .new_with_children(
132            taffy::style::Style {
133                box_sizing: taffy::style::BoxSizing::ContentBox,
134                flex_direction: taffy::style::FlexDirection::Column,
135                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
136                ..Default::default()
137            },
138            &[node00],
139        )
140        .unwrap();
141    let node1 = taffy
142        .new_leaf(taffy::style::Style {
143            box_sizing: taffy::style::BoxSizing::ContentBox,
144            flex_grow: 1f32,
145            flex_shrink: 1f32,
146            flex_basis: taffy::style::Dimension::from_percent(0f32),
147            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
148            ..Default::default()
149        })
150        .unwrap();
151    let node2 = taffy
152        .new_leaf(taffy::style::Style {
153            box_sizing: taffy::style::BoxSizing::ContentBox,
154            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
155            ..Default::default()
156        })
157        .unwrap();
158    let node3 = taffy
159        .new_leaf(taffy::style::Style {
160            box_sizing: taffy::style::BoxSizing::ContentBox,
161            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
162            ..Default::default()
163        })
164        .unwrap();
165    let node4 = taffy
166        .new_leaf(taffy::style::Style {
167            box_sizing: taffy::style::BoxSizing::ContentBox,
168            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
169            ..Default::default()
170        })
171        .unwrap();
172    let node = taffy
173        .new_with_children(
174            taffy::style::Style {
175                box_sizing: taffy::style::BoxSizing::ContentBox,
176                flex_direction: taffy::style::FlexDirection::Column,
177                flex_wrap: taffy::style::FlexWrap::Wrap,
178                align_content: Some(taffy::style::AlignContent::Stretch),
179                size: taffy::geometry::Size {
180                    width: taffy::style::Dimension::from_length(100f32),
181                    height: taffy::style::Dimension::from_length(150f32),
182                },
183                ..Default::default()
184            },
185            &[node0, node1, node2, node3, node4],
186        )
187        .unwrap();
188    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
189    println!("\nComputed tree:");
190    taffy.print_tree(node);
191    println!();
192    let layout = taffy.layout(node).unwrap();
193    let Layout { size, location, .. } = layout;
194    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
195    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node, 150f32, size.height);
196    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
197    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
198    let layout = taffy.layout(node0).unwrap();
199    let Layout { size, location, .. } = layout;
200    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
201    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
202    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
203    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
204    let layout = taffy.layout(node00).unwrap();
205    let Layout { size, location, .. } = layout;
206    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
207    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
208    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
209    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
210    let layout = taffy.layout(node1).unwrap();
211    let Layout { size, location, .. } = layout;
212    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
213    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
214    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
215    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
216    let layout = taffy.layout(node2).unwrap();
217    let Layout { size, location, .. } = layout;
218    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
219    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
220    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
221    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
222    let layout = taffy.layout(node3).unwrap();
223    let Layout { size, location, .. } = layout;
224    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
225    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3, 50f32, size.height);
226    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
227    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node3, 100f32, location.y);
228    let layout = taffy.layout(node4).unwrap();
229    let Layout { size, location, .. } = layout;
230    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
231    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node4, 50f32, size.height);
232    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node4, 50f32, location.x);
233    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
234}