1#[test]
2fn margin_auto_mutiple_children_row() {
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: taffy::style::LengthPercentageAuto::Auto,
16 top: zero(),
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: taffy::style::LengthPercentageAuto::Auto,
31 top: zero(),
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 align_items: Some(taffy::style::AlignItems::Center),
50 size: taffy::geometry::Size {
51 width: taffy::style::Dimension::Points(200f32),
52 height: taffy::style::Dimension::Points(200f32),
53 },
54 ..Default::default()
55 },
56 &[node0, node1, node2],
57 )
58 .unwrap();
59 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
60 println!("\nComputed tree:");
61 taffy::debug::print_tree(&taffy, node);
62 println!();
63 let Layout { size, location, .. } = taffy.layout(node).unwrap();
64 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
65 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.height);
66 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
67 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
68 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
69 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
70 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
71 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
72 assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 75f32, location.y);
73 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
74 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
75 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.height);
76 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 75f32, location.x);
77 assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 75f32, location.y);
78 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
79 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.width);
80 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.height);
81 assert_eq!(location.x, 150f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 150f32, location.x);
82 assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 75f32, location.y);
83}