⎇ 5db1a9d99aeb127615eb3d3dae90d83e7d5eaace
tests/generated/grid/grid_margins_auto_margins.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn grid_margins_auto_margins__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8 let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
9 let node2 = taffy
10 .new_leaf(taffy::style::Style {
11 justify_self: Some(taffy::style::JustifySelf::Start),
12 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
13 margin: taffy::geometry::Rect {
14 left: taffy::style::LengthPercentageAuto::AUTO,
15 right: taffy::style::LengthPercentageAuto::AUTO,
16 top: length(0f32),
17 bottom: length(0f32),
18 },
19 ..Default::default()
20 })
21 .unwrap();
22 let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
23 let node4 = taffy
24 .new_leaf(taffy::style::Style {
25 align_self: Some(taffy::style::AlignSelf::Start),
26 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(20f32) },
27 margin: taffy::geometry::Rect {
28 left: length(0f32),
29 right: length(0f32),
30 top: taffy::style::LengthPercentageAuto::AUTO,
31 bottom: taffy::style::LengthPercentageAuto::AUTO,
32 },
33 ..Default::default()
34 })
35 .unwrap();
36 let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
37 let node6 = taffy
38 .new_leaf(taffy::style::Style {
39 align_self: Some(taffy::style::AlignSelf::Start),
40 justify_self: Some(taffy::style::JustifySelf::Start),
41 size: taffy::geometry::Size {
42 width: taffy::style::Dimension::from_length(20f32),
43 height: taffy::style::Dimension::from_length(20f32),
44 },
45 margin: taffy::geometry::Rect {
46 left: taffy::style::LengthPercentageAuto::AUTO,
47 right: taffy::style::LengthPercentageAuto::AUTO,
48 top: taffy::style::LengthPercentageAuto::AUTO,
49 bottom: taffy::style::LengthPercentageAuto::AUTO,
50 },
51 ..Default::default()
52 })
53 .unwrap();
54 let node7 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
55 let node8 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
56 let node = taffy
57 .new_with_children(
58 taffy::style::Style {
59 display: taffy::style::Display::Grid,
60 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
61 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
62 padding: taffy::geometry::Rect {
63 left: length(40f32),
64 right: length(20f32),
65 top: length(10f32),
66 bottom: length(30f32),
67 },
68 ..Default::default()
69 },
70 &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
71 )
72 .unwrap();
73 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
74 println!("\nComputed tree:");
75 taffy.print_tree(node);
76 println!();
77 let layout = taffy.layout(node).unwrap();
78 let Layout { size, location, .. } = layout;
79 assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node, 180f32, size.width);
80 assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node, 160f32, size.height);
81 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
82 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
83 let layout = taffy.layout(node0).unwrap();
84 let Layout { size, location, .. } = layout;
85 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
86 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
87 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node0, 40f32, location.x);
88 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
89 let layout = taffy.layout(node1).unwrap();
90 let Layout { size, location, .. } = layout;
91 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
92 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
93 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node1, 80f32, location.x);
94 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
95 let layout = taffy.layout(node2).unwrap();
96 let Layout { size, location, .. } = layout;
97 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
98 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
99 assert_eq!(location.x, 130f32, "x of node {:?}. Expected {}. Actual {}", node2, 130f32, location.x);
100 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node2, 10f32, location.y);
101 let layout = taffy.layout(node3).unwrap();
102 let Layout { size, location, .. } = layout;
103 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
104 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
105 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node3, 40f32, location.x);
106 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node3, 50f32, location.y);
107 let layout = taffy.layout(node4).unwrap();
108 let Layout { size, location, .. } = layout;
109 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node4, 40f32, size.width);
110 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4, 20f32, size.height);
111 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node4, 80f32, location.x);
112 assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node4, 60f32, location.y);
113 let layout = taffy.layout(node5).unwrap();
114 let Layout { size, location, .. } = layout;
115 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node5, 40f32, size.width);
116 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
117 assert_eq!(location.x, 120f32, "x of node {:?}. Expected {}. Actual {}", node5, 120f32, location.x);
118 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node5, 50f32, location.y);
119 let layout = taffy.layout(node6).unwrap();
120 let Layout { size, location, .. } = layout;
121 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6, 20f32, size.width);
122 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6, 20f32, size.height);
123 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node6, 50f32, location.x);
124 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node6, 100f32, location.y);
125 let layout = taffy.layout(node7).unwrap();
126 let Layout { size, location, .. } = layout;
127 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node7, 40f32, size.width);
128 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node7, 40f32, size.height);
129 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node7, 80f32, location.x);
130 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node7, 90f32, location.y);
131 let layout = taffy.layout(node8).unwrap();
132 let Layout { size, location, .. } = layout;
133 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node8, 40f32, size.width);
134 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node8, 40f32, size.height);
135 assert_eq!(location.x, 120f32, "x of node {:?}. Expected {}. Actual {}", node8, 120f32, location.x);
136 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node8, 90f32, location.y);
137}
138
139#[test]
140#[allow(non_snake_case)]
141fn grid_margins_auto_margins__content_box() {
142 #[allow(unused_imports)]
143 use taffy::{prelude::*, Layout};
144 let mut taffy = crate::new_test_tree();
145 let node0 = taffy
146 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
147 .unwrap();
148 let node1 = taffy
149 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
150 .unwrap();
151 let node2 = taffy
152 .new_leaf(taffy::style::Style {
153 box_sizing: taffy::style::BoxSizing::ContentBox,
154 justify_self: Some(taffy::style::JustifySelf::Start),
155 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
156 margin: taffy::geometry::Rect {
157 left: taffy::style::LengthPercentageAuto::AUTO,
158 right: taffy::style::LengthPercentageAuto::AUTO,
159 top: length(0f32),
160 bottom: length(0f32),
161 },
162 ..Default::default()
163 })
164 .unwrap();
165 let node3 = taffy
166 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
167 .unwrap();
168 let node4 = taffy
169 .new_leaf(taffy::style::Style {
170 box_sizing: taffy::style::BoxSizing::ContentBox,
171 align_self: Some(taffy::style::AlignSelf::Start),
172 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(20f32) },
173 margin: taffy::geometry::Rect {
174 left: length(0f32),
175 right: length(0f32),
176 top: taffy::style::LengthPercentageAuto::AUTO,
177 bottom: taffy::style::LengthPercentageAuto::AUTO,
178 },
179 ..Default::default()
180 })
181 .unwrap();
182 let node5 = taffy
183 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
184 .unwrap();
185 let node6 = taffy
186 .new_leaf(taffy::style::Style {
187 box_sizing: taffy::style::BoxSizing::ContentBox,
188 align_self: Some(taffy::style::AlignSelf::Start),
189 justify_self: Some(taffy::style::JustifySelf::Start),
190 size: taffy::geometry::Size {
191 width: taffy::style::Dimension::from_length(20f32),
192 height: taffy::style::Dimension::from_length(20f32),
193 },
194 margin: taffy::geometry::Rect {
195 left: taffy::style::LengthPercentageAuto::AUTO,
196 right: taffy::style::LengthPercentageAuto::AUTO,
197 top: taffy::style::LengthPercentageAuto::AUTO,
198 bottom: taffy::style::LengthPercentageAuto::AUTO,
199 },
200 ..Default::default()
201 })
202 .unwrap();
203 let node7 = taffy
204 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
205 .unwrap();
206 let node8 = taffy
207 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
208 .unwrap();
209 let node = taffy
210 .new_with_children(
211 taffy::style::Style {
212 display: taffy::style::Display::Grid,
213 box_sizing: taffy::style::BoxSizing::ContentBox,
214 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
215 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
216 padding: taffy::geometry::Rect {
217 left: length(40f32),
218 right: length(20f32),
219 top: length(10f32),
220 bottom: length(30f32),
221 },
222 ..Default::default()
223 },
224 &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
225 )
226 .unwrap();
227 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
228 println!("\nComputed tree:");
229 taffy.print_tree(node);
230 println!();
231 let layout = taffy.layout(node).unwrap();
232 let Layout { size, location, .. } = layout;
233 assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node, 180f32, size.width);
234 assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node, 160f32, size.height);
235 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
236 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
237 let layout = taffy.layout(node0).unwrap();
238 let Layout { size, location, .. } = layout;
239 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
240 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
241 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node0, 40f32, location.x);
242 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
243 let layout = taffy.layout(node1).unwrap();
244 let Layout { size, location, .. } = layout;
245 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
246 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
247 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node1, 80f32, location.x);
248 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
249 let layout = taffy.layout(node2).unwrap();
250 let Layout { size, location, .. } = layout;
251 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
252 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
253 assert_eq!(location.x, 130f32, "x of node {:?}. Expected {}. Actual {}", node2, 130f32, location.x);
254 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node2, 10f32, location.y);
255 let layout = taffy.layout(node3).unwrap();
256 let Layout { size, location, .. } = layout;
257 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
258 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
259 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node3, 40f32, location.x);
260 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node3, 50f32, location.y);
261 let layout = taffy.layout(node4).unwrap();
262 let Layout { size, location, .. } = layout;
263 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node4, 40f32, size.width);
264 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4, 20f32, size.height);
265 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node4, 80f32, location.x);
266 assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node4, 60f32, location.y);
267 let layout = taffy.layout(node5).unwrap();
268 let Layout { size, location, .. } = layout;
269 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node5, 40f32, size.width);
270 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
271 assert_eq!(location.x, 120f32, "x of node {:?}. Expected {}. Actual {}", node5, 120f32, location.x);
272 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node5, 50f32, location.y);
273 let layout = taffy.layout(node6).unwrap();
274 let Layout { size, location, .. } = layout;
275 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6, 20f32, size.width);
276 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6, 20f32, size.height);
277 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node6, 50f32, location.x);
278 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node6, 100f32, location.y);
279 let layout = taffy.layout(node7).unwrap();
280 let Layout { size, location, .. } = layout;
281 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node7, 40f32, size.width);
282 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node7, 40f32, size.height);
283 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node7, 80f32, location.x);
284 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node7, 90f32, location.y);
285 let layout = taffy.layout(node8).unwrap();
286 let Layout { size, location, .. } = layout;
287 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node8, 40f32, size.width);
288 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node8, 40f32, size.height);
289 assert_eq!(location.x, 120f32, "x of node {:?}. Expected {}. Actual {}", node8, 120f32, location.x);
290 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node8, 90f32, location.y);
291}