tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Sutichaykuna

⎇ e6255f79aa9a3f8065504fddb315ff4a6dfe6d0f tests/generated/flex/flex_grow_0_min_size.rs Rust · 426 siq'ikuna · 16.6 KB Ñawpa willay Pi imata llamkarqan ch'uya

Flexbox: Fix flooring hypothetical_main_size by computed min size (#689) e6255f79a · Nico Burns ·

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