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