tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Sutichaykuna

⎇ float-layout tests/generated/flex/flex_wrap_align_stretch_fits_one_row.rs Rust · 112 siq'ikuna · 5.8 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 flex_wrap_align_stretch_fits_one_row__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 { width: taffy::style::Dimension::from_length(50f32), height: auto() },
10            ..Default::default()
11        })
12        .unwrap();
13    let node1 = taffy
14        .new_leaf(taffy::style::Style {
15            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
16            ..Default::default()
17        })
18        .unwrap();
19    let node = taffy
20        .new_with_children(
21            taffy::style::Style {
22                flex_wrap: taffy::style::FlexWrap::Wrap,
23                size: taffy::geometry::Size {
24                    width: taffy::style::Dimension::from_length(150f32),
25                    height: taffy::style::Dimension::from_length(100f32),
26                },
27                ..Default::default()
28            },
29            &[node0, node1],
30        )
31        .unwrap();
32    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
33    println!("\nComputed tree:");
34    taffy.print_tree(node);
35    println!();
36    let layout = taffy.layout(node).unwrap();
37    let Layout { size, location, .. } = layout;
38    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
39    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
40    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
41    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
42    let layout = taffy.layout(node0).unwrap();
43    let Layout { size, location, .. } = layout;
44    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
45    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
46    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
47    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
48    let layout = taffy.layout(node1).unwrap();
49    let Layout { size, location, .. } = layout;
50    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
51    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
52    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
54}
55
56#[test]
57#[allow(non_snake_case)]
58fn flex_wrap_align_stretch_fits_one_row__content_box() {
59    #[allow(unused_imports)]
60    use taffy::{prelude::*, Layout};
61    let mut taffy = crate::new_test_tree();
62    let node0 = taffy
63        .new_leaf(taffy::style::Style {
64            box_sizing: taffy::style::BoxSizing::ContentBox,
65            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
66            ..Default::default()
67        })
68        .unwrap();
69    let node1 = taffy
70        .new_leaf(taffy::style::Style {
71            box_sizing: taffy::style::BoxSizing::ContentBox,
72            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
73            ..Default::default()
74        })
75        .unwrap();
76    let node = taffy
77        .new_with_children(
78            taffy::style::Style {
79                box_sizing: taffy::style::BoxSizing::ContentBox,
80                flex_wrap: taffy::style::FlexWrap::Wrap,
81                size: taffy::geometry::Size {
82                    width: taffy::style::Dimension::from_length(150f32),
83                    height: taffy::style::Dimension::from_length(100f32),
84                },
85                ..Default::default()
86            },
87            &[node0, node1],
88        )
89        .unwrap();
90    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
91    println!("\nComputed tree:");
92    taffy.print_tree(node);
93    println!();
94    let layout = taffy.layout(node).unwrap();
95    let Layout { size, location, .. } = layout;
96    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
97    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
98    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
99    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
100    let layout = taffy.layout(node0).unwrap();
101    let Layout { size, location, .. } = layout;
102    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
103    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
104    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
105    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
106    let layout = taffy.layout(node1).unwrap();
107    let Layout { size, location, .. } = layout;
108    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
109    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
110    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
111    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
112}