tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

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