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