tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1090HTML 1022Markdown 12TOML 84418 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/gap_column_gap_row_gap_wrapping.rs Rust · 337 siq'ikuna · 18.0 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 gap_column_gap_row_gap_wrapping__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 {
10                width: taffy::style::Dimension::from_length(20f32),
11                height: taffy::style::Dimension::from_length(20f32),
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::from_length(20f32),
20                height: taffy::style::Dimension::from_length(20f32),
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::from_length(20f32),
29                height: taffy::style::Dimension::from_length(20f32),
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::from_length(20f32),
38                height: taffy::style::Dimension::from_length(20f32),
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::from_length(20f32),
47                height: taffy::style::Dimension::from_length(20f32),
48            },
49            ..Default::default()
50        })
51        .unwrap();
52    let node5 = taffy
53        .new_leaf(taffy::style::Style {
54            size: taffy::geometry::Size {
55                width: taffy::style::Dimension::from_length(20f32),
56                height: taffy::style::Dimension::from_length(20f32),
57            },
58            ..Default::default()
59        })
60        .unwrap();
61    let node6 = taffy
62        .new_leaf(taffy::style::Style {
63            size: taffy::geometry::Size {
64                width: taffy::style::Dimension::from_length(20f32),
65                height: taffy::style::Dimension::from_length(20f32),
66            },
67            ..Default::default()
68        })
69        .unwrap();
70    let node7 = taffy
71        .new_leaf(taffy::style::Style {
72            size: taffy::geometry::Size {
73                width: taffy::style::Dimension::from_length(20f32),
74                height: taffy::style::Dimension::from_length(20f32),
75            },
76            ..Default::default()
77        })
78        .unwrap();
79    let node8 = taffy
80        .new_leaf(taffy::style::Style {
81            size: taffy::geometry::Size {
82                width: taffy::style::Dimension::from_length(20f32),
83                height: taffy::style::Dimension::from_length(20f32),
84            },
85            ..Default::default()
86        })
87        .unwrap();
88    let node = taffy
89        .new_with_children(
90            taffy::style::Style {
91                flex_wrap: taffy::style::FlexWrap::Wrap,
92                gap: taffy::geometry::Size { width: length(10f32), height: length(20f32) },
93                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(80f32), height: auto() },
94                ..Default::default()
95            },
96            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
97        )
98        .unwrap();
99    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
100    println!("\nComputed tree:");
101    taffy.print_tree(node);
102    println!();
103    let layout = taffy.layout(node).unwrap();
104    let Layout { size, location, .. } = layout;
105    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node, 80f32, size.width);
106    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
107    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
108    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
109    let layout = taffy.layout(node0).unwrap();
110    let Layout { size, location, .. } = layout;
111    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
112    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
113    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
114    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
115    let layout = taffy.layout(node1).unwrap();
116    let Layout { size, location, .. } = layout;
117    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
118    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
119    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
120    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
121    let layout = taffy.layout(node2).unwrap();
122    let Layout { size, location, .. } = layout;
123    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
124    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
125    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
126    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
127    let layout = taffy.layout(node3).unwrap();
128    let Layout { size, location, .. } = layout;
129    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
130    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
131    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
132    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
133    let layout = taffy.layout(node4).unwrap();
134    let Layout { size, location, .. } = layout;
135    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
136    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4, 20f32, size.height);
137    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4, 30f32, location.x);
138    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
139    let layout = taffy.layout(node5).unwrap();
140    let Layout { size, location, .. } = layout;
141    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
142    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node5, 20f32, size.height);
143    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node5, 60f32, location.x);
144    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
145    let layout = taffy.layout(node6).unwrap();
146    let Layout { size, location, .. } = layout;
147    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6, 20f32, size.width);
148    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6, 20f32, size.height);
149    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
150    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, location.y);
151    let layout = taffy.layout(node7).unwrap();
152    let Layout { size, location, .. } = layout;
153    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node7, 20f32, size.width);
154    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node7, 20f32, size.height);
155    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node7, 30f32, location.x);
156    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, location.y);
157    let layout = taffy.layout(node8).unwrap();
158    let Layout { size, location, .. } = layout;
159    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node8, 20f32, size.width);
160    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node8, 20f32, size.height);
161    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node8, 60f32, location.x);
162    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node8, 80f32, location.y);
163}
164
165#[test]
166#[allow(non_snake_case)]
167fn gap_column_gap_row_gap_wrapping__content_box() {
168    #[allow(unused_imports)]
169    use taffy::{prelude::*, Layout};
170    let mut taffy = crate::new_test_tree();
171    let node0 = taffy
172        .new_leaf(taffy::style::Style {
173            box_sizing: taffy::style::BoxSizing::ContentBox,
174            size: taffy::geometry::Size {
175                width: taffy::style::Dimension::from_length(20f32),
176                height: taffy::style::Dimension::from_length(20f32),
177            },
178            ..Default::default()
179        })
180        .unwrap();
181    let node1 = 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_length(20f32),
186                height: taffy::style::Dimension::from_length(20f32),
187            },
188            ..Default::default()
189        })
190        .unwrap();
191    let node2 = 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(20f32),
196                height: taffy::style::Dimension::from_length(20f32),
197            },
198            ..Default::default()
199        })
200        .unwrap();
201    let node3 = taffy
202        .new_leaf(taffy::style::Style {
203            box_sizing: taffy::style::BoxSizing::ContentBox,
204            size: taffy::geometry::Size {
205                width: taffy::style::Dimension::from_length(20f32),
206                height: taffy::style::Dimension::from_length(20f32),
207            },
208            ..Default::default()
209        })
210        .unwrap();
211    let node4 = taffy
212        .new_leaf(taffy::style::Style {
213            box_sizing: taffy::style::BoxSizing::ContentBox,
214            size: taffy::geometry::Size {
215                width: taffy::style::Dimension::from_length(20f32),
216                height: taffy::style::Dimension::from_length(20f32),
217            },
218            ..Default::default()
219        })
220        .unwrap();
221    let node5 = taffy
222        .new_leaf(taffy::style::Style {
223            box_sizing: taffy::style::BoxSizing::ContentBox,
224            size: taffy::geometry::Size {
225                width: taffy::style::Dimension::from_length(20f32),
226                height: taffy::style::Dimension::from_length(20f32),
227            },
228            ..Default::default()
229        })
230        .unwrap();
231    let node6 = taffy
232        .new_leaf(taffy::style::Style {
233            box_sizing: taffy::style::BoxSizing::ContentBox,
234            size: taffy::geometry::Size {
235                width: taffy::style::Dimension::from_length(20f32),
236                height: taffy::style::Dimension::from_length(20f32),
237            },
238            ..Default::default()
239        })
240        .unwrap();
241    let node7 = taffy
242        .new_leaf(taffy::style::Style {
243            box_sizing: taffy::style::BoxSizing::ContentBox,
244            size: taffy::geometry::Size {
245                width: taffy::style::Dimension::from_length(20f32),
246                height: taffy::style::Dimension::from_length(20f32),
247            },
248            ..Default::default()
249        })
250        .unwrap();
251    let node8 = taffy
252        .new_leaf(taffy::style::Style {
253            box_sizing: taffy::style::BoxSizing::ContentBox,
254            size: taffy::geometry::Size {
255                width: taffy::style::Dimension::from_length(20f32),
256                height: taffy::style::Dimension::from_length(20f32),
257            },
258            ..Default::default()
259        })
260        .unwrap();
261    let node = taffy
262        .new_with_children(
263            taffy::style::Style {
264                box_sizing: taffy::style::BoxSizing::ContentBox,
265                flex_wrap: taffy::style::FlexWrap::Wrap,
266                gap: taffy::geometry::Size { width: length(10f32), height: length(20f32) },
267                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(80f32), height: auto() },
268                ..Default::default()
269            },
270            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
271        )
272        .unwrap();
273    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
274    println!("\nComputed tree:");
275    taffy.print_tree(node);
276    println!();
277    let layout = taffy.layout(node).unwrap();
278    let Layout { size, location, .. } = layout;
279    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node, 80f32, size.width);
280    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
281    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
282    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
283    let layout = taffy.layout(node0).unwrap();
284    let Layout { size, location, .. } = layout;
285    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
286    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
287    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
288    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
289    let layout = taffy.layout(node1).unwrap();
290    let Layout { size, location, .. } = layout;
291    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
292    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
293    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
294    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
295    let layout = taffy.layout(node2).unwrap();
296    let Layout { size, location, .. } = layout;
297    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
298    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
299    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
300    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
301    let layout = taffy.layout(node3).unwrap();
302    let Layout { size, location, .. } = layout;
303    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
304    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
305    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
306    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
307    let layout = taffy.layout(node4).unwrap();
308    let Layout { size, location, .. } = layout;
309    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
310    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4, 20f32, size.height);
311    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4, 30f32, location.x);
312    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
313    let layout = taffy.layout(node5).unwrap();
314    let Layout { size, location, .. } = layout;
315    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
316    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node5, 20f32, size.height);
317    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node5, 60f32, location.x);
318    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
319    let layout = taffy.layout(node6).unwrap();
320    let Layout { size, location, .. } = layout;
321    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6, 20f32, size.width);
322    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6, 20f32, size.height);
323    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
324    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, location.y);
325    let layout = taffy.layout(node7).unwrap();
326    let Layout { size, location, .. } = layout;
327    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node7, 20f32, size.width);
328    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node7, 20f32, size.height);
329    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node7, 30f32, location.x);
330    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, location.y);
331    let layout = taffy.layout(node8).unwrap();
332    let Layout { size, location, .. } = layout;
333    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node8, 20f32, size.width);
334    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node8, 20f32, size.height);
335    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node8, 60f32, location.x);
336    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node8, 80f32, location.y);
337}