⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227
tests/generated/flex/align_baseline_multiline_row_and_column.rs
History
Who touched what
raw
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn align_baseline_multiline_row_and_column__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 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(50f32),
11 height: taffy::style::Dimension::Length(50f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node10 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::Length(50f32),
20 height: taffy::style::Dimension::Length(10f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node1 = taffy
26 .new_with_children(
27 taffy::style::Style {
28 flex_direction: taffy::style::FlexDirection::Column,
29 size: taffy::geometry::Size {
30 width: taffy::style::Dimension::Length(50f32),
31 height: taffy::style::Dimension::Length(50f32),
32 },
33 ..Default::default()
34 },
35 &[node10],
36 )
37 .unwrap();
38 let node20 = taffy
39 .new_leaf(taffy::style::Style {
40 size: taffy::geometry::Size {
41 width: taffy::style::Dimension::Length(50f32),
42 height: taffy::style::Dimension::Length(10f32),
43 },
44 ..Default::default()
45 })
46 .unwrap();
47 let node2 = taffy
48 .new_with_children(
49 taffy::style::Style {
50 flex_direction: taffy::style::FlexDirection::Column,
51 size: taffy::geometry::Size {
52 width: taffy::style::Dimension::Length(50f32),
53 height: taffy::style::Dimension::Length(20f32),
54 },
55 ..Default::default()
56 },
57 &[node20],
58 )
59 .unwrap();
60 let node3 = taffy
61 .new_leaf(taffy::style::Style {
62 size: taffy::geometry::Size {
63 width: taffy::style::Dimension::Length(50f32),
64 height: taffy::style::Dimension::Length(20f32),
65 },
66 ..Default::default()
67 })
68 .unwrap();
69 let node = taffy
70 .new_with_children(
71 taffy::style::Style {
72 flex_wrap: taffy::style::FlexWrap::Wrap,
73 align_items: Some(taffy::style::AlignItems::Baseline),
74 size: taffy::geometry::Size {
75 width: taffy::style::Dimension::Length(100f32),
76 height: taffy::style::Dimension::Length(100f32),
77 },
78 ..Default::default()
79 },
80 &[node0, node1, node2, node3],
81 )
82 .unwrap();
83 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
84 println!("\nComputed tree:");
85 taffy.print_tree(node);
86 println!();
87 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
88 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
89 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
90 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
91 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
92 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
93 #[cfg(feature = "content_size")]
94 assert_eq!(
95 layout.scroll_width(),
96 0f32,
97 "scroll_width of node {:?}. Expected {}. Actual {}",
98 node,
99 0f32,
100 layout.scroll_width()
101 );
102 #[cfg(feature = "content_size")]
103 assert_eq!(
104 layout.scroll_height(),
105 20f32,
106 "scroll_height of node {:?}. Expected {}. Actual {}",
107 node,
108 20f32,
109 layout.scroll_height()
110 );
111 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
112 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
113 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
114 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
115 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
116 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
117 #[cfg(feature = "content_size")]
118 assert_eq!(
119 layout.scroll_width(),
120 0f32,
121 "scroll_width of node {:?}. Expected {}. Actual {}",
122 node0,
123 0f32,
124 layout.scroll_width()
125 );
126 #[cfg(feature = "content_size")]
127 assert_eq!(
128 layout.scroll_height(),
129 0f32,
130 "scroll_height of node {:?}. Expected {}. Actual {}",
131 node0,
132 0f32,
133 layout.scroll_height()
134 );
135 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
136 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
137 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
138 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
139 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
140 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
141 #[cfg(feature = "content_size")]
142 assert_eq!(
143 layout.scroll_width(),
144 0f32,
145 "scroll_width of node {:?}. Expected {}. Actual {}",
146 node1,
147 0f32,
148 layout.scroll_width()
149 );
150 #[cfg(feature = "content_size")]
151 assert_eq!(
152 layout.scroll_height(),
153 0f32,
154 "scroll_height of node {:?}. Expected {}. Actual {}",
155 node1,
156 0f32,
157 layout.scroll_height()
158 );
159 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
160 let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
161 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
162 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
163 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
164 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
165 #[cfg(feature = "content_size")]
166 assert_eq!(
167 layout.scroll_width(),
168 0f32,
169 "scroll_width of node {:?}. Expected {}. Actual {}",
170 node10,
171 0f32,
172 layout.scroll_width()
173 );
174 #[cfg(feature = "content_size")]
175 assert_eq!(
176 layout.scroll_height(),
177 0f32,
178 "scroll_height of node {:?}. Expected {}. Actual {}",
179 node10,
180 0f32,
181 layout.scroll_height()
182 );
183 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
184 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
185 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
186 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
187 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
188 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node2, 100f32, location.y);
189 #[cfg(feature = "content_size")]
190 assert_eq!(
191 layout.scroll_width(),
192 0f32,
193 "scroll_width of node {:?}. Expected {}. Actual {}",
194 node2,
195 0f32,
196 layout.scroll_width()
197 );
198 #[cfg(feature = "content_size")]
199 assert_eq!(
200 layout.scroll_height(),
201 0f32,
202 "scroll_height of node {:?}. Expected {}. Actual {}",
203 node2,
204 0f32,
205 layout.scroll_height()
206 );
207 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
208 let layout @ Layout { size, location, .. } = taffy.layout(node20).unwrap();
209 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node20, 50f32, size.width);
210 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20, 10f32, size.height);
211 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node20, 0f32, location.x);
212 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20, 0f32, location.y);
213 #[cfg(feature = "content_size")]
214 assert_eq!(
215 layout.scroll_width(),
216 0f32,
217 "scroll_width of node {:?}. Expected {}. Actual {}",
218 node20,
219 0f32,
220 layout.scroll_width()
221 );
222 #[cfg(feature = "content_size")]
223 assert_eq!(
224 layout.scroll_height(),
225 0f32,
226 "scroll_height of node {:?}. Expected {}. Actual {}",
227 node20,
228 0f32,
229 layout.scroll_height()
230 );
231 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
232 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
233 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
234 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
235 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
236 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node3, 90f32, location.y);
237 #[cfg(feature = "content_size")]
238 assert_eq!(
239 layout.scroll_width(),
240 0f32,
241 "scroll_width of node {:?}. Expected {}. Actual {}",
242 node3,
243 0f32,
244 layout.scroll_width()
245 );
246 #[cfg(feature = "content_size")]
247 assert_eq!(
248 layout.scroll_height(),
249 0f32,
250 "scroll_height of node {:?}. Expected {}. Actual {}",
251 node3,
252 0f32,
253 layout.scroll_height()
254 );
255}
256
257#[test]
258#[allow(non_snake_case)]
259fn align_baseline_multiline_row_and_column__content_box() {
260 #[allow(unused_imports)]
261 use taffy::{prelude::*, tree::Layout, TaffyTree};
262 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
263 let node0 = taffy
264 .new_leaf(taffy::style::Style {
265 box_sizing: taffy::style::BoxSizing::ContentBox,
266 size: taffy::geometry::Size {
267 width: taffy::style::Dimension::Length(50f32),
268 height: taffy::style::Dimension::Length(50f32),
269 },
270 ..Default::default()
271 })
272 .unwrap();
273 let node10 = taffy
274 .new_leaf(taffy::style::Style {
275 box_sizing: taffy::style::BoxSizing::ContentBox,
276 size: taffy::geometry::Size {
277 width: taffy::style::Dimension::Length(50f32),
278 height: taffy::style::Dimension::Length(10f32),
279 },
280 ..Default::default()
281 })
282 .unwrap();
283 let node1 = taffy
284 .new_with_children(
285 taffy::style::Style {
286 box_sizing: taffy::style::BoxSizing::ContentBox,
287 flex_direction: taffy::style::FlexDirection::Column,
288 size: taffy::geometry::Size {
289 width: taffy::style::Dimension::Length(50f32),
290 height: taffy::style::Dimension::Length(50f32),
291 },
292 ..Default::default()
293 },
294 &[node10],
295 )
296 .unwrap();
297 let node20 = taffy
298 .new_leaf(taffy::style::Style {
299 box_sizing: taffy::style::BoxSizing::ContentBox,
300 size: taffy::geometry::Size {
301 width: taffy::style::Dimension::Length(50f32),
302 height: taffy::style::Dimension::Length(10f32),
303 },
304 ..Default::default()
305 })
306 .unwrap();
307 let node2 = taffy
308 .new_with_children(
309 taffy::style::Style {
310 box_sizing: taffy::style::BoxSizing::ContentBox,
311 flex_direction: taffy::style::FlexDirection::Column,
312 size: taffy::geometry::Size {
313 width: taffy::style::Dimension::Length(50f32),
314 height: taffy::style::Dimension::Length(20f32),
315 },
316 ..Default::default()
317 },
318 &[node20],
319 )
320 .unwrap();
321 let node3 = taffy
322 .new_leaf(taffy::style::Style {
323 box_sizing: taffy::style::BoxSizing::ContentBox,
324 size: taffy::geometry::Size {
325 width: taffy::style::Dimension::Length(50f32),
326 height: taffy::style::Dimension::Length(20f32),
327 },
328 ..Default::default()
329 })
330 .unwrap();
331 let node = taffy
332 .new_with_children(
333 taffy::style::Style {
334 box_sizing: taffy::style::BoxSizing::ContentBox,
335 flex_wrap: taffy::style::FlexWrap::Wrap,
336 align_items: Some(taffy::style::AlignItems::Baseline),
337 size: taffy::geometry::Size {
338 width: taffy::style::Dimension::Length(100f32),
339 height: taffy::style::Dimension::Length(100f32),
340 },
341 ..Default::default()
342 },
343 &[node0, node1, node2, node3],
344 )
345 .unwrap();
346 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
347 println!("\nComputed tree:");
348 taffy.print_tree(node);
349 println!();
350 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
351 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
352 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
353 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
354 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
355 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
356 #[cfg(feature = "content_size")]
357 assert_eq!(
358 layout.scroll_width(),
359 0f32,
360 "scroll_width of node {:?}. Expected {}. Actual {}",
361 node,
362 0f32,
363 layout.scroll_width()
364 );
365 #[cfg(feature = "content_size")]
366 assert_eq!(
367 layout.scroll_height(),
368 20f32,
369 "scroll_height of node {:?}. Expected {}. Actual {}",
370 node,
371 20f32,
372 layout.scroll_height()
373 );
374 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
375 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
376 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
377 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
378 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
379 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
380 #[cfg(feature = "content_size")]
381 assert_eq!(
382 layout.scroll_width(),
383 0f32,
384 "scroll_width of node {:?}. Expected {}. Actual {}",
385 node0,
386 0f32,
387 layout.scroll_width()
388 );
389 #[cfg(feature = "content_size")]
390 assert_eq!(
391 layout.scroll_height(),
392 0f32,
393 "scroll_height of node {:?}. Expected {}. Actual {}",
394 node0,
395 0f32,
396 layout.scroll_height()
397 );
398 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
399 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
400 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
401 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
402 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
403 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
404 #[cfg(feature = "content_size")]
405 assert_eq!(
406 layout.scroll_width(),
407 0f32,
408 "scroll_width of node {:?}. Expected {}. Actual {}",
409 node1,
410 0f32,
411 layout.scroll_width()
412 );
413 #[cfg(feature = "content_size")]
414 assert_eq!(
415 layout.scroll_height(),
416 0f32,
417 "scroll_height of node {:?}. Expected {}. Actual {}",
418 node1,
419 0f32,
420 layout.scroll_height()
421 );
422 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
423 let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
424 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
425 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
426 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
427 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
428 #[cfg(feature = "content_size")]
429 assert_eq!(
430 layout.scroll_width(),
431 0f32,
432 "scroll_width of node {:?}. Expected {}. Actual {}",
433 node10,
434 0f32,
435 layout.scroll_width()
436 );
437 #[cfg(feature = "content_size")]
438 assert_eq!(
439 layout.scroll_height(),
440 0f32,
441 "scroll_height of node {:?}. Expected {}. Actual {}",
442 node10,
443 0f32,
444 layout.scroll_height()
445 );
446 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
447 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
448 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
449 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
450 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
451 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node2, 100f32, location.y);
452 #[cfg(feature = "content_size")]
453 assert_eq!(
454 layout.scroll_width(),
455 0f32,
456 "scroll_width of node {:?}. Expected {}. Actual {}",
457 node2,
458 0f32,
459 layout.scroll_width()
460 );
461 #[cfg(feature = "content_size")]
462 assert_eq!(
463 layout.scroll_height(),
464 0f32,
465 "scroll_height of node {:?}. Expected {}. Actual {}",
466 node2,
467 0f32,
468 layout.scroll_height()
469 );
470 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
471 let layout @ Layout { size, location, .. } = taffy.layout(node20).unwrap();
472 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node20, 50f32, size.width);
473 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20, 10f32, size.height);
474 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node20, 0f32, location.x);
475 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20, 0f32, location.y);
476 #[cfg(feature = "content_size")]
477 assert_eq!(
478 layout.scroll_width(),
479 0f32,
480 "scroll_width of node {:?}. Expected {}. Actual {}",
481 node20,
482 0f32,
483 layout.scroll_width()
484 );
485 #[cfg(feature = "content_size")]
486 assert_eq!(
487 layout.scroll_height(),
488 0f32,
489 "scroll_height of node {:?}. Expected {}. Actual {}",
490 node20,
491 0f32,
492 layout.scroll_height()
493 );
494 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
495 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
496 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
497 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
498 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
499 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node3, 90f32, location.y);
500 #[cfg(feature = "content_size")]
501 assert_eq!(
502 layout.scroll_width(),
503 0f32,
504 "scroll_width of node {:?}. Expected {}. Actual {}",
505 node3,
506 0f32,
507 layout.scroll_width()
508 );
509 #[cfg(feature = "content_size")]
510 assert_eq!(
511 layout.scroll_height(),
512 0f32,
513 "scroll_height of node {:?}. Expected {}. Actual {}",
514 node3,
515 0f32,
516 layout.scroll_height()
517 );
518}