1#[test]
2fn margin_auto_mutiple_children_column() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Points(50f32),
11 height: taffy::style::Dimension::Points(50f32),
12 },
13 margin: taffy::geometry::Rect {
14 left: zero(),
15 right: zero(),
16 top: taffy::style::LengthPercentageAuto::Auto,
17 bottom: zero(),
18 },
19 ..Default::default()
20 })
21 .unwrap();
22 let node1 = taffy
23 .new_leaf(taffy::style::Style {
24 size: taffy::geometry::Size {
25 width: taffy::style::Dimension::Points(50f32),
26 height: taffy::style::Dimension::Points(50f32),
27 },
28 margin: taffy::geometry::Rect {
29 left: zero(),
30 right: zero(),
31 top: taffy::style::LengthPercentageAuto::Auto,
32 bottom: zero(),
33 },
34 ..Default::default()
35 })
36 .unwrap();
37 let node2 = taffy
38 .new_leaf(taffy::style::Style {
39 size: taffy::geometry::Size {
40 width: taffy::style::Dimension::Points(50f32),
41 height: taffy::style::Dimension::Points(50f32),
42 },
43 ..Default::default()
44 })
45 .unwrap();
46 let node = taffy
47 .new_with_children(
48 taffy::style::Style {
49 flex_direction: taffy::style::FlexDirection::Column,
50 align_items: Some(taffy::style::AlignItems::Center),
51 size: taffy::geometry::Size {
52 width: taffy::style::Dimension::Points(200f32),
53 height: taffy::style::Dimension::Points(200f32),
54 },
55 ..Default::default()
56 },
57 &[node0, node1, node2],
58 )
59 .unwrap();
60 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
61 println!("\nComputed tree:");
62 taffy::debug::print_tree(&taffy, node);
63 println!();
64 let Layout { size, location, .. } = taffy.layout(node).unwrap();
65 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
66 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.height);
67 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
68 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
69 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
70 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
71 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
72 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 75f32, location.x);
73 assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 25f32, location.y);
74 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
75 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
76 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.height);
77 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 75f32, location.x);
78 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 100f32, location.y);
79 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
80 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.width);
81 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.height);
82 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 75f32, location.x);
83 assert_eq!(location.y, 150f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 150f32, location.y);
84}