tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/bevy_issue_8082.rs Rust · 277 lines · 13.7 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 bevy_issue_8082__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            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_length(50f32),
11                height: taffy::style::Dimension::from_length(50f32),
12            },
13            margin: taffy::geometry::Rect {
14                left: length(10f32),
15                right: length(10f32),
16                top: length(10f32),
17                bottom: length(10f32),
18            },
19            ..Default::default()
20        })
21        .unwrap();
22    let node01 = taffy
23        .new_leaf(taffy::style::Style {
24            size: taffy::geometry::Size {
25                width: taffy::style::Dimension::from_length(50f32),
26                height: taffy::style::Dimension::from_length(50f32),
27            },
28            margin: taffy::geometry::Rect {
29                left: length(10f32),
30                right: length(10f32),
31                top: length(10f32),
32                bottom: length(10f32),
33            },
34            ..Default::default()
35        })
36        .unwrap();
37    let node02 = taffy
38        .new_leaf(taffy::style::Style {
39            size: taffy::geometry::Size {
40                width: taffy::style::Dimension::from_length(50f32),
41                height: taffy::style::Dimension::from_length(50f32),
42            },
43            margin: taffy::geometry::Rect {
44                left: length(10f32),
45                right: length(10f32),
46                top: length(10f32),
47                bottom: length(10f32),
48            },
49            ..Default::default()
50        })
51        .unwrap();
52    let node03 = taffy
53        .new_leaf(taffy::style::Style {
54            size: taffy::geometry::Size {
55                width: taffy::style::Dimension::from_length(50f32),
56                height: taffy::style::Dimension::from_length(50f32),
57            },
58            margin: taffy::geometry::Rect {
59                left: length(10f32),
60                right: length(10f32),
61                top: length(10f32),
62                bottom: length(10f32),
63            },
64            ..Default::default()
65        })
66        .unwrap();
67    let node0 = taffy
68        .new_with_children(
69            taffy::style::Style {
70                flex_wrap: taffy::style::FlexWrap::Wrap,
71                align_items: Some(taffy::style::AlignItems::FlexStart),
72                align_content: Some(taffy::style::AlignContent::Center),
73                justify_content: Some(taffy::style::JustifyContent::Center),
74                ..Default::default()
75            },
76            &[node00, node01, node02, node03],
77        )
78        .unwrap();
79    let node = taffy
80        .new_with_children(
81            taffy::style::Style {
82                flex_direction: taffy::style::FlexDirection::Column,
83                align_items: Some(taffy::style::AlignItems::Stretch),
84                align_content: Some(taffy::style::AlignContent::Center),
85                justify_content: Some(taffy::style::JustifyContent::FlexStart),
86                size: taffy::geometry::Size {
87                    width: taffy::style::Dimension::from_length(200f32),
88                    height: taffy::style::Dimension::from_length(400f32),
89                },
90                ..Default::default()
91            },
92            &[node0],
93        )
94        .unwrap();
95    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
96    println!("\nComputed tree:");
97    taffy.print_tree(node);
98    println!();
99    let layout = taffy.layout(node).unwrap();
100    let Layout { size, location, .. } = layout;
101    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
102    assert_eq!(size.height, 400f32, "height of node {:?}. Expected {}. Actual {}", node, 400f32, size.height);
103    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
104    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
105    let layout = taffy.layout(node0).unwrap();
106    let Layout { size, location, .. } = layout;
107    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
108    assert_eq!(size.height, 140f32, "height of node {:?}. Expected {}. Actual {}", node0, 140f32, size.height);
109    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
110    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
111    let layout = taffy.layout(node00).unwrap();
112    let Layout { size, location, .. } = layout;
113    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
114    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
115    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node00, 40f32, location.x);
116    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node00, 10f32, location.y);
117    let layout = taffy.layout(node01).unwrap();
118    let Layout { size, location, .. } = layout;
119    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node01, 50f32, size.width);
120    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node01, 50f32, size.height);
121    assert_eq!(location.x, 110f32, "x of node {:?}. Expected {}. Actual {}", node01, 110f32, location.x);
122    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node01, 10f32, location.y);
123    let layout = taffy.layout(node02).unwrap();
124    let Layout { size, location, .. } = layout;
125    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node02, 50f32, size.width);
126    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node02, 50f32, size.height);
127    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node02, 40f32, location.x);
128    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node02, 80f32, location.y);
129    let layout = taffy.layout(node03).unwrap();
130    let Layout { size, location, .. } = layout;
131    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node03, 50f32, size.width);
132    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node03, 50f32, size.height);
133    assert_eq!(location.x, 110f32, "x of node {:?}. Expected {}. Actual {}", node03, 110f32, location.x);
134    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node03, 80f32, location.y);
135}
136
137#[test]
138#[allow(non_snake_case)]
139fn bevy_issue_8082__content_box() {
140    #[allow(unused_imports)]
141    use taffy::{prelude::*, Layout};
142    let mut taffy = crate::new_test_tree();
143    let node00 = taffy
144        .new_leaf(taffy::style::Style {
145            box_sizing: taffy::style::BoxSizing::ContentBox,
146            size: taffy::geometry::Size {
147                width: taffy::style::Dimension::from_length(50f32),
148                height: taffy::style::Dimension::from_length(50f32),
149            },
150            margin: taffy::geometry::Rect {
151                left: length(10f32),
152                right: length(10f32),
153                top: length(10f32),
154                bottom: length(10f32),
155            },
156            ..Default::default()
157        })
158        .unwrap();
159    let node01 = taffy
160        .new_leaf(taffy::style::Style {
161            box_sizing: taffy::style::BoxSizing::ContentBox,
162            size: taffy::geometry::Size {
163                width: taffy::style::Dimension::from_length(50f32),
164                height: taffy::style::Dimension::from_length(50f32),
165            },
166            margin: taffy::geometry::Rect {
167                left: length(10f32),
168                right: length(10f32),
169                top: length(10f32),
170                bottom: length(10f32),
171            },
172            ..Default::default()
173        })
174        .unwrap();
175    let node02 = taffy
176        .new_leaf(taffy::style::Style {
177            box_sizing: taffy::style::BoxSizing::ContentBox,
178            size: taffy::geometry::Size {
179                width: taffy::style::Dimension::from_length(50f32),
180                height: taffy::style::Dimension::from_length(50f32),
181            },
182            margin: taffy::geometry::Rect {
183                left: length(10f32),
184                right: length(10f32),
185                top: length(10f32),
186                bottom: length(10f32),
187            },
188            ..Default::default()
189        })
190        .unwrap();
191    let node03 = taffy
192        .new_leaf(taffy::style::Style {
193            box_sizing: taffy::style::BoxSizing::ContentBox,
194            size: taffy::geometry::Size {
195                width: taffy::style::Dimension::from_length(50f32),
196                height: taffy::style::Dimension::from_length(50f32),
197            },
198            margin: taffy::geometry::Rect {
199                left: length(10f32),
200                right: length(10f32),
201                top: length(10f32),
202                bottom: length(10f32),
203            },
204            ..Default::default()
205        })
206        .unwrap();
207    let node0 = taffy
208        .new_with_children(
209            taffy::style::Style {
210                box_sizing: taffy::style::BoxSizing::ContentBox,
211                flex_wrap: taffy::style::FlexWrap::Wrap,
212                align_items: Some(taffy::style::AlignItems::FlexStart),
213                align_content: Some(taffy::style::AlignContent::Center),
214                justify_content: Some(taffy::style::JustifyContent::Center),
215                ..Default::default()
216            },
217            &[node00, node01, node02, node03],
218        )
219        .unwrap();
220    let node = taffy
221        .new_with_children(
222            taffy::style::Style {
223                box_sizing: taffy::style::BoxSizing::ContentBox,
224                flex_direction: taffy::style::FlexDirection::Column,
225                align_items: Some(taffy::style::AlignItems::Stretch),
226                align_content: Some(taffy::style::AlignContent::Center),
227                justify_content: Some(taffy::style::JustifyContent::FlexStart),
228                size: taffy::geometry::Size {
229                    width: taffy::style::Dimension::from_length(200f32),
230                    height: taffy::style::Dimension::from_length(400f32),
231                },
232                ..Default::default()
233            },
234            &[node0],
235        )
236        .unwrap();
237    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
238    println!("\nComputed tree:");
239    taffy.print_tree(node);
240    println!();
241    let layout = taffy.layout(node).unwrap();
242    let Layout { size, location, .. } = layout;
243    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
244    assert_eq!(size.height, 400f32, "height of node {:?}. Expected {}. Actual {}", node, 400f32, size.height);
245    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
246    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
247    let layout = taffy.layout(node0).unwrap();
248    let Layout { size, location, .. } = layout;
249    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
250    assert_eq!(size.height, 140f32, "height of node {:?}. Expected {}. Actual {}", node0, 140f32, size.height);
251    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
252    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
253    let layout = taffy.layout(node00).unwrap();
254    let Layout { size, location, .. } = layout;
255    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
256    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
257    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node00, 40f32, location.x);
258    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node00, 10f32, location.y);
259    let layout = taffy.layout(node01).unwrap();
260    let Layout { size, location, .. } = layout;
261    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node01, 50f32, size.width);
262    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node01, 50f32, size.height);
263    assert_eq!(location.x, 110f32, "x of node {:?}. Expected {}. Actual {}", node01, 110f32, location.x);
264    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node01, 10f32, location.y);
265    let layout = taffy.layout(node02).unwrap();
266    let Layout { size, location, .. } = layout;
267    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node02, 50f32, size.width);
268    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node02, 50f32, size.height);
269    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node02, 40f32, location.x);
270    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node02, 80f32, location.y);
271    let layout = taffy.layout(node03).unwrap();
272    let Layout { size, location, .. } = layout;
273    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node03, 50f32, size.width);
274    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node03, 50f32, size.height);
275    assert_eq!(location.x, 110f32, "x of node {:?}. Expected {}. Actual {}", node03, 110f32, location.x);
276    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node03, 80f32, location.y);
277}