Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn gridflex_kitchen_sink__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node000 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
10 ..Default::default()
11 })
12 .unwrap();
13 let node00100 = taffy
14 .new_leaf(taffy::style::Style {
15 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
16 ..Default::default()
17 })
18 .unwrap();
19 let node00101 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
20 let node00102 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
21 let node00103 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
22 let node0010 = taffy
23 .new_with_children(
24 taffy::style::Style {
25 display: taffy::style::Display::Grid,
26 grid_template_rows: vec![percent(0.3f32), percent(0.1f32)],
27 grid_template_columns: vec![auto(), percent(0.1f32)],
28 ..Default::default()
29 },
30 &[node00100, node00101, node00102, node00103],
31 )
32 .unwrap();
33 let node001 = taffy
34 .new_with_children(
35 taffy::style::Style {
36 flex_grow: 1f32,
37 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
38 ..Default::default()
39 },
40 &[node0010],
41 )
42 .unwrap();
43 let node00 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node000, node001]).unwrap();
44 let node01 = taffy
45 .new_leaf_with_context(
46 taffy::style::Style { ..Default::default() },
47 crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
48 )
49 .unwrap();
50 let node02 = taffy
51 .new_leaf_with_context(
52 taffy::style::Style { ..Default::default() },
53 crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
54 )
55 .unwrap();
56 let node03 = taffy
57 .new_leaf_with_context(
58 taffy::style::Style { ..Default::default() },
59 crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
60 )
61 .unwrap();
62 let node0 = taffy
63 .new_with_children(
64 taffy::style::Style {
65 display: taffy::style::Display::Grid,
66 grid_template_rows: vec![fr(1f32), fr(1f32)],
67 grid_template_columns: vec![fr(1f32), fr(1f32)],
68 ..Default::default()
69 },
70 &[node00, node01, node02, node03],
71 )
72 .unwrap();
73 let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
74 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
75 println!("\nComputed tree:");
76 taffy.print_tree(node);
77 println!();
78 let layout = taffy.layout(node).unwrap();
79 let Layout { size, location, .. } = layout;
80 assert_eq!(size.width, 140f32, "width of node {:?}. Expected {}. Actual {}", node, 140f32, size.width);
81 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
82 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
83 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
84 let layout = taffy.layout(node0).unwrap();
85 let Layout { size, location, .. } = layout;
86 assert_eq!(size.width, 140f32, "width of node {:?}. Expected {}. Actual {}", node0, 140f32, size.width);
87 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
88 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
89 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
90 let layout = taffy.layout(node00).unwrap();
91 let Layout { size, location, .. } = layout;
92 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node00, 70f32, size.width);
93 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
94 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
95 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
96 let layout = taffy.layout(node000).unwrap();
97 let Layout { size, location, .. } = layout;
98 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node000, 20f32, size.width);
99 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
100 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
101 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
102 let layout = taffy.layout(node001).unwrap();
103 let Layout { size, location, .. } = layout;
104 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node001, 50f32, size.width);
105 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node001, 10f32, size.height);
106 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node001, 20f32, location.x);
107 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node001, 0f32, location.y);
108 let layout = taffy.layout(node0010).unwrap();
109 let Layout { size, location, .. } = layout;
110 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0010, 20f32, size.width);
111 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0010, 10f32, size.height);
112 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0010, 0f32, location.x);
113 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0010, 0f32, location.y);
114 let layout = taffy.layout(node00100).unwrap();
115 let Layout { size, location, .. } = layout;
116 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00100, 20f32, size.width);
117 assert_eq!(size.height, 3f32, "height of node {:?}. Expected {}. Actual {}", node00100, 3f32, size.height);
118 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00100, 0f32, location.x);
119 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00100, 0f32, location.y);
120 let layout = taffy.layout(node00101).unwrap();
121 let Layout { size, location, .. } = layout;
122 assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node00101, 2f32, size.width);
123 assert_eq!(size.height, 3f32, "height of node {:?}. Expected {}. Actual {}", node00101, 3f32, size.height);
124 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00101, 20f32, location.x);
125 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00101, 0f32, location.y);
126 let layout = taffy.layout(node00102).unwrap();
127 let Layout { size, location, .. } = layout;
128 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00102, 20f32, size.width);
129 assert_eq!(size.height, 1f32, "height of node {:?}. Expected {}. Actual {}", node00102, 1f32, size.height);
130 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00102, 0f32, location.x);
131 assert_eq!(location.y, 3f32, "y of node {:?}. Expected {}. Actual {}", node00102, 3f32, location.y);
132 let layout = taffy.layout(node00103).unwrap();
133 let Layout { size, location, .. } = layout;
134 assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node00103, 2f32, size.width);
135 assert_eq!(size.height, 1f32, "height of node {:?}. Expected {}. Actual {}", node00103, 1f32, size.height);
136 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00103, 20f32, location.x);
137 assert_eq!(location.y, 3f32, "y of node {:?}. Expected {}. Actual {}", node00103, 3f32, location.y);
138 let layout = taffy.layout(node01).unwrap();
139 let Layout { size, location, .. } = layout;
140 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node01, 70f32, size.width);
141 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01, 10f32, size.height);
142 assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node01, 70f32, location.x);
143 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
144 let layout = taffy.layout(node02).unwrap();
145 let Layout { size, location, .. } = layout;
146 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node02, 70f32, size.width);
147 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02, 10f32, size.height);
148 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
149 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02, 10f32, location.y);
150 let layout = taffy.layout(node03).unwrap();
151 let Layout { size, location, .. } = layout;
152 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node03, 70f32, size.width);
153 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03, 10f32, size.height);
154 assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node03, 70f32, location.x);
155 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03, 10f32, location.y);
156}
157
158#[test]
159#[allow(non_snake_case)]
160fn gridflex_kitchen_sink__content_box() {
161 #[allow(unused_imports)]
162 use taffy::{prelude::*, Layout};
163 let mut taffy = crate::new_test_tree();
164 let node000 = taffy
165 .new_leaf(taffy::style::Style {
166 box_sizing: taffy::style::BoxSizing::ContentBox,
167 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
168 ..Default::default()
169 })
170 .unwrap();
171 let node00100 = taffy
172 .new_leaf(taffy::style::Style {
173 box_sizing: taffy::style::BoxSizing::ContentBox,
174 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
175 ..Default::default()
176 })
177 .unwrap();
178 let node00101 = taffy
179 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
180 .unwrap();
181 let node00102 = taffy
182 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
183 .unwrap();
184 let node00103 = taffy
185 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
186 .unwrap();
187 let node0010 = taffy
188 .new_with_children(
189 taffy::style::Style {
190 display: taffy::style::Display::Grid,
191 box_sizing: taffy::style::BoxSizing::ContentBox,
192 grid_template_rows: vec![percent(0.3f32), percent(0.1f32)],
193 grid_template_columns: vec![auto(), percent(0.1f32)],
194 ..Default::default()
195 },
196 &[node00100, node00101, node00102, node00103],
197 )
198 .unwrap();
199 let node001 = taffy
200 .new_with_children(
201 taffy::style::Style {
202 box_sizing: taffy::style::BoxSizing::ContentBox,
203 flex_grow: 1f32,
204 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
205 ..Default::default()
206 },
207 &[node0010],
208 )
209 .unwrap();
210 let node00 = taffy
211 .new_with_children(
212 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
213 &[node000, node001],
214 )
215 .unwrap();
216 let node01 = taffy
217 .new_leaf_with_context(
218 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
219 crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
220 )
221 .unwrap();
222 let node02 = taffy
223 .new_leaf_with_context(
224 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
225 crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
226 )
227 .unwrap();
228 let node03 = taffy
229 .new_leaf_with_context(
230 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
231 crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
232 )
233 .unwrap();
234 let node0 = taffy
235 .new_with_children(
236 taffy::style::Style {
237 display: taffy::style::Display::Grid,
238 box_sizing: taffy::style::BoxSizing::ContentBox,
239 grid_template_rows: vec![fr(1f32), fr(1f32)],
240 grid_template_columns: vec![fr(1f32), fr(1f32)],
241 ..Default::default()
242 },
243 &[node00, node01, node02, node03],
244 )
245 .unwrap();
246 let node = taffy
247 .new_with_children(
248 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
249 &[node0],
250 )
251 .unwrap();
252 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
253 println!("\nComputed tree:");
254 taffy.print_tree(node);
255 println!();
256 let layout = taffy.layout(node).unwrap();
257 let Layout { size, location, .. } = layout;
258 assert_eq!(size.width, 140f32, "width of node {:?}. Expected {}. Actual {}", node, 140f32, size.width);
259 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
260 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
261 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
262 let layout = taffy.layout(node0).unwrap();
263 let Layout { size, location, .. } = layout;
264 assert_eq!(size.width, 140f32, "width of node {:?}. Expected {}. Actual {}", node0, 140f32, size.width);
265 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
266 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
267 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
268 let layout = taffy.layout(node00).unwrap();
269 let Layout { size, location, .. } = layout;
270 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node00, 70f32, size.width);
271 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
272 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
273 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
274 let layout = taffy.layout(node000).unwrap();
275 let Layout { size, location, .. } = layout;
276 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node000, 20f32, size.width);
277 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
278 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
279 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
280 let layout = taffy.layout(node001).unwrap();
281 let Layout { size, location, .. } = layout;
282 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node001, 50f32, size.width);
283 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node001, 10f32, size.height);
284 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node001, 20f32, location.x);
285 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node001, 0f32, location.y);
286 let layout = taffy.layout(node0010).unwrap();
287 let Layout { size, location, .. } = layout;
288 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0010, 20f32, size.width);
289 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0010, 10f32, size.height);
290 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0010, 0f32, location.x);
291 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0010, 0f32, location.y);
292 let layout = taffy.layout(node00100).unwrap();
293 let Layout { size, location, .. } = layout;
294 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00100, 20f32, size.width);
295 assert_eq!(size.height, 3f32, "height of node {:?}. Expected {}. Actual {}", node00100, 3f32, size.height);
296 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00100, 0f32, location.x);
297 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00100, 0f32, location.y);
298 let layout = taffy.layout(node00101).unwrap();
299 let Layout { size, location, .. } = layout;
300 assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node00101, 2f32, size.width);
301 assert_eq!(size.height, 3f32, "height of node {:?}. Expected {}. Actual {}", node00101, 3f32, size.height);
302 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00101, 20f32, location.x);
303 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00101, 0f32, location.y);
304 let layout = taffy.layout(node00102).unwrap();
305 let Layout { size, location, .. } = layout;
306 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00102, 20f32, size.width);
307 assert_eq!(size.height, 1f32, "height of node {:?}. Expected {}. Actual {}", node00102, 1f32, size.height);
308 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00102, 0f32, location.x);
309 assert_eq!(location.y, 3f32, "y of node {:?}. Expected {}. Actual {}", node00102, 3f32, location.y);
310 let layout = taffy.layout(node00103).unwrap();
311 let Layout { size, location, .. } = layout;
312 assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node00103, 2f32, size.width);
313 assert_eq!(size.height, 1f32, "height of node {:?}. Expected {}. Actual {}", node00103, 1f32, size.height);
314 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00103, 20f32, location.x);
315 assert_eq!(location.y, 3f32, "y of node {:?}. Expected {}. Actual {}", node00103, 3f32, location.y);
316 let layout = taffy.layout(node01).unwrap();
317 let Layout { size, location, .. } = layout;
318 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node01, 70f32, size.width);
319 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01, 10f32, size.height);
320 assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node01, 70f32, location.x);
321 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
322 let layout = taffy.layout(node02).unwrap();
323 let Layout { size, location, .. } = layout;
324 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node02, 70f32, size.width);
325 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02, 10f32, size.height);
326 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
327 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02, 10f32, location.y);
328 let layout = taffy.layout(node03).unwrap();
329 let Layout { size, location, .. } = layout;
330 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node03, 70f32, size.width);
331 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03, 10f32, size.height);
332 assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node03, 70f32, location.x);
333 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03, 10f32, location.y);
334}