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