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