⎇ float-layout
tests/generated/block/block_absolute_resolved_insets.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn block_absolute_resolved_insets__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node00 = taffy
8 .new_leaf(taffy::style::Style {
9 position: taffy::style::Position::Absolute,
10 inset: taffy::geometry::Rect {
11 left: taffy::style::LengthPercentageAuto::AUTO,
12 right: auto(),
13 top: taffy::style::LengthPercentageAuto::AUTO,
14 bottom: auto(),
15 },
16 ..Default::default()
17 })
18 .unwrap();
19 let node01 = taffy
20 .new_leaf(taffy::style::Style {
21 position: taffy::style::Position::Absolute,
22 inset: taffy::geometry::Rect { left: length(0f32), right: auto(), top: length(0f32), bottom: auto() },
23 ..Default::default()
24 })
25 .unwrap();
26 let node02 = taffy
27 .new_leaf(taffy::style::Style {
28 position: taffy::style::Position::Absolute,
29 inset: taffy::geometry::Rect { left: percent(1f32), right: auto(), top: percent(1f32), bottom: auto() },
30 ..Default::default()
31 })
32 .unwrap();
33 let node03 = taffy
34 .new_leaf(taffy::style::Style {
35 position: taffy::style::Position::Absolute,
36 inset: taffy::geometry::Rect { left: auto(), right: percent(1f32), top: auto(), bottom: percent(1f32) },
37 ..Default::default()
38 })
39 .unwrap();
40 let node04 = taffy
41 .new_leaf(taffy::style::Style {
42 position: taffy::style::Position::Absolute,
43 inset: taffy::geometry::Rect { left: length(30f32), right: auto(), top: length(30f32), bottom: auto() },
44 ..Default::default()
45 })
46 .unwrap();
47 let node05 = taffy
48 .new_leaf(taffy::style::Style {
49 position: taffy::style::Position::Absolute,
50 size: taffy::geometry::Size {
51 width: taffy::style::Dimension::from_percent(1f32),
52 height: taffy::style::Dimension::from_percent(1f32),
53 },
54 inset: taffy::geometry::Rect { left: length(0f32), right: auto(), top: length(0f32), bottom: auto() },
55 ..Default::default()
56 })
57 .unwrap();
58 let node0 = taffy
59 .new_with_children(
60 taffy::style::Style {
61 display: taffy::style::Display::Block,
62 size: taffy::geometry::Size {
63 width: taffy::style::Dimension::from_length(200f32),
64 height: taffy::style::Dimension::from_length(200f32),
65 },
66 padding: taffy::geometry::Rect {
67 left: length(15f32),
68 right: length(15f32),
69 top: length(15f32),
70 bottom: length(15f32),
71 },
72 border: taffy::geometry::Rect {
73 left: length(20f32),
74 right: length(20f32),
75 top: length(20f32),
76 bottom: length(20f32),
77 },
78 ..Default::default()
79 },
80 &[node00, node01, node02, node03, node04, node05],
81 )
82 .unwrap();
83 let node10 = taffy
84 .new_leaf(taffy::style::Style {
85 position: taffy::style::Position::Absolute,
86 inset: taffy::geometry::Rect {
87 left: taffy::style::LengthPercentageAuto::AUTO,
88 right: auto(),
89 top: taffy::style::LengthPercentageAuto::AUTO,
90 bottom: auto(),
91 },
92 ..Default::default()
93 })
94 .unwrap();
95 let node11 = taffy
96 .new_leaf(taffy::style::Style {
97 position: taffy::style::Position::Absolute,
98 inset: taffy::geometry::Rect { left: length(0f32), right: auto(), top: length(0f32), bottom: auto() },
99 ..Default::default()
100 })
101 .unwrap();
102 let node12 = taffy
103 .new_leaf(taffy::style::Style {
104 position: taffy::style::Position::Absolute,
105 inset: taffy::geometry::Rect { left: percent(1f32), right: auto(), top: percent(1f32), bottom: auto() },
106 ..Default::default()
107 })
108 .unwrap();
109 let node13 = taffy
110 .new_leaf(taffy::style::Style {
111 position: taffy::style::Position::Absolute,
112 inset: taffy::geometry::Rect { left: auto(), right: percent(1f32), top: auto(), bottom: percent(1f32) },
113 ..Default::default()
114 })
115 .unwrap();
116 let node14 = taffy
117 .new_leaf(taffy::style::Style {
118 position: taffy::style::Position::Absolute,
119 inset: taffy::geometry::Rect { left: length(30f32), right: auto(), top: length(30f32), bottom: auto() },
120 ..Default::default()
121 })
122 .unwrap();
123 let node15 = taffy
124 .new_leaf(taffy::style::Style {
125 position: taffy::style::Position::Absolute,
126 size: taffy::geometry::Size {
127 width: taffy::style::Dimension::from_percent(1f32),
128 height: taffy::style::Dimension::from_percent(1f32),
129 },
130 inset: taffy::geometry::Rect { left: length(0f32), right: auto(), top: length(0f32), bottom: auto() },
131 ..Default::default()
132 })
133 .unwrap();
134 let node1 = taffy
135 .new_with_children(
136 taffy::style::Style {
137 display: taffy::style::Display::Block,
138 overflow: taffy::geometry::Point {
139 x: taffy::style::Overflow::Scroll,
140 y: taffy::style::Overflow::Scroll,
141 },
142 scrollbar_width: 15f32,
143 size: taffy::geometry::Size {
144 width: taffy::style::Dimension::from_length(200f32),
145 height: taffy::style::Dimension::from_length(200f32),
146 },
147 padding: taffy::geometry::Rect {
148 left: length(15f32),
149 right: length(15f32),
150 top: length(15f32),
151 bottom: length(15f32),
152 },
153 border: taffy::geometry::Rect {
154 left: length(20f32),
155 right: length(20f32),
156 top: length(20f32),
157 bottom: length(20f32),
158 },
159 ..Default::default()
160 },
161 &[node10, node11, node12, node13, node14, node15],
162 )
163 .unwrap();
164 let node20 = taffy
165 .new_leaf(taffy::style::Style {
166 display: taffy::style::Display::Block,
167 size: taffy::geometry::Size {
168 width: taffy::style::Dimension::from_length(50f32),
169 height: taffy::style::Dimension::from_length(10f32),
170 },
171 ..Default::default()
172 })
173 .unwrap();
174 let node21 = taffy
175 .new_leaf(taffy::style::Style {
176 position: taffy::style::Position::Absolute,
177 inset: taffy::geometry::Rect {
178 left: taffy::style::LengthPercentageAuto::AUTO,
179 right: auto(),
180 top: taffy::style::LengthPercentageAuto::AUTO,
181 bottom: auto(),
182 },
183 ..Default::default()
184 })
185 .unwrap();
186 let node2 = taffy
187 .new_with_children(
188 taffy::style::Style {
189 display: taffy::style::Display::Block,
190 size: taffy::geometry::Size {
191 width: taffy::style::Dimension::from_length(200f32),
192 height: taffy::style::Dimension::from_length(200f32),
193 },
194 padding: taffy::geometry::Rect {
195 left: length(15f32),
196 right: length(15f32),
197 top: length(15f32),
198 bottom: length(15f32),
199 },
200 border: taffy::geometry::Rect {
201 left: length(20f32),
202 right: length(20f32),
203 top: length(20f32),
204 bottom: length(20f32),
205 },
206 ..Default::default()
207 },
208 &[node20, node21],
209 )
210 .unwrap();
211 let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0, node1, node2]).unwrap();
212 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
213 println!("\nComputed tree:");
214 taffy.print_tree(node);
215 println!();
216 let layout = taffy.layout(node).unwrap();
217 let Layout { size, location, .. } = layout;
218 assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node, 600f32, size.width);
219 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
220 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
221 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
222 let layout = taffy.layout(node0).unwrap();
223 let Layout { size, location, .. } = layout;
224 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
225 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node0, 200f32, size.height);
226 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
227 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
228 let layout = taffy.layout(node00).unwrap();
229 let Layout { size, location, .. } = layout;
230 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node00, 0f32, size.width);
231 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node00, 0f32, size.height);
232 assert_eq!(location.x, 35f32, "x of node {:?}. Expected {}. Actual {}", node00, 35f32, location.x);
233 assert_eq!(location.y, 35f32, "y of node {:?}. Expected {}. Actual {}", node00, 35f32, location.y);
234 let layout = taffy.layout(node01).unwrap();
235 let Layout { size, location, .. } = layout;
236 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node01, 0f32, size.width);
237 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node01, 0f32, size.height);
238 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
239 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node01, 20f32, location.y);
240 let layout = taffy.layout(node02).unwrap();
241 let Layout { size, location, .. } = layout;
242 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node02, 0f32, size.width);
243 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node02, 0f32, size.height);
244 assert_eq!(location.x, 180f32, "x of node {:?}. Expected {}. Actual {}", node02, 180f32, location.x);
245 assert_eq!(location.y, 180f32, "y of node {:?}. Expected {}. Actual {}", node02, 180f32, location.y);
246 let layout = taffy.layout(node03).unwrap();
247 let Layout { size, location, .. } = layout;
248 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node03, 0f32, size.width);
249 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node03, 0f32, size.height);
250 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03, 20f32, location.x);
251 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node03, 20f32, location.y);
252 let layout = taffy.layout(node04).unwrap();
253 let Layout { size, location, .. } = layout;
254 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node04, 0f32, size.width);
255 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node04, 0f32, size.height);
256 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node04, 50f32, location.x);
257 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node04, 50f32, location.y);
258 let layout = taffy.layout(node05).unwrap();
259 let Layout { size, location, .. } = layout;
260 assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node05, 160f32, size.width);
261 assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node05, 160f32, size.height);
262 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node05, 20f32, location.x);
263 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node05, 20f32, location.y);
264 let layout = taffy.layout(node1).unwrap();
265 let Layout { size, location, .. } = layout;
266 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1, 200f32, size.width);
267 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node1, 200f32, size.height);
268 assert_eq!(location.x, 200f32, "x of node {:?}. Expected {}. Actual {}", node1, 200f32, location.x);
269 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
270 #[cfg(feature = "content_size")]
271 assert_eq!(
272 layout.scroll_width(),
273 0f32,
274 "scroll_width of node {:?}. Expected {}. Actual {}",
275 node1,
276 0f32,
277 layout.scroll_width()
278 );
279 #[cfg(feature = "content_size")]
280 assert_eq!(
281 layout.scroll_height(),
282 0f32,
283 "scroll_height of node {:?}. Expected {}. Actual {}",
284 node1,
285 0f32,
286 layout.scroll_height()
287 );
288 let layout = taffy.layout(node10).unwrap();
289 let Layout { size, location, .. } = layout;
290 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node10, 0f32, size.width);
291 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node10, 0f32, size.height);
292 assert_eq!(location.x, 35f32, "x of node {:?}. Expected {}. Actual {}", node10, 35f32, location.x);
293 assert_eq!(location.y, 35f32, "y of node {:?}. Expected {}. Actual {}", node10, 35f32, location.y);
294 let layout = taffy.layout(node11).unwrap();
295 let Layout { size, location, .. } = layout;
296 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node11, 0f32, size.width);
297 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node11, 0f32, size.height);
298 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node11, 20f32, location.x);
299 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node11, 20f32, location.y);
300 let layout = taffy.layout(node12).unwrap();
301 let Layout { size, location, .. } = layout;
302 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node12, 0f32, size.width);
303 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node12, 0f32, size.height);
304 assert_eq!(location.x, 165f32, "x of node {:?}. Expected {}. Actual {}", node12, 165f32, location.x);
305 assert_eq!(location.y, 165f32, "y of node {:?}. Expected {}. Actual {}", node12, 165f32, location.y);
306 let layout = taffy.layout(node13).unwrap();
307 let Layout { size, location, .. } = layout;
308 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node13, 0f32, size.width);
309 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node13, 0f32, size.height);
310 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node13, 20f32, location.x);
311 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node13, 20f32, location.y);
312 let layout = taffy.layout(node14).unwrap();
313 let Layout { size, location, .. } = layout;
314 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node14, 0f32, size.width);
315 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node14, 0f32, size.height);
316 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node14, 50f32, location.x);
317 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node14, 50f32, location.y);
318 let layout = taffy.layout(node15).unwrap();
319 let Layout { size, location, .. } = layout;
320 assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node15, 145f32, size.width);
321 assert_eq!(size.height, 145f32, "height of node {:?}. Expected {}. Actual {}", node15, 145f32, size.height);
322 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node15, 20f32, location.x);
323 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node15, 20f32, location.y);
324 let layout = taffy.layout(node2).unwrap();
325 let Layout { size, location, .. } = layout;
326 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node2, 200f32, size.width);
327 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node2, 200f32, size.height);
328 assert_eq!(location.x, 400f32, "x of node {:?}. Expected {}. Actual {}", node2, 400f32, location.x);
329 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
330 let layout = taffy.layout(node20).unwrap();
331 let Layout { size, location, .. } = layout;
332 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node20, 50f32, size.width);
333 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20, 10f32, size.height);
334 assert_eq!(location.x, 35f32, "x of node {:?}. Expected {}. Actual {}", node20, 35f32, location.x);
335 assert_eq!(location.y, 35f32, "y of node {:?}. Expected {}. Actual {}", node20, 35f32, location.y);
336 let layout = taffy.layout(node21).unwrap();
337 let Layout { size, location, .. } = layout;
338 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node21, 0f32, size.width);
339 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node21, 0f32, size.height);
340 assert_eq!(location.x, 35f32, "x of node {:?}. Expected {}. Actual {}", node21, 35f32, location.x);
341 assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node21, 45f32, location.y);
342}
343
344#[test]
345#[allow(non_snake_case)]
346fn block_absolute_resolved_insets__content_box() {
347 #[allow(unused_imports)]
348 use taffy::{prelude::*, Layout};
349 let mut taffy = crate::new_test_tree();
350 let node00 = taffy
351 .new_leaf(taffy::style::Style {
352 box_sizing: taffy::style::BoxSizing::ContentBox,
353 position: taffy::style::Position::Absolute,
354 inset: taffy::geometry::Rect {
355 left: taffy::style::LengthPercentageAuto::AUTO,
356 right: auto(),
357 top: taffy::style::LengthPercentageAuto::AUTO,
358 bottom: auto(),
359 },
360 ..Default::default()
361 })
362 .unwrap();
363 let node01 = taffy
364 .new_leaf(taffy::style::Style {
365 box_sizing: taffy::style::BoxSizing::ContentBox,
366 position: taffy::style::Position::Absolute,
367 inset: taffy::geometry::Rect { left: length(0f32), right: auto(), top: length(0f32), bottom: auto() },
368 ..Default::default()
369 })
370 .unwrap();
371 let node02 = taffy
372 .new_leaf(taffy::style::Style {
373 box_sizing: taffy::style::BoxSizing::ContentBox,
374 position: taffy::style::Position::Absolute,
375 inset: taffy::geometry::Rect { left: percent(1f32), right: auto(), top: percent(1f32), bottom: auto() },
376 ..Default::default()
377 })
378 .unwrap();
379 let node03 = taffy
380 .new_leaf(taffy::style::Style {
381 box_sizing: taffy::style::BoxSizing::ContentBox,
382 position: taffy::style::Position::Absolute,
383 inset: taffy::geometry::Rect { left: auto(), right: percent(1f32), top: auto(), bottom: percent(1f32) },
384 ..Default::default()
385 })
386 .unwrap();
387 let node04 = taffy
388 .new_leaf(taffy::style::Style {
389 box_sizing: taffy::style::BoxSizing::ContentBox,
390 position: taffy::style::Position::Absolute,
391 inset: taffy::geometry::Rect { left: length(30f32), right: auto(), top: length(30f32), bottom: auto() },
392 ..Default::default()
393 })
394 .unwrap();
395 let node05 = taffy
396 .new_leaf(taffy::style::Style {
397 box_sizing: taffy::style::BoxSizing::ContentBox,
398 position: taffy::style::Position::Absolute,
399 size: taffy::geometry::Size {
400 width: taffy::style::Dimension::from_percent(1f32),
401 height: taffy::style::Dimension::from_percent(1f32),
402 },
403 inset: taffy::geometry::Rect { left: length(0f32), right: auto(), top: length(0f32), bottom: auto() },
404 ..Default::default()
405 })
406 .unwrap();
407 let node0 = taffy
408 .new_with_children(
409 taffy::style::Style {
410 display: taffy::style::Display::Block,
411 box_sizing: taffy::style::BoxSizing::ContentBox,
412 size: taffy::geometry::Size {
413 width: taffy::style::Dimension::from_length(200f32),
414 height: taffy::style::Dimension::from_length(200f32),
415 },
416 padding: taffy::geometry::Rect {
417 left: length(15f32),
418 right: length(15f32),
419 top: length(15f32),
420 bottom: length(15f32),
421 },
422 border: taffy::geometry::Rect {
423 left: length(20f32),
424 right: length(20f32),
425 top: length(20f32),
426 bottom: length(20f32),
427 },
428 ..Default::default()
429 },
430 &[node00, node01, node02, node03, node04, node05],
431 )
432 .unwrap();
433 let node10 = taffy
434 .new_leaf(taffy::style::Style {
435 box_sizing: taffy::style::BoxSizing::ContentBox,
436 position: taffy::style::Position::Absolute,
437 inset: taffy::geometry::Rect {
438 left: taffy::style::LengthPercentageAuto::AUTO,
439 right: auto(),
440 top: taffy::style::LengthPercentageAuto::AUTO,
441 bottom: auto(),
442 },
443 ..Default::default()
444 })
445 .unwrap();
446 let node11 = taffy
447 .new_leaf(taffy::style::Style {
448 box_sizing: taffy::style::BoxSizing::ContentBox,
449 position: taffy::style::Position::Absolute,
450 inset: taffy::geometry::Rect { left: length(0f32), right: auto(), top: length(0f32), bottom: auto() },
451 ..Default::default()
452 })
453 .unwrap();
454 let node12 = taffy
455 .new_leaf(taffy::style::Style {
456 box_sizing: taffy::style::BoxSizing::ContentBox,
457 position: taffy::style::Position::Absolute,
458 inset: taffy::geometry::Rect { left: percent(1f32), right: auto(), top: percent(1f32), bottom: auto() },
459 ..Default::default()
460 })
461 .unwrap();
462 let node13 = taffy
463 .new_leaf(taffy::style::Style {
464 box_sizing: taffy::style::BoxSizing::ContentBox,
465 position: taffy::style::Position::Absolute,
466 inset: taffy::geometry::Rect { left: auto(), right: percent(1f32), top: auto(), bottom: percent(1f32) },
467 ..Default::default()
468 })
469 .unwrap();
470 let node14 = taffy
471 .new_leaf(taffy::style::Style {
472 box_sizing: taffy::style::BoxSizing::ContentBox,
473 position: taffy::style::Position::Absolute,
474 inset: taffy::geometry::Rect { left: length(30f32), right: auto(), top: length(30f32), bottom: auto() },
475 ..Default::default()
476 })
477 .unwrap();
478 let node15 = taffy
479 .new_leaf(taffy::style::Style {
480 box_sizing: taffy::style::BoxSizing::ContentBox,
481 position: taffy::style::Position::Absolute,
482 size: taffy::geometry::Size {
483 width: taffy::style::Dimension::from_percent(1f32),
484 height: taffy::style::Dimension::from_percent(1f32),
485 },
486 inset: taffy::geometry::Rect { left: length(0f32), right: auto(), top: length(0f32), bottom: auto() },
487 ..Default::default()
488 })
489 .unwrap();
490 let node1 = taffy
491 .new_with_children(
492 taffy::style::Style {
493 display: taffy::style::Display::Block,
494 box_sizing: taffy::style::BoxSizing::ContentBox,
495 overflow: taffy::geometry::Point {
496 x: taffy::style::Overflow::Scroll,
497 y: taffy::style::Overflow::Scroll,
498 },
499 scrollbar_width: 15f32,
500 size: taffy::geometry::Size {
501 width: taffy::style::Dimension::from_length(200f32),
502 height: taffy::style::Dimension::from_length(200f32),
503 },
504 padding: taffy::geometry::Rect {
505 left: length(15f32),
506 right: length(15f32),
507 top: length(15f32),
508 bottom: length(15f32),
509 },
510 border: taffy::geometry::Rect {
511 left: length(20f32),
512 right: length(20f32),
513 top: length(20f32),
514 bottom: length(20f32),
515 },
516 ..Default::default()
517 },
518 &[node10, node11, node12, node13, node14, node15],
519 )
520 .unwrap();
521 let node20 = taffy
522 .new_leaf(taffy::style::Style {
523 display: taffy::style::Display::Block,
524 box_sizing: taffy::style::BoxSizing::ContentBox,
525 size: taffy::geometry::Size {
526 width: taffy::style::Dimension::from_length(50f32),
527 height: taffy::style::Dimension::from_length(10f32),
528 },
529 ..Default::default()
530 })
531 .unwrap();
532 let node21 = taffy
533 .new_leaf(taffy::style::Style {
534 box_sizing: taffy::style::BoxSizing::ContentBox,
535 position: taffy::style::Position::Absolute,
536 inset: taffy::geometry::Rect {
537 left: taffy::style::LengthPercentageAuto::AUTO,
538 right: auto(),
539 top: taffy::style::LengthPercentageAuto::AUTO,
540 bottom: auto(),
541 },
542 ..Default::default()
543 })
544 .unwrap();
545 let node2 = taffy
546 .new_with_children(
547 taffy::style::Style {
548 display: taffy::style::Display::Block,
549 box_sizing: taffy::style::BoxSizing::ContentBox,
550 size: taffy::geometry::Size {
551 width: taffy::style::Dimension::from_length(200f32),
552 height: taffy::style::Dimension::from_length(200f32),
553 },
554 padding: taffy::geometry::Rect {
555 left: length(15f32),
556 right: length(15f32),
557 top: length(15f32),
558 bottom: length(15f32),
559 },
560 border: taffy::geometry::Rect {
561 left: length(20f32),
562 right: length(20f32),
563 top: length(20f32),
564 bottom: length(20f32),
565 },
566 ..Default::default()
567 },
568 &[node20, node21],
569 )
570 .unwrap();
571 let node = taffy
572 .new_with_children(
573 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
574 &[node0, node1, node2],
575 )
576 .unwrap();
577 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
578 println!("\nComputed tree:");
579 taffy.print_tree(node);
580 println!();
581 let layout = taffy.layout(node).unwrap();
582 let Layout { size, location, .. } = layout;
583 assert_eq!(size.width, 810f32, "width of node {:?}. Expected {}. Actual {}", node, 810f32, size.width);
584 assert_eq!(size.height, 270f32, "height of node {:?}. Expected {}. Actual {}", node, 270f32, size.height);
585 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
586 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
587 let layout = taffy.layout(node0).unwrap();
588 let Layout { size, location, .. } = layout;
589 assert_eq!(size.width, 270f32, "width of node {:?}. Expected {}. Actual {}", node0, 270f32, size.width);
590 assert_eq!(size.height, 270f32, "height of node {:?}. Expected {}. Actual {}", node0, 270f32, size.height);
591 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
592 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
593 let layout = taffy.layout(node00).unwrap();
594 let Layout { size, location, .. } = layout;
595 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node00, 0f32, size.width);
596 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node00, 0f32, size.height);
597 assert_eq!(location.x, 35f32, "x of node {:?}. Expected {}. Actual {}", node00, 35f32, location.x);
598 assert_eq!(location.y, 35f32, "y of node {:?}. Expected {}. Actual {}", node00, 35f32, location.y);
599 let layout = taffy.layout(node01).unwrap();
600 let Layout { size, location, .. } = layout;
601 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node01, 0f32, size.width);
602 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node01, 0f32, size.height);
603 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
604 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node01, 20f32, location.y);
605 let layout = taffy.layout(node02).unwrap();
606 let Layout { size, location, .. } = layout;
607 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node02, 0f32, size.width);
608 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node02, 0f32, size.height);
609 assert_eq!(location.x, 250f32, "x of node {:?}. Expected {}. Actual {}", node02, 250f32, location.x);
610 assert_eq!(location.y, 250f32, "y of node {:?}. Expected {}. Actual {}", node02, 250f32, location.y);
611 let layout = taffy.layout(node03).unwrap();
612 let Layout { size, location, .. } = layout;
613 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node03, 0f32, size.width);
614 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node03, 0f32, size.height);
615 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03, 20f32, location.x);
616 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node03, 20f32, location.y);
617 let layout = taffy.layout(node04).unwrap();
618 let Layout { size, location, .. } = layout;
619 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node04, 0f32, size.width);
620 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node04, 0f32, size.height);
621 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node04, 50f32, location.x);
622 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node04, 50f32, location.y);
623 let layout = taffy.layout(node05).unwrap();
624 let Layout { size, location, .. } = layout;
625 assert_eq!(size.width, 230f32, "width of node {:?}. Expected {}. Actual {}", node05, 230f32, size.width);
626 assert_eq!(size.height, 230f32, "height of node {:?}. Expected {}. Actual {}", node05, 230f32, size.height);
627 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node05, 20f32, location.x);
628 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node05, 20f32, location.y);
629 let layout = taffy.layout(node1).unwrap();
630 let Layout { size, location, .. } = layout;
631 assert_eq!(size.width, 270f32, "width of node {:?}. Expected {}. Actual {}", node1, 270f32, size.width);
632 assert_eq!(size.height, 270f32, "height of node {:?}. Expected {}. Actual {}", node1, 270f32, size.height);
633 assert_eq!(location.x, 270f32, "x of node {:?}. Expected {}. Actual {}", node1, 270f32, location.x);
634 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
635 #[cfg(feature = "content_size")]
636 assert_eq!(
637 layout.scroll_width(),
638 0f32,
639 "scroll_width of node {:?}. Expected {}. Actual {}",
640 node1,
641 0f32,
642 layout.scroll_width()
643 );
644 #[cfg(feature = "content_size")]
645 assert_eq!(
646 layout.scroll_height(),
647 0f32,
648 "scroll_height of node {:?}. Expected {}. Actual {}",
649 node1,
650 0f32,
651 layout.scroll_height()
652 );
653 let layout = taffy.layout(node10).unwrap();
654 let Layout { size, location, .. } = layout;
655 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node10, 0f32, size.width);
656 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node10, 0f32, size.height);
657 assert_eq!(location.x, 35f32, "x of node {:?}. Expected {}. Actual {}", node10, 35f32, location.x);
658 assert_eq!(location.y, 35f32, "y of node {:?}. Expected {}. Actual {}", node10, 35f32, location.y);
659 let layout = taffy.layout(node11).unwrap();
660 let Layout { size, location, .. } = layout;
661 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node11, 0f32, size.width);
662 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node11, 0f32, size.height);
663 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node11, 20f32, location.x);
664 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node11, 20f32, location.y);
665 let layout = taffy.layout(node12).unwrap();
666 let Layout { size, location, .. } = layout;
667 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node12, 0f32, size.width);
668 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node12, 0f32, size.height);
669 assert_eq!(location.x, 235f32, "x of node {:?}. Expected {}. Actual {}", node12, 235f32, location.x);
670 assert_eq!(location.y, 235f32, "y of node {:?}. Expected {}. Actual {}", node12, 235f32, location.y);
671 let layout = taffy.layout(node13).unwrap();
672 let Layout { size, location, .. } = layout;
673 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node13, 0f32, size.width);
674 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node13, 0f32, size.height);
675 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node13, 20f32, location.x);
676 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node13, 20f32, location.y);
677 let layout = taffy.layout(node14).unwrap();
678 let Layout { size, location, .. } = layout;
679 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node14, 0f32, size.width);
680 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node14, 0f32, size.height);
681 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node14, 50f32, location.x);
682 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node14, 50f32, location.y);
683 let layout = taffy.layout(node15).unwrap();
684 let Layout { size, location, .. } = layout;
685 assert_eq!(size.width, 215f32, "width of node {:?}. Expected {}. Actual {}", node15, 215f32, size.width);
686 assert_eq!(size.height, 215f32, "height of node {:?}. Expected {}. Actual {}", node15, 215f32, size.height);
687 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node15, 20f32, location.x);
688 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node15, 20f32, location.y);
689 let layout = taffy.layout(node2).unwrap();
690 let Layout { size, location, .. } = layout;
691 assert_eq!(size.width, 270f32, "width of node {:?}. Expected {}. Actual {}", node2, 270f32, size.width);
692 assert_eq!(size.height, 270f32, "height of node {:?}. Expected {}. Actual {}", node2, 270f32, size.height);
693 assert_eq!(location.x, 540f32, "x of node {:?}. Expected {}. Actual {}", node2, 540f32, location.x);
694 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
695 let layout = taffy.layout(node20).unwrap();
696 let Layout { size, location, .. } = layout;
697 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node20, 50f32, size.width);
698 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20, 10f32, size.height);
699 assert_eq!(location.x, 35f32, "x of node {:?}. Expected {}. Actual {}", node20, 35f32, location.x);
700 assert_eq!(location.y, 35f32, "y of node {:?}. Expected {}. Actual {}", node20, 35f32, location.y);
701 let layout = taffy.layout(node21).unwrap();
702 let Layout { size, location, .. } = layout;
703 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node21, 0f32, size.width);
704 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node21, 0f32, size.height);
705 assert_eq!(location.x, 35f32, "x of node {:?}. Expected {}. Actual {}", node21, 35f32, location.x);
706 assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node21, 45f32, location.y);
707}