1#[test]
2fn grid_justify_self_sized_all() {
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 justify_self: Some(taffy::style::JustifySelf::Start),
10 size: taffy::geometry::Size {
11 width: taffy::style::Dimension::Points(20f32),
12 height: taffy::style::Dimension::Points(20f32),
13 },
14 ..Default::default()
15 })
16 .unwrap();
17 let node1 = taffy
18 .new_leaf(taffy::style::Style {
19 justify_self: Some(taffy::style::JustifySelf::Start),
20 size: taffy::geometry::Size {
21 width: taffy::style::Dimension::Points(60f32),
22 height: taffy::style::Dimension::Points(60f32),
23 },
24 ..Default::default()
25 })
26 .unwrap();
27 let node2 = taffy
28 .new_leaf(taffy::style::Style {
29 justify_self: Some(taffy::style::JustifySelf::End),
30 size: taffy::geometry::Size {
31 width: taffy::style::Dimension::Points(20f32),
32 height: taffy::style::Dimension::Points(20f32),
33 },
34 ..Default::default()
35 })
36 .unwrap();
37 let node3 = taffy
38 .new_leaf(taffy::style::Style {
39 justify_self: Some(taffy::style::JustifySelf::End),
40 size: taffy::geometry::Size {
41 width: taffy::style::Dimension::Points(60f32),
42 height: taffy::style::Dimension::Points(60f32),
43 },
44 ..Default::default()
45 })
46 .unwrap();
47 let node4 = taffy
48 .new_leaf(taffy::style::Style {
49 justify_self: Some(taffy::style::JustifySelf::Center),
50 size: taffy::geometry::Size {
51 width: taffy::style::Dimension::Points(20f32),
52 height: taffy::style::Dimension::Points(20f32),
53 },
54 ..Default::default()
55 })
56 .unwrap();
57 let node5 = taffy
58 .new_leaf(taffy::style::Style {
59 justify_self: Some(taffy::style::JustifySelf::Center),
60 size: taffy::geometry::Size {
61 width: taffy::style::Dimension::Points(60f32),
62 height: taffy::style::Dimension::Points(60f32),
63 },
64 ..Default::default()
65 })
66 .unwrap();
67 let node6 = taffy
68 .new_leaf(taffy::style::Style {
69 justify_self: Some(taffy::style::JustifySelf::Stretch),
70 size: taffy::geometry::Size {
71 width: taffy::style::Dimension::Points(20f32),
72 height: taffy::style::Dimension::Points(20f32),
73 },
74 ..Default::default()
75 })
76 .unwrap();
77 let node7 = taffy
78 .new_leaf(taffy::style::Style {
79 justify_self: Some(taffy::style::JustifySelf::Stretch),
80 size: taffy::geometry::Size {
81 width: taffy::style::Dimension::Points(60f32),
82 height: taffy::style::Dimension::Points(60f32),
83 },
84 ..Default::default()
85 })
86 .unwrap();
87 let node = taffy
88 .new_with_children(
89 taffy::style::Style {
90 display: taffy::style::Display::Grid,
91 grid_template_rows: vec![points(40f32), points(40f32), points(40f32)],
92 grid_template_columns: vec![points(40f32), points(40f32), points(40f32)],
93 size: taffy::geometry::Size {
94 width: taffy::style::Dimension::Points(120f32),
95 height: taffy::style::Dimension::Points(120f32),
96 },
97 ..Default::default()
98 },
99 &[node0, node1, node2, node3, node4, node5, node6, node7],
100 )
101 .unwrap();
102 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
103 println!("\nComputed tree:");
104 taffy::debug::print_tree(&taffy, node);
105 println!();
106 let Layout { size, location, .. } = taffy.layout(node).unwrap();
107 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 120f32, size.width);
108 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 120f32, size.height);
109 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
110 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
111 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
112 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
113 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
114 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
115 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
116 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
117 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, size.width);
118 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, size.height);
119 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.x);
120 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
121 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
122 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.width);
123 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.height);
124 assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 100f32, location.x);
125 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
126 let Layout { size, location, .. } = taffy.layout(node3).unwrap();
127 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 60f32, size.width);
128 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 60f32, size.height);
129 assert_eq!(location.x, -20f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), -20f32, location.x);
130 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 40f32, location.y);
131 let Layout { size, location, .. } = taffy.layout(node4).unwrap();
132 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4.data(), 20f32, size.width);
133 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4.data(), 20f32, size.height);
134 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node4.data(), 50f32, location.x);
135 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4.data(), 40f32, location.y);
136 let Layout { size, location, .. } = taffy.layout(node5).unwrap();
137 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node5.data(), 60f32, size.width);
138 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node5.data(), 60f32, size.height);
139 assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node5.data(), 70f32, location.x);
140 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5.data(), 40f32, location.y);
141 let Layout { size, location, .. } = taffy.layout(node6).unwrap();
142 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6.data(), 20f32, size.width);
143 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6.data(), 20f32, size.height);
144 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6.data(), 0f32, location.x);
145 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6.data(), 80f32, location.y);
146 let Layout { size, location, .. } = taffy.layout(node7).unwrap();
147 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node7.data(), 60f32, size.width);
148 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node7.data(), 60f32, size.height);
149 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7.data(), 40f32, location.x);
150 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7.data(), 80f32, location.y);
151}