⎇ b746ac4f346dde8a2b6f85d3a428c02a2342f099
tests/generated/flex/wrap_reverse_row_align_content_space_around.rs
History
Who touched what
raw
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn wrap_reverse_row_align_content_space_around__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, tree::Layout, TaffyTree};
6 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(30f32),
11 height: taffy::style::Dimension::Length(10f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node1 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::Length(30f32),
20 height: taffy::style::Dimension::Length(20f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node2 = taffy
26 .new_leaf(taffy::style::Style {
27 size: taffy::geometry::Size {
28 width: taffy::style::Dimension::Length(30f32),
29 height: taffy::style::Dimension::Length(30f32),
30 },
31 ..Default::default()
32 })
33 .unwrap();
34 let node3 = taffy
35 .new_leaf(taffy::style::Style {
36 size: taffy::geometry::Size {
37 width: taffy::style::Dimension::Length(30f32),
38 height: taffy::style::Dimension::Length(40f32),
39 },
40 ..Default::default()
41 })
42 .unwrap();
43 let node4 = taffy
44 .new_leaf(taffy::style::Style {
45 size: taffy::geometry::Size {
46 width: taffy::style::Dimension::Length(30f32),
47 height: taffy::style::Dimension::Length(50f32),
48 },
49 ..Default::default()
50 })
51 .unwrap();
52 let node = taffy
53 .new_with_children(
54 taffy::style::Style {
55 flex_wrap: taffy::style::FlexWrap::WrapReverse,
56 align_content: Some(taffy::style::AlignContent::SpaceAround),
57 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
58 ..Default::default()
59 },
60 &[node0, node1, node2, node3, node4],
61 )
62 .unwrap();
63 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
64 println!("\nComputed tree:");
65 taffy.print_tree(node);
66 println!();
67 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
68 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
69 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
70 assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node, 80f32, size.height);
71 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
72 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
73 #[cfg(feature = "content_size")]
74 assert_eq!(
75 layout.scroll_width(),
76 0f32,
77 "scroll_width of node {:?}. Expected {}. Actual {}",
78 node,
79 0f32,
80 layout.scroll_width()
81 );
82 #[cfg(feature = "content_size")]
83 assert_eq!(
84 layout.scroll_height(),
85 0f32,
86 "scroll_height of node {:?}. Expected {}. Actual {}",
87 node,
88 0f32,
89 layout.scroll_height()
90 );
91 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
92 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
93 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width);
94 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
95 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
96 assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node0, 70f32, location.y);
97 #[cfg(feature = "content_size")]
98 assert_eq!(
99 layout.scroll_width(),
100 0f32,
101 "scroll_width of node {:?}. Expected {}. Actual {}",
102 node0,
103 0f32,
104 layout.scroll_width()
105 );
106 #[cfg(feature = "content_size")]
107 assert_eq!(
108 layout.scroll_height(),
109 0f32,
110 "scroll_height of node {:?}. Expected {}. Actual {}",
111 node0,
112 0f32,
113 layout.scroll_height()
114 );
115 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
116 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
117 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width);
118 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
119 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
120 assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node1, 60f32, location.y);
121 #[cfg(feature = "content_size")]
122 assert_eq!(
123 layout.scroll_width(),
124 0f32,
125 "scroll_width of node {:?}. Expected {}. Actual {}",
126 node1,
127 0f32,
128 layout.scroll_width()
129 );
130 #[cfg(feature = "content_size")]
131 assert_eq!(
132 layout.scroll_height(),
133 0f32,
134 "scroll_height of node {:?}. Expected {}. Actual {}",
135 node1,
136 0f32,
137 layout.scroll_height()
138 );
139 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
140 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
141 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node2, 30f32, size.width);
142 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
143 assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
144 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
145 #[cfg(feature = "content_size")]
146 assert_eq!(
147 layout.scroll_width(),
148 0f32,
149 "scroll_width of node {:?}. Expected {}. Actual {}",
150 node2,
151 0f32,
152 layout.scroll_width()
153 );
154 #[cfg(feature = "content_size")]
155 assert_eq!(
156 layout.scroll_height(),
157 0f32,
158 "scroll_height of node {:?}. Expected {}. Actual {}",
159 node2,
160 0f32,
161 layout.scroll_height()
162 );
163 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
164 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
165 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node3, 30f32, size.width);
166 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
167 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
168 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node3, 10f32, location.y);
169 #[cfg(feature = "content_size")]
170 assert_eq!(
171 layout.scroll_width(),
172 0f32,
173 "scroll_width of node {:?}. Expected {}. Actual {}",
174 node3,
175 0f32,
176 layout.scroll_width()
177 );
178 #[cfg(feature = "content_size")]
179 assert_eq!(
180 layout.scroll_height(),
181 0f32,
182 "scroll_height of node {:?}. Expected {}. Actual {}",
183 node3,
184 0f32,
185 layout.scroll_height()
186 );
187 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
188 let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
189 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node4, 30f32, size.width);
190 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node4, 50f32, size.height);
191 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4, 30f32, location.x);
192 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
193 #[cfg(feature = "content_size")]
194 assert_eq!(
195 layout.scroll_width(),
196 0f32,
197 "scroll_width of node {:?}. Expected {}. Actual {}",
198 node4,
199 0f32,
200 layout.scroll_width()
201 );
202 #[cfg(feature = "content_size")]
203 assert_eq!(
204 layout.scroll_height(),
205 0f32,
206 "scroll_height of node {:?}. Expected {}. Actual {}",
207 node4,
208 0f32,
209 layout.scroll_height()
210 );
211}
212
213#[test]
214#[allow(non_snake_case)]
215fn wrap_reverse_row_align_content_space_around__content_box() {
216 #[allow(unused_imports)]
217 use taffy::{prelude::*, tree::Layout, TaffyTree};
218 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
219 let node0 = taffy
220 .new_leaf(taffy::style::Style {
221 box_sizing: taffy::style::BoxSizing::ContentBox,
222 size: taffy::geometry::Size {
223 width: taffy::style::Dimension::Length(30f32),
224 height: taffy::style::Dimension::Length(10f32),
225 },
226 ..Default::default()
227 })
228 .unwrap();
229 let node1 = taffy
230 .new_leaf(taffy::style::Style {
231 box_sizing: taffy::style::BoxSizing::ContentBox,
232 size: taffy::geometry::Size {
233 width: taffy::style::Dimension::Length(30f32),
234 height: taffy::style::Dimension::Length(20f32),
235 },
236 ..Default::default()
237 })
238 .unwrap();
239 let node2 = taffy
240 .new_leaf(taffy::style::Style {
241 box_sizing: taffy::style::BoxSizing::ContentBox,
242 size: taffy::geometry::Size {
243 width: taffy::style::Dimension::Length(30f32),
244 height: taffy::style::Dimension::Length(30f32),
245 },
246 ..Default::default()
247 })
248 .unwrap();
249 let node3 = taffy
250 .new_leaf(taffy::style::Style {
251 box_sizing: taffy::style::BoxSizing::ContentBox,
252 size: taffy::geometry::Size {
253 width: taffy::style::Dimension::Length(30f32),
254 height: taffy::style::Dimension::Length(40f32),
255 },
256 ..Default::default()
257 })
258 .unwrap();
259 let node4 = taffy
260 .new_leaf(taffy::style::Style {
261 box_sizing: taffy::style::BoxSizing::ContentBox,
262 size: taffy::geometry::Size {
263 width: taffy::style::Dimension::Length(30f32),
264 height: taffy::style::Dimension::Length(50f32),
265 },
266 ..Default::default()
267 })
268 .unwrap();
269 let node = taffy
270 .new_with_children(
271 taffy::style::Style {
272 box_sizing: taffy::style::BoxSizing::ContentBox,
273 flex_wrap: taffy::style::FlexWrap::WrapReverse,
274 align_content: Some(taffy::style::AlignContent::SpaceAround),
275 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
276 ..Default::default()
277 },
278 &[node0, node1, node2, node3, node4],
279 )
280 .unwrap();
281 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
282 println!("\nComputed tree:");
283 taffy.print_tree(node);
284 println!();
285 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
286 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
287 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
288 assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node, 80f32, size.height);
289 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
290 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
291 #[cfg(feature = "content_size")]
292 assert_eq!(
293 layout.scroll_width(),
294 0f32,
295 "scroll_width of node {:?}. Expected {}. Actual {}",
296 node,
297 0f32,
298 layout.scroll_width()
299 );
300 #[cfg(feature = "content_size")]
301 assert_eq!(
302 layout.scroll_height(),
303 0f32,
304 "scroll_height of node {:?}. Expected {}. Actual {}",
305 node,
306 0f32,
307 layout.scroll_height()
308 );
309 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
310 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
311 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width);
312 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
313 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
314 assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node0, 70f32, location.y);
315 #[cfg(feature = "content_size")]
316 assert_eq!(
317 layout.scroll_width(),
318 0f32,
319 "scroll_width of node {:?}. Expected {}. Actual {}",
320 node0,
321 0f32,
322 layout.scroll_width()
323 );
324 #[cfg(feature = "content_size")]
325 assert_eq!(
326 layout.scroll_height(),
327 0f32,
328 "scroll_height of node {:?}. Expected {}. Actual {}",
329 node0,
330 0f32,
331 layout.scroll_height()
332 );
333 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
334 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
335 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width);
336 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
337 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
338 assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node1, 60f32, location.y);
339 #[cfg(feature = "content_size")]
340 assert_eq!(
341 layout.scroll_width(),
342 0f32,
343 "scroll_width of node {:?}. Expected {}. Actual {}",
344 node1,
345 0f32,
346 layout.scroll_width()
347 );
348 #[cfg(feature = "content_size")]
349 assert_eq!(
350 layout.scroll_height(),
351 0f32,
352 "scroll_height of node {:?}. Expected {}. Actual {}",
353 node1,
354 0f32,
355 layout.scroll_height()
356 );
357 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
358 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
359 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node2, 30f32, size.width);
360 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
361 assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
362 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
363 #[cfg(feature = "content_size")]
364 assert_eq!(
365 layout.scroll_width(),
366 0f32,
367 "scroll_width of node {:?}. Expected {}. Actual {}",
368 node2,
369 0f32,
370 layout.scroll_width()
371 );
372 #[cfg(feature = "content_size")]
373 assert_eq!(
374 layout.scroll_height(),
375 0f32,
376 "scroll_height of node {:?}. Expected {}. Actual {}",
377 node2,
378 0f32,
379 layout.scroll_height()
380 );
381 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
382 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
383 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node3, 30f32, size.width);
384 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
385 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
386 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node3, 10f32, location.y);
387 #[cfg(feature = "content_size")]
388 assert_eq!(
389 layout.scroll_width(),
390 0f32,
391 "scroll_width of node {:?}. Expected {}. Actual {}",
392 node3,
393 0f32,
394 layout.scroll_width()
395 );
396 #[cfg(feature = "content_size")]
397 assert_eq!(
398 layout.scroll_height(),
399 0f32,
400 "scroll_height of node {:?}. Expected {}. Actual {}",
401 node3,
402 0f32,
403 layout.scroll_height()
404 );
405 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
406 let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
407 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node4, 30f32, size.width);
408 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node4, 50f32, size.height);
409 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4, 30f32, location.x);
410 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
411 #[cfg(feature = "content_size")]
412 assert_eq!(
413 layout.scroll_width(),
414 0f32,
415 "scroll_width of node {:?}. Expected {}. Actual {}",
416 node4,
417 0f32,
418 layout.scroll_width()
419 );
420 #[cfg(feature = "content_size")]
421 assert_eq!(
422 layout.scroll_height(),
423 0f32,
424 "scroll_height of node {:?}. Expected {}. Actual {}",
425 node4,
426 0f32,
427 layout.scroll_height()
428 );
429}