tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definiciones

⎇ b746ac4f346dde8a2b6f85d3a428c02a2342f099 tests/generated/flex/align_content_flex_start_with_flex.rs Rust · 431 líneas · 17.6 KB Historia Quién tocó qué crudo

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn align_content_flex_start_with_flex__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, tree::Layout, TaffyTree};
6    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            flex_grow: 1f32,
10            flex_shrink: 0f32,
11            flex_basis: taffy::style::Dimension::Percent(0f32),
12            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
13            ..Default::default()
14        })
15        .unwrap();
16    let node1 = taffy
17        .new_leaf(taffy::style::Style {
18            flex_grow: 1f32,
19            flex_shrink: 0f32,
20            flex_basis: taffy::style::Dimension::Percent(0f32),
21            size: taffy::geometry::Size {
22                width: taffy::style::Dimension::Length(50f32),
23                height: taffy::style::Dimension::Length(10f32),
24            },
25            ..Default::default()
26        })
27        .unwrap();
28    let node2 = taffy
29        .new_leaf(taffy::style::Style {
30            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
31            ..Default::default()
32        })
33        .unwrap();
34    let node3 = taffy
35        .new_leaf(taffy::style::Style {
36            flex_grow: 1f32,
37            flex_shrink: 1f32,
38            flex_basis: taffy::style::Dimension::Percent(0f32),
39            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
40            ..Default::default()
41        })
42        .unwrap();
43    let node4 = taffy
44        .new_leaf(taffy::style::Style {
45            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
46            ..Default::default()
47        })
48        .unwrap();
49    let node = taffy
50        .new_with_children(
51            taffy::style::Style {
52                flex_direction: taffy::style::FlexDirection::Column,
53                flex_wrap: taffy::style::FlexWrap::Wrap,
54                align_content: Some(taffy::style::AlignContent::FlexStart),
55                size: taffy::geometry::Size {
56                    width: taffy::style::Dimension::Length(100f32),
57                    height: taffy::style::Dimension::Length(120f32),
58                },
59                ..Default::default()
60            },
61            &[node0, node1, node2, node3, node4],
62        )
63        .unwrap();
64    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
65    println!("\nComputed tree:");
66    taffy.print_tree(node);
67    println!();
68    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
69    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
70    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
71    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
72    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
73    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
74    #[cfg(feature = "content_size")]
75    assert_eq!(
76        layout.scroll_width(),
77        0f32,
78        "scroll_width of node {:?}. Expected {}. Actual {}",
79        node,
80        0f32,
81        layout.scroll_width()
82    );
83    #[cfg(feature = "content_size")]
84    assert_eq!(
85        layout.scroll_height(),
86        0f32,
87        "scroll_height of node {:?}. Expected {}. Actual {}",
88        node,
89        0f32,
90        layout.scroll_height()
91    );
92    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
93    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
94    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
95    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
96    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
97    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
98    #[cfg(feature = "content_size")]
99    assert_eq!(
100        layout.scroll_width(),
101        0f32,
102        "scroll_width of node {:?}. Expected {}. Actual {}",
103        node0,
104        0f32,
105        layout.scroll_width()
106    );
107    #[cfg(feature = "content_size")]
108    assert_eq!(
109        layout.scroll_height(),
110        0f32,
111        "scroll_height of node {:?}. Expected {}. Actual {}",
112        node0,
113        0f32,
114        layout.scroll_height()
115    );
116    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
117    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
118    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
119    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
120    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
121    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
122    #[cfg(feature = "content_size")]
123    assert_eq!(
124        layout.scroll_width(),
125        0f32,
126        "scroll_width of node {:?}. Expected {}. Actual {}",
127        node1,
128        0f32,
129        layout.scroll_width()
130    );
131    #[cfg(feature = "content_size")]
132    assert_eq!(
133        layout.scroll_height(),
134        0f32,
135        "scroll_height of node {:?}. Expected {}. Actual {}",
136        node1,
137        0f32,
138        layout.scroll_height()
139    );
140    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
141    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
142    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
143    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node2, 0f32, size.height);
144    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
145    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node2, 80f32, location.y);
146    #[cfg(feature = "content_size")]
147    assert_eq!(
148        layout.scroll_width(),
149        0f32,
150        "scroll_width of node {:?}. Expected {}. Actual {}",
151        node2,
152        0f32,
153        layout.scroll_width()
154    );
155    #[cfg(feature = "content_size")]
156    assert_eq!(
157        layout.scroll_height(),
158        0f32,
159        "scroll_height of node {:?}. Expected {}. Actual {}",
160        node2,
161        0f32,
162        layout.scroll_height()
163    );
164    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
165    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
166    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
167    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
168    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
169    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node3, 80f32, location.y);
170    #[cfg(feature = "content_size")]
171    assert_eq!(
172        layout.scroll_width(),
173        0f32,
174        "scroll_width of node {:?}. Expected {}. Actual {}",
175        node3,
176        0f32,
177        layout.scroll_width()
178    );
179    #[cfg(feature = "content_size")]
180    assert_eq!(
181        layout.scroll_height(),
182        0f32,
183        "scroll_height of node {:?}. Expected {}. Actual {}",
184        node3,
185        0f32,
186        layout.scroll_height()
187    );
188    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
189    let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
190    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
191    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node4, 0f32, size.height);
192    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
193    assert_eq!(location.y, 120f32, "y of node {:?}. Expected {}. Actual {}", node4, 120f32, location.y);
194    #[cfg(feature = "content_size")]
195    assert_eq!(
196        layout.scroll_width(),
197        0f32,
198        "scroll_width of node {:?}. Expected {}. Actual {}",
199        node4,
200        0f32,
201        layout.scroll_width()
202    );
203    #[cfg(feature = "content_size")]
204    assert_eq!(
205        layout.scroll_height(),
206        0f32,
207        "scroll_height of node {:?}. Expected {}. Actual {}",
208        node4,
209        0f32,
210        layout.scroll_height()
211    );
212}
213
214#[test]
215#[allow(non_snake_case)]
216fn align_content_flex_start_with_flex__content_box() {
217    #[allow(unused_imports)]
218    use taffy::{prelude::*, tree::Layout, TaffyTree};
219    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
220    let node0 = taffy
221        .new_leaf(taffy::style::Style {
222            box_sizing: taffy::style::BoxSizing::ContentBox,
223            flex_grow: 1f32,
224            flex_shrink: 0f32,
225            flex_basis: taffy::style::Dimension::Percent(0f32),
226            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
227            ..Default::default()
228        })
229        .unwrap();
230    let node1 = taffy
231        .new_leaf(taffy::style::Style {
232            box_sizing: taffy::style::BoxSizing::ContentBox,
233            flex_grow: 1f32,
234            flex_shrink: 0f32,
235            flex_basis: taffy::style::Dimension::Percent(0f32),
236            size: taffy::geometry::Size {
237                width: taffy::style::Dimension::Length(50f32),
238                height: taffy::style::Dimension::Length(10f32),
239            },
240            ..Default::default()
241        })
242        .unwrap();
243    let node2 = taffy
244        .new_leaf(taffy::style::Style {
245            box_sizing: taffy::style::BoxSizing::ContentBox,
246            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
247            ..Default::default()
248        })
249        .unwrap();
250    let node3 = taffy
251        .new_leaf(taffy::style::Style {
252            box_sizing: taffy::style::BoxSizing::ContentBox,
253            flex_grow: 1f32,
254            flex_shrink: 1f32,
255            flex_basis: taffy::style::Dimension::Percent(0f32),
256            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
257            ..Default::default()
258        })
259        .unwrap();
260    let node4 = taffy
261        .new_leaf(taffy::style::Style {
262            box_sizing: taffy::style::BoxSizing::ContentBox,
263            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
264            ..Default::default()
265        })
266        .unwrap();
267    let node = taffy
268        .new_with_children(
269            taffy::style::Style {
270                box_sizing: taffy::style::BoxSizing::ContentBox,
271                flex_direction: taffy::style::FlexDirection::Column,
272                flex_wrap: taffy::style::FlexWrap::Wrap,
273                align_content: Some(taffy::style::AlignContent::FlexStart),
274                size: taffy::geometry::Size {
275                    width: taffy::style::Dimension::Length(100f32),
276                    height: taffy::style::Dimension::Length(120f32),
277                },
278                ..Default::default()
279            },
280            &[node0, node1, node2, node3, node4],
281        )
282        .unwrap();
283    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
284    println!("\nComputed tree:");
285    taffy.print_tree(node);
286    println!();
287    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
288    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
289    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
290    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
291    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
292    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
293    #[cfg(feature = "content_size")]
294    assert_eq!(
295        layout.scroll_width(),
296        0f32,
297        "scroll_width of node {:?}. Expected {}. Actual {}",
298        node,
299        0f32,
300        layout.scroll_width()
301    );
302    #[cfg(feature = "content_size")]
303    assert_eq!(
304        layout.scroll_height(),
305        0f32,
306        "scroll_height of node {:?}. Expected {}. Actual {}",
307        node,
308        0f32,
309        layout.scroll_height()
310    );
311    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
312    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
313    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
314    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
315    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
316    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
317    #[cfg(feature = "content_size")]
318    assert_eq!(
319        layout.scroll_width(),
320        0f32,
321        "scroll_width of node {:?}. Expected {}. Actual {}",
322        node0,
323        0f32,
324        layout.scroll_width()
325    );
326    #[cfg(feature = "content_size")]
327    assert_eq!(
328        layout.scroll_height(),
329        0f32,
330        "scroll_height of node {:?}. Expected {}. Actual {}",
331        node0,
332        0f32,
333        layout.scroll_height()
334    );
335    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
336    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
337    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
338    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
339    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
340    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
341    #[cfg(feature = "content_size")]
342    assert_eq!(
343        layout.scroll_width(),
344        0f32,
345        "scroll_width of node {:?}. Expected {}. Actual {}",
346        node1,
347        0f32,
348        layout.scroll_width()
349    );
350    #[cfg(feature = "content_size")]
351    assert_eq!(
352        layout.scroll_height(),
353        0f32,
354        "scroll_height of node {:?}. Expected {}. Actual {}",
355        node1,
356        0f32,
357        layout.scroll_height()
358    );
359    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
360    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
361    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
362    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node2, 0f32, size.height);
363    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
364    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node2, 80f32, location.y);
365    #[cfg(feature = "content_size")]
366    assert_eq!(
367        layout.scroll_width(),
368        0f32,
369        "scroll_width of node {:?}. Expected {}. Actual {}",
370        node2,
371        0f32,
372        layout.scroll_width()
373    );
374    #[cfg(feature = "content_size")]
375    assert_eq!(
376        layout.scroll_height(),
377        0f32,
378        "scroll_height of node {:?}. Expected {}. Actual {}",
379        node2,
380        0f32,
381        layout.scroll_height()
382    );
383    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
384    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
385    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
386    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
387    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
388    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node3, 80f32, location.y);
389    #[cfg(feature = "content_size")]
390    assert_eq!(
391        layout.scroll_width(),
392        0f32,
393        "scroll_width of node {:?}. Expected {}. Actual {}",
394        node3,
395        0f32,
396        layout.scroll_width()
397    );
398    #[cfg(feature = "content_size")]
399    assert_eq!(
400        layout.scroll_height(),
401        0f32,
402        "scroll_height of node {:?}. Expected {}. Actual {}",
403        node3,
404        0f32,
405        layout.scroll_height()
406    );
407    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
408    let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
409    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
410    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node4, 0f32, size.height);
411    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
412    assert_eq!(location.y, 120f32, "y of node {:?}. Expected {}. Actual {}", node4, 120f32, location.y);
413    #[cfg(feature = "content_size")]
414    assert_eq!(
415        layout.scroll_width(),
416        0f32,
417        "scroll_width of node {:?}. Expected {}. Actual {}",
418        node4,
419        0f32,
420        layout.scroll_width()
421    );
422    #[cfg(feature = "content_size")]
423    assert_eq!(
424        layout.scroll_height(),
425        0f32,
426        "scroll_height of node {:?}. Expected {}. Actual {}",
427        node4,
428        0f32,
429        layout.scroll_height()
430    );
431}