⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227
tests/generated/flex/gap_column_gap_wrap_align_flex_start.rs
History
Who touched what
raw
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn gap_column_gap_wrap_align_flex_start__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(20f32),
11 height: taffy::style::Dimension::Length(20f32),
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(20f32),
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(20f32),
29 height: taffy::style::Dimension::Length(20f32),
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(20f32),
38 height: taffy::style::Dimension::Length(20f32),
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(20f32),
47 height: taffy::style::Dimension::Length(20f32),
48 },
49 ..Default::default()
50 })
51 .unwrap();
52 let node5 = taffy
53 .new_leaf(taffy::style::Style {
54 size: taffy::geometry::Size {
55 width: taffy::style::Dimension::Length(20f32),
56 height: taffy::style::Dimension::Length(20f32),
57 },
58 ..Default::default()
59 })
60 .unwrap();
61 let node = taffy
62 .new_with_children(
63 taffy::style::Style {
64 flex_wrap: taffy::style::FlexWrap::Wrap,
65 align_content: Some(taffy::style::AlignContent::FlexStart),
66 gap: taffy::geometry::Size {
67 width: taffy::style::LengthPercentage::Length(10f32),
68 height: taffy::style::LengthPercentage::Length(20f32),
69 },
70 size: taffy::geometry::Size {
71 width: taffy::style::Dimension::Length(100f32),
72 height: taffy::style::Dimension::Length(100f32),
73 },
74 ..Default::default()
75 },
76 &[node0, node1, node2, node3, node4, node5],
77 )
78 .unwrap();
79 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
80 println!("\nComputed tree:");
81 taffy.print_tree(node);
82 println!();
83 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
84 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
85 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
86 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
87 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
88 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
89 #[cfg(feature = "content_size")]
90 assert_eq!(
91 layout.scroll_width(),
92 0f32,
93 "scroll_width of node {:?}. Expected {}. Actual {}",
94 node,
95 0f32,
96 layout.scroll_width()
97 );
98 #[cfg(feature = "content_size")]
99 assert_eq!(
100 layout.scroll_height(),
101 0f32,
102 "scroll_height of node {:?}. Expected {}. Actual {}",
103 node,
104 0f32,
105 layout.scroll_height()
106 );
107 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
108 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
109 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
110 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
111 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
112 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
113 #[cfg(feature = "content_size")]
114 assert_eq!(
115 layout.scroll_width(),
116 0f32,
117 "scroll_width of node {:?}. Expected {}. Actual {}",
118 node0,
119 0f32,
120 layout.scroll_width()
121 );
122 #[cfg(feature = "content_size")]
123 assert_eq!(
124 layout.scroll_height(),
125 0f32,
126 "scroll_height of node {:?}. Expected {}. Actual {}",
127 node0,
128 0f32,
129 layout.scroll_height()
130 );
131 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
132 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
133 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
134 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
135 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
136 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
137 #[cfg(feature = "content_size")]
138 assert_eq!(
139 layout.scroll_width(),
140 0f32,
141 "scroll_width of node {:?}. Expected {}. Actual {}",
142 node1,
143 0f32,
144 layout.scroll_width()
145 );
146 #[cfg(feature = "content_size")]
147 assert_eq!(
148 layout.scroll_height(),
149 0f32,
150 "scroll_height of node {:?}. Expected {}. Actual {}",
151 node1,
152 0f32,
153 layout.scroll_height()
154 );
155 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
156 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
157 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
158 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
159 assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
160 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
161 #[cfg(feature = "content_size")]
162 assert_eq!(
163 layout.scroll_width(),
164 0f32,
165 "scroll_width of node {:?}. Expected {}. Actual {}",
166 node2,
167 0f32,
168 layout.scroll_width()
169 );
170 #[cfg(feature = "content_size")]
171 assert_eq!(
172 layout.scroll_height(),
173 0f32,
174 "scroll_height of node {:?}. Expected {}. Actual {}",
175 node2,
176 0f32,
177 layout.scroll_height()
178 );
179 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
180 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
181 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
182 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
183 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
184 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
185 #[cfg(feature = "content_size")]
186 assert_eq!(
187 layout.scroll_width(),
188 0f32,
189 "scroll_width of node {:?}. Expected {}. Actual {}",
190 node3,
191 0f32,
192 layout.scroll_width()
193 );
194 #[cfg(feature = "content_size")]
195 assert_eq!(
196 layout.scroll_height(),
197 0f32,
198 "scroll_height of node {:?}. Expected {}. Actual {}",
199 node3,
200 0f32,
201 layout.scroll_height()
202 );
203 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
204 let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
205 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
206 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4, 20f32, size.height);
207 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4, 30f32, location.x);
208 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
209 #[cfg(feature = "content_size")]
210 assert_eq!(
211 layout.scroll_width(),
212 0f32,
213 "scroll_width of node {:?}. Expected {}. Actual {}",
214 node4,
215 0f32,
216 layout.scroll_width()
217 );
218 #[cfg(feature = "content_size")]
219 assert_eq!(
220 layout.scroll_height(),
221 0f32,
222 "scroll_height of node {:?}. Expected {}. Actual {}",
223 node4,
224 0f32,
225 layout.scroll_height()
226 );
227 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
228 let layout @ Layout { size, location, .. } = taffy.layout(node5).unwrap();
229 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
230 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node5, 20f32, size.height);
231 assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node5, 60f32, location.x);
232 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
233 #[cfg(feature = "content_size")]
234 assert_eq!(
235 layout.scroll_width(),
236 0f32,
237 "scroll_width of node {:?}. Expected {}. Actual {}",
238 node5,
239 0f32,
240 layout.scroll_width()
241 );
242 #[cfg(feature = "content_size")]
243 assert_eq!(
244 layout.scroll_height(),
245 0f32,
246 "scroll_height of node {:?}. Expected {}. Actual {}",
247 node5,
248 0f32,
249 layout.scroll_height()
250 );
251}
252
253#[test]
254#[allow(non_snake_case)]
255fn gap_column_gap_wrap_align_flex_start__content_box() {
256 #[allow(unused_imports)]
257 use taffy::{prelude::*, tree::Layout, TaffyTree};
258 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
259 let node0 = 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(20f32),
264 height: taffy::style::Dimension::Length(20f32),
265 },
266 ..Default::default()
267 })
268 .unwrap();
269 let node1 = taffy
270 .new_leaf(taffy::style::Style {
271 box_sizing: taffy::style::BoxSizing::ContentBox,
272 size: taffy::geometry::Size {
273 width: taffy::style::Dimension::Length(20f32),
274 height: taffy::style::Dimension::Length(20f32),
275 },
276 ..Default::default()
277 })
278 .unwrap();
279 let node2 = taffy
280 .new_leaf(taffy::style::Style {
281 box_sizing: taffy::style::BoxSizing::ContentBox,
282 size: taffy::geometry::Size {
283 width: taffy::style::Dimension::Length(20f32),
284 height: taffy::style::Dimension::Length(20f32),
285 },
286 ..Default::default()
287 })
288 .unwrap();
289 let node3 = taffy
290 .new_leaf(taffy::style::Style {
291 box_sizing: taffy::style::BoxSizing::ContentBox,
292 size: taffy::geometry::Size {
293 width: taffy::style::Dimension::Length(20f32),
294 height: taffy::style::Dimension::Length(20f32),
295 },
296 ..Default::default()
297 })
298 .unwrap();
299 let node4 = taffy
300 .new_leaf(taffy::style::Style {
301 box_sizing: taffy::style::BoxSizing::ContentBox,
302 size: taffy::geometry::Size {
303 width: taffy::style::Dimension::Length(20f32),
304 height: taffy::style::Dimension::Length(20f32),
305 },
306 ..Default::default()
307 })
308 .unwrap();
309 let node5 = taffy
310 .new_leaf(taffy::style::Style {
311 box_sizing: taffy::style::BoxSizing::ContentBox,
312 size: taffy::geometry::Size {
313 width: taffy::style::Dimension::Length(20f32),
314 height: taffy::style::Dimension::Length(20f32),
315 },
316 ..Default::default()
317 })
318 .unwrap();
319 let node = taffy
320 .new_with_children(
321 taffy::style::Style {
322 box_sizing: taffy::style::BoxSizing::ContentBox,
323 flex_wrap: taffy::style::FlexWrap::Wrap,
324 align_content: Some(taffy::style::AlignContent::FlexStart),
325 gap: taffy::geometry::Size {
326 width: taffy::style::LengthPercentage::Length(10f32),
327 height: taffy::style::LengthPercentage::Length(20f32),
328 },
329 size: taffy::geometry::Size {
330 width: taffy::style::Dimension::Length(100f32),
331 height: taffy::style::Dimension::Length(100f32),
332 },
333 ..Default::default()
334 },
335 &[node0, node1, node2, node3, node4, node5],
336 )
337 .unwrap();
338 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
339 println!("\nComputed tree:");
340 taffy.print_tree(node);
341 println!();
342 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
343 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
344 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
345 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
346 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
347 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
348 #[cfg(feature = "content_size")]
349 assert_eq!(
350 layout.scroll_width(),
351 0f32,
352 "scroll_width of node {:?}. Expected {}. Actual {}",
353 node,
354 0f32,
355 layout.scroll_width()
356 );
357 #[cfg(feature = "content_size")]
358 assert_eq!(
359 layout.scroll_height(),
360 0f32,
361 "scroll_height of node {:?}. Expected {}. Actual {}",
362 node,
363 0f32,
364 layout.scroll_height()
365 );
366 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
367 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
368 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
369 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
370 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
371 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
372 #[cfg(feature = "content_size")]
373 assert_eq!(
374 layout.scroll_width(),
375 0f32,
376 "scroll_width of node {:?}. Expected {}. Actual {}",
377 node0,
378 0f32,
379 layout.scroll_width()
380 );
381 #[cfg(feature = "content_size")]
382 assert_eq!(
383 layout.scroll_height(),
384 0f32,
385 "scroll_height of node {:?}. Expected {}. Actual {}",
386 node0,
387 0f32,
388 layout.scroll_height()
389 );
390 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
391 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
392 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
393 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
394 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
395 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
396 #[cfg(feature = "content_size")]
397 assert_eq!(
398 layout.scroll_width(),
399 0f32,
400 "scroll_width of node {:?}. Expected {}. Actual {}",
401 node1,
402 0f32,
403 layout.scroll_width()
404 );
405 #[cfg(feature = "content_size")]
406 assert_eq!(
407 layout.scroll_height(),
408 0f32,
409 "scroll_height of node {:?}. Expected {}. Actual {}",
410 node1,
411 0f32,
412 layout.scroll_height()
413 );
414 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
415 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
416 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
417 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
418 assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
419 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
420 #[cfg(feature = "content_size")]
421 assert_eq!(
422 layout.scroll_width(),
423 0f32,
424 "scroll_width of node {:?}. Expected {}. Actual {}",
425 node2,
426 0f32,
427 layout.scroll_width()
428 );
429 #[cfg(feature = "content_size")]
430 assert_eq!(
431 layout.scroll_height(),
432 0f32,
433 "scroll_height of node {:?}. Expected {}. Actual {}",
434 node2,
435 0f32,
436 layout.scroll_height()
437 );
438 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
439 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
440 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
441 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
442 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
443 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
444 #[cfg(feature = "content_size")]
445 assert_eq!(
446 layout.scroll_width(),
447 0f32,
448 "scroll_width of node {:?}. Expected {}. Actual {}",
449 node3,
450 0f32,
451 layout.scroll_width()
452 );
453 #[cfg(feature = "content_size")]
454 assert_eq!(
455 layout.scroll_height(),
456 0f32,
457 "scroll_height of node {:?}. Expected {}. Actual {}",
458 node3,
459 0f32,
460 layout.scroll_height()
461 );
462 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
463 let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
464 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
465 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4, 20f32, size.height);
466 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4, 30f32, location.x);
467 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
468 #[cfg(feature = "content_size")]
469 assert_eq!(
470 layout.scroll_width(),
471 0f32,
472 "scroll_width of node {:?}. Expected {}. Actual {}",
473 node4,
474 0f32,
475 layout.scroll_width()
476 );
477 #[cfg(feature = "content_size")]
478 assert_eq!(
479 layout.scroll_height(),
480 0f32,
481 "scroll_height of node {:?}. Expected {}. Actual {}",
482 node4,
483 0f32,
484 layout.scroll_height()
485 );
486 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
487 let layout @ Layout { size, location, .. } = taffy.layout(node5).unwrap();
488 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
489 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node5, 20f32, size.height);
490 assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node5, 60f32, location.x);
491 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
492 #[cfg(feature = "content_size")]
493 assert_eq!(
494 layout.scroll_width(),
495 0f32,
496 "scroll_width of node {:?}. Expected {}. Actual {}",
497 node5,
498 0f32,
499 layout.scroll_width()
500 );
501 #[cfg(feature = "content_size")]
502 assert_eq!(
503 layout.scroll_height(),
504 0f32,
505 "scroll_height of node {:?}. Expected {}. Actual {}",
506 node5,
507 0f32,
508 layout.scroll_height()
509 );
510}