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