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