1#[test]
2fn align_content_stretch_column() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::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::Points(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::Points(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::Points(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::Points(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::Points(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::Points(100f32),
60 height: taffy::style::Dimension::Points(150f32),
61 },
62 ..Default::default()
63 },
64 &[node0, node1, node2, node3, node4],
65 )
66 .unwrap();
67 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
68 println!("\nComputed tree:");
69 taffy::debug::print_tree(&taffy, node);
70 println!();
71 let Layout { size, location, .. } = taffy.layout(node).unwrap();
72 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
73 assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 150f32, size.height);
74 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
75 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
76 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
77 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
78 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
79 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
80 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
81 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
82 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 50f32, size.width);
83 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 50f32, size.height);
84 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
85 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
86 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
87 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
88 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, size.height);
89 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
90 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, location.y);
91 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
92 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.width);
93 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.height);
94 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.x);
95 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, location.y);
96 let Layout { size, location, .. } = taffy.layout(node3).unwrap();
97 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.width);
98 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.height);
99 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 0f32, location.x);
100 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 100f32, location.y);
101 let Layout { size, location, .. } = taffy.layout(node4).unwrap();
102 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4.data(), 50f32, size.width);
103 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node4.data(), 50f32, size.height);
104 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node4.data(), 50f32, location.x);
105 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4.data(), 0f32, location.y);
106}