tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 717HTML 669Markdown 12TOML 62372 Definiciones

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/multiline_min_max_8.rs Rust · 413 líneas · 16.8 KB Historia Quién tocó qué crudo

Fix resolving flexible lengths (WPT css/flexbox-multiline-min-max test) (#692) 25571b5d0 · Nico Burns ·

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