tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

⎇ float-layout tests/generated/flex/multiline_min_max_14.rs Rust · 219 lines · 11.1 KB History Who touched what raw

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn multiline_min_max_14__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            flex_grow: 1f32,
10            flex_shrink: 1f32,
11            flex_basis: taffy::style::Dimension::from_length(600f32),
12            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
13            max_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(300f32), height: auto() },
14            margin: taffy::geometry::Rect { left: length(10f32), right: zero(), top: zero(), bottom: zero() },
15            ..Default::default()
16        })
17        .unwrap();
18    let node1 = taffy
19        .new_leaf(taffy::style::Style {
20            flex_grow: 1f32,
21            flex_shrink: 1f32,
22            flex_basis: taffy::style::Dimension::AUTO,
23            size: taffy::geometry::Size {
24                width: taffy::style::Dimension::from_length(100f32),
25                height: taffy::style::Dimension::from_length(10f32),
26            },
27            ..Default::default()
28        })
29        .unwrap();
30    let node2 = taffy
31        .new_leaf(taffy::style::Style {
32            flex_grow: 1f32,
33            flex_shrink: 1f32,
34            flex_basis: taffy::style::Dimension::AUTO,
35            size: taffy::geometry::Size {
36                width: taffy::style::Dimension::from_length(100f32),
37                height: taffy::style::Dimension::from_length(10f32),
38            },
39            ..Default::default()
40        })
41        .unwrap();
42    let node3 = taffy
43        .new_leaf(taffy::style::Style {
44            flex_grow: 1f32,
45            flex_shrink: 1f32,
46            flex_basis: taffy::style::Dimension::AUTO,
47            size: taffy::geometry::Size {
48                width: taffy::style::Dimension::from_length(100f32),
49                height: taffy::style::Dimension::from_length(10f32),
50            },
51            ..Default::default()
52        })
53        .unwrap();
54    let node = taffy
55        .new_with_children(
56            taffy::style::Style {
57                display: taffy::style::Display::Flex,
58                box_sizing: taffy::style::BoxSizing::ContentBox,
59                flex_wrap: taffy::style::FlexWrap::Wrap,
60                size: taffy::geometry::Size {
61                    width: taffy::style::Dimension::from_length(600f32),
62                    height: taffy::style::Dimension::from_length(20f32),
63                },
64                border: taffy::geometry::Rect {
65                    left: length(5f32),
66                    right: length(5f32),
67                    top: length(5f32),
68                    bottom: length(5f32),
69                },
70                ..Default::default()
71            },
72            &[node0, node1, node2, node3],
73        )
74        .unwrap();
75    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
76    println!("\nComputed tree:");
77    taffy.print_tree(node);
78    println!();
79    let layout = taffy.layout(node).unwrap();
80    let Layout { size, location, .. } = layout;
81    assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width);
82    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, size.height);
83    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
84    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
85    let layout = taffy.layout(node0).unwrap();
86    let Layout { size, location, .. } = layout;
87    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width);
88    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
89    assert_eq!(location.x, 15f32, "x of node {:?}. Expected {}. Actual {}", node0, 15f32, location.x);
90    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
91    let layout = taffy.layout(node1).unwrap();
92    let Layout { size, location, .. } = layout;
93    assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node1, 145f32, size.width);
94    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
95    assert_eq!(location.x, 315f32, "x of node {:?}. Expected {}. Actual {}", node1, 315f32, location.x);
96    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y);
97    let layout = taffy.layout(node2).unwrap();
98    let Layout { size, location, .. } = layout;
99    assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node2, 145f32, size.width);
100    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
101    assert_eq!(location.x, 460f32, "x of node {:?}. Expected {}. Actual {}", node2, 460f32, location.x);
102    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y);
103    let layout = taffy.layout(node3).unwrap();
104    let Layout { size, location, .. } = layout;
105    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node3, 600f32, size.width);
106    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
107    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node3, 5f32, location.x);
108    assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node3, 15f32, location.y);
109}
110
111#[test]
112#[allow(non_snake_case)]
113fn multiline_min_max_14__content_box() {
114    #[allow(unused_imports)]
115    use taffy::{prelude::*, Layout};
116    let mut taffy = crate::new_test_tree();
117    let node0 = taffy
118        .new_leaf(taffy::style::Style {
119            flex_grow: 1f32,
120            flex_shrink: 1f32,
121            flex_basis: taffy::style::Dimension::from_length(600f32),
122            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
123            max_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(300f32), height: auto() },
124            margin: taffy::geometry::Rect { left: length(10f32), right: zero(), top: zero(), bottom: zero() },
125            ..Default::default()
126        })
127        .unwrap();
128    let node1 = taffy
129        .new_leaf(taffy::style::Style {
130            flex_grow: 1f32,
131            flex_shrink: 1f32,
132            flex_basis: taffy::style::Dimension::AUTO,
133            size: taffy::geometry::Size {
134                width: taffy::style::Dimension::from_length(100f32),
135                height: taffy::style::Dimension::from_length(10f32),
136            },
137            ..Default::default()
138        })
139        .unwrap();
140    let node2 = taffy
141        .new_leaf(taffy::style::Style {
142            flex_grow: 1f32,
143            flex_shrink: 1f32,
144            flex_basis: taffy::style::Dimension::AUTO,
145            size: taffy::geometry::Size {
146                width: taffy::style::Dimension::from_length(100f32),
147                height: taffy::style::Dimension::from_length(10f32),
148            },
149            ..Default::default()
150        })
151        .unwrap();
152    let node3 = taffy
153        .new_leaf(taffy::style::Style {
154            flex_grow: 1f32,
155            flex_shrink: 1f32,
156            flex_basis: taffy::style::Dimension::AUTO,
157            size: taffy::geometry::Size {
158                width: taffy::style::Dimension::from_length(100f32),
159                height: taffy::style::Dimension::from_length(10f32),
160            },
161            ..Default::default()
162        })
163        .unwrap();
164    let node = taffy
165        .new_with_children(
166            taffy::style::Style {
167                display: taffy::style::Display::Flex,
168                box_sizing: taffy::style::BoxSizing::ContentBox,
169                flex_wrap: taffy::style::FlexWrap::Wrap,
170                size: taffy::geometry::Size {
171                    width: taffy::style::Dimension::from_length(600f32),
172                    height: taffy::style::Dimension::from_length(20f32),
173                },
174                border: taffy::geometry::Rect {
175                    left: length(5f32),
176                    right: length(5f32),
177                    top: length(5f32),
178                    bottom: length(5f32),
179                },
180                ..Default::default()
181            },
182            &[node0, node1, node2, node3],
183        )
184        .unwrap();
185    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
186    println!("\nComputed tree:");
187    taffy.print_tree(node);
188    println!();
189    let layout = taffy.layout(node).unwrap();
190    let Layout { size, location, .. } = layout;
191    assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width);
192    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, size.height);
193    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
194    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
195    let layout = taffy.layout(node0).unwrap();
196    let Layout { size, location, .. } = layout;
197    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width);
198    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
199    assert_eq!(location.x, 15f32, "x of node {:?}. Expected {}. Actual {}", node0, 15f32, location.x);
200    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
201    let layout = taffy.layout(node1).unwrap();
202    let Layout { size, location, .. } = layout;
203    assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node1, 145f32, size.width);
204    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
205    assert_eq!(location.x, 315f32, "x of node {:?}. Expected {}. Actual {}", node1, 315f32, location.x);
206    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y);
207    let layout = taffy.layout(node2).unwrap();
208    let Layout { size, location, .. } = layout;
209    assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node2, 145f32, size.width);
210    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
211    assert_eq!(location.x, 460f32, "x of node {:?}. Expected {}. Actual {}", node2, 460f32, location.x);
212    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y);
213    let layout = taffy.layout(node3).unwrap();
214    let Layout { size, location, .. } = layout;
215    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node3, 600f32, size.width);
216    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
217    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node3, 5f32, location.x);
218    assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node3, 15f32, location.y);
219}