1#[cfg(test)]
2mod generated {
3 #[test]
4 fn justify_content_row_space_around() {
5 let layout = stretch::compute(&stretch::style::Node {
6 justify_content: stretch::style::JustifyContent::SpaceAround,
7 width: stretch::style::Dimension::Points(100.0000),
8 height: stretch::style::Dimension::Points(100.0000),
9 children: vec![
10 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
11 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
12 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
13 ],
14 ..Default::default()
15 });
16
17 assert_eq!(layout.width, 100.0000);
18 assert_eq!(layout.height, 100.0000);
19 assert_eq!(layout.x, 0.0000);
20 assert_eq!(layout.y, 0.0000);
21
22 assert_eq!(layout.children[0].width, 10.0000);
23 assert_eq!(layout.children[0].height, 100.0000);
24 assert_eq!(layout.children[0].x, 12.0000);
25 assert_eq!(layout.children[0].y, 0.0000);
26
27 assert_eq!(layout.children[1].width, 10.0000);
28 assert_eq!(layout.children[1].height, 100.0000);
29 assert_eq!(layout.children[1].x, 45.0000);
30 assert_eq!(layout.children[1].y, 0.0000);
31
32 assert_eq!(layout.children[2].width, 10.0000);
33 assert_eq!(layout.children[2].height, 100.0000);
34 assert_eq!(layout.children[2].x, 78.0000);
35 assert_eq!(layout.children[2].y, 0.0000);
36 }
37
38 #[test]
39 fn align_items_center() {
40 let layout = stretch::compute(&stretch::style::Node {
41 align_items: stretch::style::AlignItems::Center,
42 width: stretch::style::Dimension::Points(100.0000),
43 height: stretch::style::Dimension::Points(100.0000),
44 children: vec![stretch::style::Node {
45 width: stretch::style::Dimension::Points(10.0000),
46 height: stretch::style::Dimension::Points(10.0000),
47 ..Default::default()
48 }],
49 ..Default::default()
50 });
51
52 assert_eq!(layout.width, 100.0000);
53 assert_eq!(layout.height, 100.0000);
54 assert_eq!(layout.x, 0.0000);
55 assert_eq!(layout.y, 0.0000);
56
57 assert_eq!(layout.children[0].width, 10.0000);
58 assert_eq!(layout.children[0].height, 10.0000);
59 assert_eq!(layout.children[0].x, 0.0000);
60 assert_eq!(layout.children[0].y, 45.0000);
61 }
62
63 #[test]
64 fn absolute_layout_justify_content_center() {
65 let layout = stretch::compute(&stretch::style::Node {
66 justify_content: stretch::style::JustifyContent::Center,
67 width: stretch::style::Dimension::Points(110.0000),
68 height: stretch::style::Dimension::Points(100.0000),
69 children: vec![stretch::style::Node {
70 position: stretch::style::Position::Absolute,
71 width: stretch::style::Dimension::Points(60.0000),
72 height: stretch::style::Dimension::Points(40.0000),
73 ..Default::default()
74 }],
75 ..Default::default()
76 });
77
78 assert_eq!(layout.width, 110.0000);
79 assert_eq!(layout.height, 100.0000);
80 assert_eq!(layout.x, 0.0000);
81 assert_eq!(layout.y, 0.0000);
82
83 assert_eq!(layout.children[0].width, 60.0000);
84 assert_eq!(layout.children[0].height, 40.0000);
85 assert_eq!(layout.children[0].x, 25.0000);
86 assert_eq!(layout.children[0].y, 0.0000);
87 }
88
89 #[test]
90 fn margin_auto_bottom_and_top() {
91 let layout = stretch::compute(&stretch::style::Node {
92 align_items: stretch::style::AlignItems::Center,
93 width: stretch::style::Dimension::Points(200.0000),
94 height: stretch::style::Dimension::Points(200.0000),
95 children: vec![
96 stretch::style::Node {
97 width: stretch::style::Dimension::Points(50.0000),
98 height: stretch::style::Dimension::Points(50.0000),
99 margin: stretch::style::Edges {
100 top: stretch::style::Dimension::Auto,
101 bottom: stretch::style::Dimension::Auto,
102 ..Default::default()
103 },
104 ..Default::default()
105 },
106 stretch::style::Node {
107 width: stretch::style::Dimension::Points(50.0000),
108 height: stretch::style::Dimension::Points(50.0000),
109 ..Default::default()
110 },
111 ],
112 ..Default::default()
113 });
114
115 assert_eq!(layout.width, 200.0000);
116 assert_eq!(layout.height, 200.0000);
117 assert_eq!(layout.x, 0.0000);
118 assert_eq!(layout.y, 0.0000);
119
120 assert_eq!(layout.children[0].width, 50.0000);
121 assert_eq!(layout.children[0].height, 50.0000);
122 assert_eq!(layout.children[0].x, 0.0000);
123 assert_eq!(layout.children[0].y, 75.0000);
124
125 assert_eq!(layout.children[1].width, 50.0000);
126 assert_eq!(layout.children[1].height, 50.0000);
127 assert_eq!(layout.children[1].x, 50.0000);
128 assert_eq!(layout.children[1].y, 75.0000);
129 }
130
131 #[test]
132 fn margin_auto_left_and_right_strech() {
133 let layout = stretch::compute(&stretch::style::Node {
134 width: stretch::style::Dimension::Points(200.0000),
135 height: stretch::style::Dimension::Points(200.0000),
136 children: vec![
137 stretch::style::Node {
138 width: stretch::style::Dimension::Points(50.0000),
139 height: stretch::style::Dimension::Points(50.0000),
140 margin: stretch::style::Edges {
141 start: stretch::style::Dimension::Auto,
142 end: stretch::style::Dimension::Auto,
143 ..Default::default()
144 },
145 ..Default::default()
146 },
147 stretch::style::Node {
148 width: stretch::style::Dimension::Points(50.0000),
149 height: stretch::style::Dimension::Points(50.0000),
150 ..Default::default()
151 },
152 ],
153 ..Default::default()
154 });
155
156 assert_eq!(layout.width, 200.0000);
157 assert_eq!(layout.height, 200.0000);
158 assert_eq!(layout.x, 0.0000);
159 assert_eq!(layout.y, 0.0000);
160
161 assert_eq!(layout.children[0].width, 50.0000);
162 assert_eq!(layout.children[0].height, 50.0000);
163 assert_eq!(layout.children[0].x, 50.0000);
164 assert_eq!(layout.children[0].y, 0.0000);
165
166 assert_eq!(layout.children[1].width, 50.0000);
167 assert_eq!(layout.children[1].height, 50.0000);
168 assert_eq!(layout.children[1].x, 150.0000);
169 assert_eq!(layout.children[1].y, 0.0000);
170 }
171
172 #[test]
173 fn rounding_flex_basis_overrides_main_size() {
174 let layout = stretch::compute(&stretch::style::Node {
175 flex_direction: stretch::style::FlexDirection::Column,
176 width: stretch::style::Dimension::Points(100.0000),
177 height: stretch::style::Dimension::Points(113.0000),
178 children: vec![
179 stretch::style::Node {
180 flex_grow: 1.0000,
181 flex_basis: stretch::style::Dimension::Points(50.0000),
182 height: stretch::style::Dimension::Points(20.0000),
183 ..Default::default()
184 },
185 stretch::style::Node {
186 flex_grow: 1.0000,
187 height: stretch::style::Dimension::Points(10.0000),
188 ..Default::default()
189 },
190 stretch::style::Node {
191 flex_grow: 1.0000,
192 height: stretch::style::Dimension::Points(10.0000),
193 ..Default::default()
194 },
195 ],
196 ..Default::default()
197 });
198
199 assert_eq!(layout.width, 100.0000);
200 assert_eq!(layout.height, 113.0000);
201 assert_eq!(layout.x, 0.0000);
202 assert_eq!(layout.y, 0.0000);
203
204 assert_eq!(layout.children[0].width, 100.0000);
205 assert_eq!(layout.children[0].height, 64.0000);
206 assert_eq!(layout.children[0].x, 0.0000);
207 assert_eq!(layout.children[0].y, 0.0000);
208
209 assert_eq!(layout.children[1].width, 100.0000);
210 assert_eq!(layout.children[1].height, 25.0000);
211 assert_eq!(layout.children[1].x, 0.0000);
212 assert_eq!(layout.children[1].y, 64.0000);
213
214 assert_eq!(layout.children[2].width, 100.0000);
215 assert_eq!(layout.children[2].height, 24.0000);
216 assert_eq!(layout.children[2].x, 0.0000);
217 assert_eq!(layout.children[2].y, 89.0000);
218 }
219
220 #[test]
221 fn percentage_flex_basis() {
222 let layout = stretch::compute(&stretch::style::Node {
223 width: stretch::style::Dimension::Points(200.0000),
224 height: stretch::style::Dimension::Points(200.0000),
225 children: vec![
226 stretch::style::Node {
227 flex_grow: 1.0000,
228 flex_basis: stretch::style::Dimension::Percent(0.5000),
229 ..Default::default()
230 },
231 stretch::style::Node {
232 flex_grow: 1.0000,
233 flex_basis: stretch::style::Dimension::Percent(0.2500),
234 ..Default::default()
235 },
236 ],
237 ..Default::default()
238 });
239
240 assert_eq!(layout.width, 200.0000);
241 assert_eq!(layout.height, 200.0000);
242 assert_eq!(layout.x, 0.0000);
243 assert_eq!(layout.y, 0.0000);
244
245 assert_eq!(layout.children[0].width, 125.0000);
246 assert_eq!(layout.children[0].height, 200.0000);
247 assert_eq!(layout.children[0].x, 0.0000);
248 assert_eq!(layout.children[0].y, 0.0000);
249
250 assert_eq!(layout.children[1].width, 75.0000);
251 assert_eq!(layout.children[1].height, 200.0000);
252 assert_eq!(layout.children[1].x, 125.0000);
253 assert_eq!(layout.children[1].y, 0.0000);
254 }
255
256 #[test]
257 fn rounding_fractial_input_3() {
258 let layout = stretch::compute(&stretch::style::Node {
259 flex_direction: stretch::style::FlexDirection::Column,
260 width: stretch::style::Dimension::Points(100.0000),
261 height: stretch::style::Dimension::Points(113.4000),
262 children: vec![
263 stretch::style::Node {
264 flex_grow: 1.0000,
265 flex_basis: stretch::style::Dimension::Points(50.0000),
266 height: stretch::style::Dimension::Points(20.0000),
267 ..Default::default()
268 },
269 stretch::style::Node {
270 flex_grow: 1.0000,
271 height: stretch::style::Dimension::Points(10.0000),
272 ..Default::default()
273 },
274 stretch::style::Node {
275 flex_grow: 1.0000,
276 height: stretch::style::Dimension::Points(10.0000),
277 ..Default::default()
278 },
279 ],
280 ..Default::default()
281 });
282
283 assert_eq!(layout.width, 100.0000);
284 assert_eq!(layout.height, 113.0000);
285 assert_eq!(layout.x, 0.0000);
286 assert_eq!(layout.y, 0.0000);
287
288 assert_eq!(layout.children[0].width, 100.0000);
289 assert_eq!(layout.children[0].height, 64.0000);
290 assert_eq!(layout.children[0].x, 0.0000);
291 assert_eq!(layout.children[0].y, 0.0000);
292
293 assert_eq!(layout.children[1].width, 100.0000);
294 assert_eq!(layout.children[1].height, 25.0000);
295 assert_eq!(layout.children[1].x, 0.0000);
296 assert_eq!(layout.children[1].y, 64.0000);
297
298 assert_eq!(layout.children[2].width, 100.0000);
299 assert_eq!(layout.children[2].height, 24.0000);
300 assert_eq!(layout.children[2].x, 0.0000);
301 assert_eq!(layout.children[2].y, 89.0000);
302 }
303
304 #[test]
305 fn margin_and_stretch_column() {
306 let layout = stretch::compute(&stretch::style::Node {
307 flex_direction: stretch::style::FlexDirection::Column,
308 width: stretch::style::Dimension::Points(100.0000),
309 height: stretch::style::Dimension::Points(100.0000),
310 children: vec![stretch::style::Node {
311 flex_grow: 1.0000,
312 margin: stretch::style::Edges {
313 start: stretch::style::Dimension::Points(10.0000),
314 end: stretch::style::Dimension::Points(10.0000),
315 ..Default::default()
316 },
317 ..Default::default()
318 }],
319 ..Default::default()
320 });
321
322 assert_eq!(layout.width, 100.0000);
323 assert_eq!(layout.height, 100.0000);
324 assert_eq!(layout.x, 0.0000);
325 assert_eq!(layout.y, 0.0000);
326
327 assert_eq!(layout.children[0].width, 80.0000);
328 assert_eq!(layout.children[0].height, 100.0000);
329 assert_eq!(layout.children[0].x, 10.0000);
330 assert_eq!(layout.children[0].y, 0.0000);
331 }
332
333 #[test]
334 fn wrapped_column_max_height_flex() {
335 let layout = stretch::compute(&stretch::style::Node {
336 flex_direction: stretch::style::FlexDirection::Column,
337 flex_wrap: stretch::style::FlexWrap::Wrap,
338 align_items: stretch::style::AlignItems::Center,
339 align_content: stretch::style::AlignContent::Center,
340 justify_content: stretch::style::JustifyContent::Center,
341 width: stretch::style::Dimension::Points(700.0000),
342 height: stretch::style::Dimension::Points(500.0000),
343 children: vec![
344 stretch::style::Node {
345 flex_grow: 1.0000,
346 flex_shrink: 1.0000,
347 flex_basis: stretch::style::Dimension::Percent(0.0000),
348 width: stretch::style::Dimension::Points(100.0000),
349 height: stretch::style::Dimension::Points(500.0000),
350 max_height: stretch::style::Dimension::Points(200.0000),
351 ..Default::default()
352 },
353 stretch::style::Node {
354 flex_grow: 1.0000,
355 flex_shrink: 1.0000,
356 flex_basis: stretch::style::Dimension::Percent(0.0000),
357 width: stretch::style::Dimension::Points(200.0000),
358 height: stretch::style::Dimension::Points(200.0000),
359 margin: stretch::style::Edges {
360 start: stretch::style::Dimension::Points(20.0000),
361 end: stretch::style::Dimension::Points(20.0000),
362 top: stretch::style::Dimension::Points(20.0000),
363 bottom: stretch::style::Dimension::Points(20.0000),
364 ..Default::default()
365 },
366 ..Default::default()
367 },
368 stretch::style::Node {
369 width: stretch::style::Dimension::Points(100.0000),
370 height: stretch::style::Dimension::Points(100.0000),
371 ..Default::default()
372 },
373 ],
374 ..Default::default()
375 });
376
377 assert_eq!(layout.width, 700.0000);
378 assert_eq!(layout.height, 500.0000);
379 assert_eq!(layout.x, 0.0000);
380 assert_eq!(layout.y, 0.0000);
381
382 assert_eq!(layout.children[0].width, 100.0000);
383 assert_eq!(layout.children[0].height, 180.0000);
384 assert_eq!(layout.children[0].x, 300.0000);
385 assert_eq!(layout.children[0].y, 0.0000);
386
387 assert_eq!(layout.children[1].width, 200.0000);
388 assert_eq!(layout.children[1].height, 180.0000);
389 assert_eq!(layout.children[1].x, 250.0000);
390 assert_eq!(layout.children[1].y, 200.0000);
391
392 assert_eq!(layout.children[2].width, 100.0000);
393 assert_eq!(layout.children[2].height, 100.0000);
394 assert_eq!(layout.children[2].x, 300.0000);
395 assert_eq!(layout.children[2].y, 400.0000);
396 }
397
398 #[test]
399 fn align_baseline_nested_child() {
400 let layout = stretch::compute(&stretch::style::Node {
401 align_items: stretch::style::AlignItems::Baseline,
402 width: stretch::style::Dimension::Points(100.0000),
403 height: stretch::style::Dimension::Points(100.0000),
404 children: vec![
405 stretch::style::Node {
406 width: stretch::style::Dimension::Points(50.0000),
407 height: stretch::style::Dimension::Points(50.0000),
408 ..Default::default()
409 },
410 stretch::style::Node {
411 flex_direction: stretch::style::FlexDirection::Column,
412 width: stretch::style::Dimension::Points(50.0000),
413 height: stretch::style::Dimension::Points(20.0000),
414 children: vec![stretch::style::Node {
415 width: stretch::style::Dimension::Points(50.0000),
416 height: stretch::style::Dimension::Points(10.0000),
417 ..Default::default()
418 }],
419 ..Default::default()
420 },
421 ],
422 ..Default::default()
423 });
424
425 assert_eq!(layout.width, 100.0000);
426 assert_eq!(layout.height, 100.0000);
427 assert_eq!(layout.x, 0.0000);
428 assert_eq!(layout.y, 0.0000);
429
430 assert_eq!(layout.children[0].width, 50.0000);
431 assert_eq!(layout.children[0].height, 50.0000);
432 assert_eq!(layout.children[0].x, 0.0000);
433 assert_eq!(layout.children[0].y, 0.0000);
434
435 assert_eq!(layout.children[1].width, 50.0000);
436 assert_eq!(layout.children[1].height, 20.0000);
437 assert_eq!(layout.children[1].x, 50.0000);
438 assert_eq!(layout.children[1].y, 40.0000);
439
440 assert_eq!(layout.children[1].children[0].width, 50.0000);
441 assert_eq!(layout.children[1].children[0].height, 10.0000);
442 assert_eq!(layout.children[1].children[0].x, 0.0000);
443 assert_eq!(layout.children[1].children[0].y, 0.0000);
444 }
445
446 #[test]
447 fn max_height_overrides_height_on_root() {
448 let layout = stretch::compute(&stretch::style::Node {
449 height: stretch::style::Dimension::Points(200.0000),
450 max_height: stretch::style::Dimension::Points(100.0000),
451 ..Default::default()
452 });
453
454 assert_eq!(layout.width, 0.0000);
455 assert_eq!(layout.height, 100.0000);
456 assert_eq!(layout.x, 0.0000);
457 assert_eq!(layout.y, 0.0000);
458 }
459
460 #[test]
461 fn padding_center_child() {
462 let layout = stretch::compute(&stretch::style::Node {
463 align_items: stretch::style::AlignItems::Center,
464 justify_content: stretch::style::JustifyContent::Center,
465 width: stretch::style::Dimension::Points(100.0000),
466 height: stretch::style::Dimension::Points(100.0000),
467 padding: stretch::style::Edges {
468 start: stretch::style::Dimension::Points(10.0000),
469 end: stretch::style::Dimension::Points(20.0000),
470 top: stretch::style::Dimension::Points(10.0000),
471 bottom: stretch::style::Dimension::Points(20.0000),
472 ..Default::default()
473 },
474 children: vec![stretch::style::Node {
475 width: stretch::style::Dimension::Points(10.0000),
476 height: stretch::style::Dimension::Points(10.0000),
477 ..Default::default()
478 }],
479 ..Default::default()
480 });
481
482 assert_eq!(layout.width, 100.0000);
483 assert_eq!(layout.height, 100.0000);
484 assert_eq!(layout.x, 0.0000);
485 assert_eq!(layout.y, 0.0000);
486
487 assert_eq!(layout.children[0].width, 10.0000);
488 assert_eq!(layout.children[0].height, 10.0000);
489 assert_eq!(layout.children[0].x, 40.0000);
490 assert_eq!(layout.children[0].y, 40.0000);
491 }
492
493 #[test]
494 fn align_flex_start_with_stretching_children() {
495 let layout = stretch::compute(&stretch::style::Node {
496 width: stretch::style::Dimension::Points(500.0000),
497 height: stretch::style::Dimension::Points(500.0000),
498 children: vec![stretch::style::Node {
499 children: vec![stretch::style::Node {
500 flex_grow: 1.0000,
501 flex_shrink: 1.0000,
502 children: vec![stretch::style::Node {
503 flex_grow: 1.0000,
504 flex_shrink: 1.0000,
505 ..Default::default()
506 }],
507 ..Default::default()
508 }],
509 ..Default::default()
510 }],
511 ..Default::default()
512 });
513
514 assert_eq!(layout.width, 500.0000);
515 assert_eq!(layout.height, 500.0000);
516 assert_eq!(layout.x, 0.0000);
517 assert_eq!(layout.y, 0.0000);
518
519 assert_eq!(layout.children[0].width, 0.0000);
520 assert_eq!(layout.children[0].height, 500.0000);
521 assert_eq!(layout.children[0].x, 0.0000);
522 assert_eq!(layout.children[0].y, 0.0000);
523
524 assert_eq!(layout.children[0].children[0].width, 0.0000);
525 assert_eq!(layout.children[0].children[0].height, 500.0000);
526 assert_eq!(layout.children[0].children[0].x, 0.0000);
527 assert_eq!(layout.children[0].children[0].y, 0.0000);
528
529 assert_eq!(layout.children[0].children[0].children[0].width, 0.0000);
530 assert_eq!(layout.children[0].children[0].children[0].height, 500.0000);
531 assert_eq!(layout.children[0].children[0].children[0].x, 0.0000);
532 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
533 }
534
535 #[test]
536 fn min_width_overrides_width() {
537 let layout = stretch::compute(&stretch::style::Node {
538 children: vec![stretch::style::Node {
539 width: stretch::style::Dimension::Points(50.0000),
540 min_width: stretch::style::Dimension::Points(100.0000),
541 ..Default::default()
542 }],
543 ..Default::default()
544 });
545
546 assert_eq!(layout.width, 100.0000);
547 assert_eq!(layout.height, 0.0000);
548 assert_eq!(layout.x, 0.0000);
549 assert_eq!(layout.y, 0.0000);
550
551 assert_eq!(layout.children[0].width, 100.0000);
552 assert_eq!(layout.children[0].height, 0.0000);
553 assert_eq!(layout.children[0].x, 0.0000);
554 assert_eq!(layout.children[0].y, 0.0000);
555 }
556
557 #[test]
558 fn flex_wrap_align_stretch_fits_one_row() {
559 let layout = stretch::compute(&stretch::style::Node {
560 flex_wrap: stretch::style::FlexWrap::Wrap,
561 width: stretch::style::Dimension::Points(150.0000),
562 height: stretch::style::Dimension::Points(100.0000),
563 children: vec![
564 stretch::style::Node { width: stretch::style::Dimension::Points(50.0000), ..Default::default() },
565 stretch::style::Node { width: stretch::style::Dimension::Points(50.0000), ..Default::default() },
566 ],
567 ..Default::default()
568 });
569
570 assert_eq!(layout.width, 150.0000);
571 assert_eq!(layout.height, 100.0000);
572 assert_eq!(layout.x, 0.0000);
573 assert_eq!(layout.y, 0.0000);
574
575 assert_eq!(layout.children[0].width, 50.0000);
576 assert_eq!(layout.children[0].height, 100.0000);
577 assert_eq!(layout.children[0].x, 0.0000);
578 assert_eq!(layout.children[0].y, 0.0000);
579
580 assert_eq!(layout.children[1].width, 50.0000);
581 assert_eq!(layout.children[1].height, 100.0000);
582 assert_eq!(layout.children[1].x, 50.0000);
583 assert_eq!(layout.children[1].y, 0.0000);
584 }
585
586 #[test]
587 fn justify_content_row_space_evenly() {
588 let layout = stretch::compute(&stretch::style::Node {
589 justify_content: stretch::style::JustifyContent::SpaceEvenly,
590 width: stretch::style::Dimension::Points(100.0000),
591 height: stretch::style::Dimension::Points(100.0000),
592 children: vec![
593 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
594 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
595 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
596 ],
597 ..Default::default()
598 });
599
600 assert_eq!(layout.width, 100.0000);
601 assert_eq!(layout.height, 100.0000);
602 assert_eq!(layout.x, 0.0000);
603 assert_eq!(layout.y, 0.0000);
604
605 assert_eq!(layout.children[0].width, 0.0000);
606 assert_eq!(layout.children[0].height, 10.0000);
607 assert_eq!(layout.children[0].x, 25.0000);
608 assert_eq!(layout.children[0].y, 0.0000);
609
610 assert_eq!(layout.children[1].width, 0.0000);
611 assert_eq!(layout.children[1].height, 10.0000);
612 assert_eq!(layout.children[1].x, 50.0000);
613 assert_eq!(layout.children[1].y, 0.0000);
614
615 assert_eq!(layout.children[2].width, 0.0000);
616 assert_eq!(layout.children[2].height, 10.0000);
617 assert_eq!(layout.children[2].x, 75.0000);
618 assert_eq!(layout.children[2].y, 0.0000);
619 }
620
621 #[test]
622 fn absolute_layout_percentage_bottom_based_on_parent_height() {
623 let layout = stretch::compute(&stretch::style::Node {
624 width: stretch::style::Dimension::Points(100.0000),
625 height: stretch::style::Dimension::Points(200.0000),
626 children: vec![
627 stretch::style::Node {
628 position: stretch::style::Position::Absolute,
629 width: stretch::style::Dimension::Points(10.0000),
630 height: stretch::style::Dimension::Points(10.0000),
631 top: stretch::style::Dimension::Percent(0.5000),
632 ..Default::default()
633 },
634 stretch::style::Node {
635 position: stretch::style::Position::Absolute,
636 width: stretch::style::Dimension::Points(10.0000),
637 height: stretch::style::Dimension::Points(10.0000),
638 bottom: stretch::style::Dimension::Percent(0.5000),
639 ..Default::default()
640 },
641 stretch::style::Node {
642 position: stretch::style::Position::Absolute,
643 width: stretch::style::Dimension::Points(10.0000),
644 top: stretch::style::Dimension::Percent(0.1000),
645 bottom: stretch::style::Dimension::Percent(0.1000),
646 ..Default::default()
647 },
648 ],
649 ..Default::default()
650 });
651
652 assert_eq!(layout.width, 100.0000);
653 assert_eq!(layout.height, 200.0000);
654 assert_eq!(layout.x, 0.0000);
655 assert_eq!(layout.y, 0.0000);
656
657 assert_eq!(layout.children[0].width, 10.0000);
658 assert_eq!(layout.children[0].height, 10.0000);
659 assert_eq!(layout.children[0].x, 0.0000);
660 assert_eq!(layout.children[0].y, 100.0000);
661
662 assert_eq!(layout.children[1].width, 10.0000);
663 assert_eq!(layout.children[1].height, 10.0000);
664 assert_eq!(layout.children[1].x, 0.0000);
665 assert_eq!(layout.children[1].y, 90.0000);
666
667 assert_eq!(layout.children[2].width, 10.0000);
668 assert_eq!(layout.children[2].height, 160.0000);
669 assert_eq!(layout.children[2].x, 0.0000);
670 assert_eq!(layout.children[2].y, 20.0000);
671 }
672
673 #[test]
674 fn absolute_layout_align_items_and_justify_content_flex_end() {
675 let layout = stretch::compute(&stretch::style::Node {
676 align_items: stretch::style::AlignItems::FlexEnd,
677 justify_content: stretch::style::JustifyContent::FlexEnd,
678 width: stretch::style::Dimension::Points(110.0000),
679 height: stretch::style::Dimension::Points(100.0000),
680 children: vec![stretch::style::Node {
681 position: stretch::style::Position::Absolute,
682 width: stretch::style::Dimension::Points(60.0000),
683 height: stretch::style::Dimension::Points(40.0000),
684 ..Default::default()
685 }],
686 ..Default::default()
687 });
688
689 assert_eq!(layout.width, 110.0000);
690 assert_eq!(layout.height, 100.0000);
691 assert_eq!(layout.x, 0.0000);
692 assert_eq!(layout.y, 0.0000);
693
694 assert_eq!(layout.children[0].width, 60.0000);
695 assert_eq!(layout.children[0].height, 40.0000);
696 assert_eq!(layout.children[0].x, 50.0000);
697 assert_eq!(layout.children[0].y, 60.0000);
698 }
699
700 #[test]
701 fn nested_overflowing_child() {
702 let layout = stretch::compute(&stretch::style::Node {
703 width: stretch::style::Dimension::Points(100.0000),
704 height: stretch::style::Dimension::Points(100.0000),
705 children: vec![stretch::style::Node {
706 children: vec![stretch::style::Node {
707 width: stretch::style::Dimension::Points(200.0000),
708 height: stretch::style::Dimension::Points(200.0000),
709 ..Default::default()
710 }],
711 ..Default::default()
712 }],
713 ..Default::default()
714 });
715
716 assert_eq!(layout.width, 100.0000);
717 assert_eq!(layout.height, 100.0000);
718 assert_eq!(layout.x, 0.0000);
719 assert_eq!(layout.y, 0.0000);
720
721 assert_eq!(layout.children[0].width, 200.0000);
722 assert_eq!(layout.children[0].height, 100.0000);
723 assert_eq!(layout.children[0].x, 0.0000);
724 assert_eq!(layout.children[0].y, 0.0000);
725
726 assert_eq!(layout.children[0].children[0].width, 200.0000);
727 assert_eq!(layout.children[0].children[0].height, 200.0000);
728 assert_eq!(layout.children[0].children[0].x, 0.0000);
729 assert_eq!(layout.children[0].children[0].y, 0.0000);
730 }
731
732 #[test]
733 fn flex_direction_row() {
734 let layout = stretch::compute(&stretch::style::Node {
735 width: stretch::style::Dimension::Points(100.0000),
736 height: stretch::style::Dimension::Points(100.0000),
737 children: vec![
738 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
739 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
740 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
741 ],
742 ..Default::default()
743 });
744
745 assert_eq!(layout.width, 100.0000);
746 assert_eq!(layout.height, 100.0000);
747 assert_eq!(layout.x, 0.0000);
748 assert_eq!(layout.y, 0.0000);
749
750 assert_eq!(layout.children[0].width, 10.0000);
751 assert_eq!(layout.children[0].height, 100.0000);
752 assert_eq!(layout.children[0].x, 0.0000);
753 assert_eq!(layout.children[0].y, 0.0000);
754
755 assert_eq!(layout.children[1].width, 10.0000);
756 assert_eq!(layout.children[1].height, 100.0000);
757 assert_eq!(layout.children[1].x, 10.0000);
758 assert_eq!(layout.children[1].y, 0.0000);
759
760 assert_eq!(layout.children[2].width, 10.0000);
761 assert_eq!(layout.children[2].height, 100.0000);
762 assert_eq!(layout.children[2].x, 20.0000);
763 assert_eq!(layout.children[2].y, 0.0000);
764 }
765
766 #[test]
767 fn child_min_max_width_flexing() {
768 let layout = stretch::compute(&stretch::style::Node {
769 width: stretch::style::Dimension::Points(120.0000),
770 height: stretch::style::Dimension::Points(50.0000),
771 children: vec![
772 stretch::style::Node {
773 flex_grow: 1.0000,
774 flex_shrink: 0.0000,
775 flex_basis: stretch::style::Dimension::Points(0.0000),
776 min_width: stretch::style::Dimension::Points(60.0000),
777 ..Default::default()
778 },
779 stretch::style::Node {
780 flex_grow: 1.0000,
781 flex_shrink: 0.0000,
782 flex_basis: stretch::style::Dimension::Percent(0.5000),
783 max_width: stretch::style::Dimension::Points(20.0000),
784 ..Default::default()
785 },
786 ],
787 ..Default::default()
788 });
789
790 assert_eq!(layout.width, 120.0000);
791 assert_eq!(layout.height, 50.0000);
792 assert_eq!(layout.x, 0.0000);
793 assert_eq!(layout.y, 0.0000);
794
795 assert_eq!(layout.children[0].width, 100.0000);
796 assert_eq!(layout.children[0].height, 50.0000);
797 assert_eq!(layout.children[0].x, 0.0000);
798 assert_eq!(layout.children[0].y, 0.0000);
799
800 assert_eq!(layout.children[1].width, 20.0000);
801 assert_eq!(layout.children[1].height, 50.0000);
802 assert_eq!(layout.children[1].x, 100.0000);
803 assert_eq!(layout.children[1].y, 0.0000);
804 }
805
806 #[test]
807 fn absolute_layout_in_wrap_reverse_row_container_flex_end() {
808 let layout = stretch::compute(&stretch::style::Node {
809 flex_wrap: stretch::style::FlexWrap::WrapReverse,
810 width: stretch::style::Dimension::Points(100.0000),
811 height: stretch::style::Dimension::Points(100.0000),
812 children: vec![stretch::style::Node {
813 position: stretch::style::Position::Absolute,
814 align_self: stretch::style::AlignSelf::FlexEnd,
815 width: stretch::style::Dimension::Points(20.0000),
816 height: stretch::style::Dimension::Points(20.0000),
817 ..Default::default()
818 }],
819 ..Default::default()
820 });
821
822 assert_eq!(layout.width, 100.0000);
823 assert_eq!(layout.height, 100.0000);
824 assert_eq!(layout.x, 0.0000);
825 assert_eq!(layout.y, 0.0000);
826
827 assert_eq!(layout.children[0].width, 20.0000);
828 assert_eq!(layout.children[0].height, 20.0000);
829 assert_eq!(layout.children[0].x, 0.0000);
830 assert_eq!(layout.children[0].y, 0.0000);
831 }
832
833 #[test]
834 fn margin_and_flex_column() {
835 let layout = stretch::compute(&stretch::style::Node {
836 flex_direction: stretch::style::FlexDirection::Column,
837 width: stretch::style::Dimension::Points(100.0000),
838 height: stretch::style::Dimension::Points(100.0000),
839 children: vec![stretch::style::Node {
840 flex_grow: 1.0000,
841 margin: stretch::style::Edges {
842 top: stretch::style::Dimension::Points(10.0000),
843 bottom: stretch::style::Dimension::Points(10.0000),
844 ..Default::default()
845 },
846 ..Default::default()
847 }],
848 ..Default::default()
849 });
850
851 assert_eq!(layout.width, 100.0000);
852 assert_eq!(layout.height, 100.0000);
853 assert_eq!(layout.x, 0.0000);
854 assert_eq!(layout.y, 0.0000);
855
856 assert_eq!(layout.children[0].width, 100.0000);
857 assert_eq!(layout.children[0].height, 80.0000);
858 assert_eq!(layout.children[0].x, 0.0000);
859 assert_eq!(layout.children[0].y, 10.0000);
860 }
861
862 #[test]
863 fn flex_basis_flex_shrink_row() {
864 let layout = stretch::compute(&stretch::style::Node {
865 width: stretch::style::Dimension::Points(100.0000),
866 height: stretch::style::Dimension::Points(100.0000),
867 children: vec![
868 stretch::style::Node { flex_basis: stretch::style::Dimension::Points(100.0000), ..Default::default() },
869 stretch::style::Node { flex_basis: stretch::style::Dimension::Points(50.0000), ..Default::default() },
870 ],
871 ..Default::default()
872 });
873
874 assert_eq!(layout.width, 100.0000);
875 assert_eq!(layout.height, 100.0000);
876 assert_eq!(layout.x, 0.0000);
877 assert_eq!(layout.y, 0.0000);
878
879 assert_eq!(layout.children[0].width, 67.0000);
880 assert_eq!(layout.children[0].height, 100.0000);
881 assert_eq!(layout.children[0].x, 0.0000);
882 assert_eq!(layout.children[0].y, 0.0000);
883
884 assert_eq!(layout.children[1].width, 33.0000);
885 assert_eq!(layout.children[1].height, 100.0000);
886 assert_eq!(layout.children[1].x, 67.0000);
887 assert_eq!(layout.children[1].y, 0.0000);
888 }
889
890 #[test]
891 fn justify_content_column_min_height_and_margin_top() {
892 let layout = stretch::compute(&stretch::style::Node {
893 flex_direction: stretch::style::FlexDirection::Column,
894 justify_content: stretch::style::JustifyContent::Center,
895 min_height: stretch::style::Dimension::Points(50.0000),
896 children: vec![stretch::style::Node {
897 width: stretch::style::Dimension::Points(20.0000),
898 height: stretch::style::Dimension::Points(20.0000),
899 margin: stretch::style::Edges { top: stretch::style::Dimension::Points(10.0000), ..Default::default() },
900 ..Default::default()
901 }],
902 ..Default::default()
903 });
904
905 assert_eq!(layout.width, 20.0000);
906 assert_eq!(layout.height, 50.0000);
907 assert_eq!(layout.x, 0.0000);
908 assert_eq!(layout.y, 0.0000);
909
910 assert_eq!(layout.children[0].width, 20.0000);
911 assert_eq!(layout.children[0].height, 20.0000);
912 assert_eq!(layout.children[0].x, 0.0000);
913 assert_eq!(layout.children[0].y, 20.0000);
914 }
915
916 #[test]
917 fn justify_content_overflow_min_max() {
918 let layout = stretch::compute(&stretch::style::Node {
919 flex_direction: stretch::style::FlexDirection::Column,
920 justify_content: stretch::style::JustifyContent::Center,
921 min_height: stretch::style::Dimension::Points(100.0000),
922 max_height: stretch::style::Dimension::Points(110.0000),
923 children: vec![
924 stretch::style::Node {
925 flex_shrink: 0.0000,
926 width: stretch::style::Dimension::Points(50.0000),
927 height: stretch::style::Dimension::Points(50.0000),
928 ..Default::default()
929 },
930 stretch::style::Node {
931 flex_shrink: 0.0000,
932 width: stretch::style::Dimension::Points(50.0000),
933 height: stretch::style::Dimension::Points(50.0000),
934 ..Default::default()
935 },
936 stretch::style::Node {
937 flex_shrink: 0.0000,
938 width: stretch::style::Dimension::Points(50.0000),
939 height: stretch::style::Dimension::Points(50.0000),
940 ..Default::default()
941 },
942 ],
943 ..Default::default()
944 });
945
946 assert_eq!(layout.width, 50.0000);
947 assert_eq!(layout.height, 110.0000);
948 assert_eq!(layout.x, 0.0000);
949 assert_eq!(layout.y, 0.0000);
950
951 assert_eq!(layout.children[0].width, 50.0000);
952 assert_eq!(layout.children[0].height, 50.0000);
953 assert_eq!(layout.children[0].x, 0.0000);
954 assert_eq!(layout.children[0].y, -20.0000);
955
956 assert_eq!(layout.children[1].width, 50.0000);
957 assert_eq!(layout.children[1].height, 50.0000);
958 assert_eq!(layout.children[1].x, 0.0000);
959 assert_eq!(layout.children[1].y, 30.0000);
960
961 assert_eq!(layout.children[2].width, 50.0000);
962 assert_eq!(layout.children[2].height, 50.0000);
963 assert_eq!(layout.children[2].x, 0.0000);
964 assert_eq!(layout.children[2].y, 80.0000);
965 }
966
967 #[test]
968 fn wrap_reverse_column_fixed_size() {
969 let layout = stretch::compute(&stretch::style::Node {
970 flex_direction: stretch::style::FlexDirection::Column,
971 flex_wrap: stretch::style::FlexWrap::WrapReverse,
972 align_items: stretch::style::AlignItems::Center,
973 width: stretch::style::Dimension::Points(200.0000),
974 height: stretch::style::Dimension::Points(100.0000),
975 children: vec![
976 stretch::style::Node {
977 width: stretch::style::Dimension::Points(30.0000),
978 height: stretch::style::Dimension::Points(10.0000),
979 ..Default::default()
980 },
981 stretch::style::Node {
982 width: stretch::style::Dimension::Points(30.0000),
983 height: stretch::style::Dimension::Points(20.0000),
984 ..Default::default()
985 },
986 stretch::style::Node {
987 width: stretch::style::Dimension::Points(30.0000),
988 height: stretch::style::Dimension::Points(30.0000),
989 ..Default::default()
990 },
991 stretch::style::Node {
992 width: stretch::style::Dimension::Points(30.0000),
993 height: stretch::style::Dimension::Points(40.0000),
994 ..Default::default()
995 },
996 stretch::style::Node {
997 width: stretch::style::Dimension::Points(30.0000),
998 height: stretch::style::Dimension::Points(50.0000),
999 ..Default::default()
1000 },
1001 ],
1002 ..Default::default()
1003 });
1004
1005 assert_eq!(layout.width, 200.0000);
1006 assert_eq!(layout.height, 100.0000);
1007 assert_eq!(layout.x, 0.0000);
1008 assert_eq!(layout.y, 0.0000);
1009
1010 assert_eq!(layout.children[0].width, 30.0000);
1011 assert_eq!(layout.children[0].height, 10.0000);
1012 assert_eq!(layout.children[0].x, 135.0000);
1013 assert_eq!(layout.children[0].y, 0.0000);
1014
1015 assert_eq!(layout.children[1].width, 30.0000);
1016 assert_eq!(layout.children[1].height, 20.0000);
1017 assert_eq!(layout.children[1].x, 135.0000);
1018 assert_eq!(layout.children[1].y, 10.0000);
1019
1020 assert_eq!(layout.children[2].width, 30.0000);
1021 assert_eq!(layout.children[2].height, 30.0000);
1022 assert_eq!(layout.children[2].x, 135.0000);
1023 assert_eq!(layout.children[2].y, 30.0000);
1024
1025 assert_eq!(layout.children[3].width, 30.0000);
1026 assert_eq!(layout.children[3].height, 40.0000);
1027 assert_eq!(layout.children[3].x, 135.0000);
1028 assert_eq!(layout.children[3].y, 60.0000);
1029
1030 assert_eq!(layout.children[4].width, 30.0000);
1031 assert_eq!(layout.children[4].height, 50.0000);
1032 assert_eq!(layout.children[4].x, 35.0000);
1033 assert_eq!(layout.children[4].y, 0.0000);
1034 }
1035
1036 #[test]
1037 fn max_width() {
1038 let layout = stretch::compute(&stretch::style::Node {
1039 flex_direction: stretch::style::FlexDirection::Column,
1040 width: stretch::style::Dimension::Points(100.0000),
1041 height: stretch::style::Dimension::Points(100.0000),
1042 children: vec![stretch::style::Node {
1043 max_width: stretch::style::Dimension::Points(50.0000),
1044 height: stretch::style::Dimension::Points(10.0000),
1045 ..Default::default()
1046 }],
1047 ..Default::default()
1048 });
1049
1050 assert_eq!(layout.width, 100.0000);
1051 assert_eq!(layout.height, 100.0000);
1052 assert_eq!(layout.x, 0.0000);
1053 assert_eq!(layout.y, 0.0000);
1054
1055 assert_eq!(layout.children[0].width, 50.0000);
1056 assert_eq!(layout.children[0].height, 10.0000);
1057 assert_eq!(layout.children[0].x, 0.0000);
1058 assert_eq!(layout.children[0].y, 0.0000);
1059 }
1060
1061 #[test]
1062 fn justify_content_row_center() {
1063 let layout = stretch::compute(&stretch::style::Node {
1064 justify_content: stretch::style::JustifyContent::Center,
1065 width: stretch::style::Dimension::Points(100.0000),
1066 height: stretch::style::Dimension::Points(100.0000),
1067 children: vec![
1068 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
1069 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
1070 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
1071 ],
1072 ..Default::default()
1073 });
1074
1075 assert_eq!(layout.width, 100.0000);
1076 assert_eq!(layout.height, 100.0000);
1077 assert_eq!(layout.x, 0.0000);
1078 assert_eq!(layout.y, 0.0000);
1079
1080 assert_eq!(layout.children[0].width, 10.0000);
1081 assert_eq!(layout.children[0].height, 100.0000);
1082 assert_eq!(layout.children[0].x, 35.0000);
1083 assert_eq!(layout.children[0].y, 0.0000);
1084
1085 assert_eq!(layout.children[1].width, 10.0000);
1086 assert_eq!(layout.children[1].height, 100.0000);
1087 assert_eq!(layout.children[1].x, 45.0000);
1088 assert_eq!(layout.children[1].y, 0.0000);
1089
1090 assert_eq!(layout.children[2].width, 10.0000);
1091 assert_eq!(layout.children[2].height, 100.0000);
1092 assert_eq!(layout.children[2].x, 55.0000);
1093 assert_eq!(layout.children[2].y, 0.0000);
1094 }
1095
1096 #[test]
1097 fn flex_grow_root_minimized() {
1098 let layout = stretch::compute(&stretch::style::Node {
1099 flex_direction: stretch::style::FlexDirection::Column,
1100 width: stretch::style::Dimension::Points(100.0000),
1101 min_height: stretch::style::Dimension::Points(100.0000),
1102 max_height: stretch::style::Dimension::Points(500.0000),
1103 children: vec![stretch::style::Node {
1104 flex_direction: stretch::style::FlexDirection::Column,
1105 flex_grow: 1.0000,
1106 min_height: stretch::style::Dimension::Points(100.0000),
1107 max_height: stretch::style::Dimension::Points(500.0000),
1108 children: vec![
1109 stretch::style::Node {
1110 flex_grow: 1.0000,
1111 flex_basis: stretch::style::Dimension::Points(200.0000),
1112 ..Default::default()
1113 },
1114 stretch::style::Node { height: stretch::style::Dimension::Points(100.0000), ..Default::default() },
1115 ],
1116 ..Default::default()
1117 }],
1118 ..Default::default()
1119 });
1120
1121 assert_eq!(layout.width, 100.0000);
1122 assert_eq!(layout.height, 300.0000);
1123 assert_eq!(layout.x, 0.0000);
1124 assert_eq!(layout.y, 0.0000);
1125
1126 assert_eq!(layout.children[0].width, 100.0000);
1127 assert_eq!(layout.children[0].height, 300.0000);
1128 assert_eq!(layout.children[0].x, 0.0000);
1129 assert_eq!(layout.children[0].y, 0.0000);
1130
1131 assert_eq!(layout.children[0].children[0].width, 100.0000);
1132 assert_eq!(layout.children[0].children[0].height, 200.0000);
1133 assert_eq!(layout.children[0].children[0].x, 0.0000);
1134 assert_eq!(layout.children[0].children[0].y, 0.0000);
1135
1136 assert_eq!(layout.children[0].children[1].width, 100.0000);
1137 assert_eq!(layout.children[0].children[1].height, 100.0000);
1138 assert_eq!(layout.children[0].children[1].x, 0.0000);
1139 assert_eq!(layout.children[0].children[1].y, 200.0000);
1140 }
1141
1142 #[test]
1143 fn container_with_unsized_child() {
1144 let layout = stretch::compute(&stretch::style::Node {
1145 width: stretch::style::Dimension::Points(100.0000),
1146 height: stretch::style::Dimension::Points(100.0000),
1147 children: vec![stretch::style::Node { ..Default::default() }],
1148 ..Default::default()
1149 });
1150
1151 assert_eq!(layout.width, 100.0000);
1152 assert_eq!(layout.height, 100.0000);
1153 assert_eq!(layout.x, 0.0000);
1154 assert_eq!(layout.y, 0.0000);
1155
1156 assert_eq!(layout.children[0].width, 0.0000);
1157 assert_eq!(layout.children[0].height, 100.0000);
1158 assert_eq!(layout.children[0].x, 0.0000);
1159 assert_eq!(layout.children[0].y, 0.0000);
1160 }
1161
1162 #[test]
1163 fn flex_grow_within_constrained_min_row() {
1164 let layout = stretch::compute(&stretch::style::Node {
1165 min_width: stretch::style::Dimension::Points(100.0000),
1166 height: stretch::style::Dimension::Points(100.0000),
1167 children: vec![
1168 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
1169 stretch::style::Node { width: stretch::style::Dimension::Points(50.0000), ..Default::default() },
1170 ],
1171 ..Default::default()
1172 });
1173
1174 assert_eq!(layout.width, 100.0000);
1175 assert_eq!(layout.height, 100.0000);
1176 assert_eq!(layout.x, 0.0000);
1177 assert_eq!(layout.y, 0.0000);
1178
1179 assert_eq!(layout.children[0].width, 50.0000);
1180 assert_eq!(layout.children[0].height, 100.0000);
1181 assert_eq!(layout.children[0].x, 0.0000);
1182 assert_eq!(layout.children[0].y, 0.0000);
1183
1184 assert_eq!(layout.children[1].width, 50.0000);
1185 assert_eq!(layout.children[1].height, 100.0000);
1186 assert_eq!(layout.children[1].x, 50.0000);
1187 assert_eq!(layout.children[1].y, 0.0000);
1188 }
1189
1190 #[test]
1191 fn flex_shrink_by_outer_margin_with_max_size() {
1192 let layout = stretch::compute(&stretch::style::Node {
1193 flex_direction: stretch::style::FlexDirection::Column,
1194 height: stretch::style::Dimension::Points(100.0000),
1195 max_height: stretch::style::Dimension::Points(80.0000),
1196 children: vec![stretch::style::Node {
1197 width: stretch::style::Dimension::Points(20.0000),
1198 height: stretch::style::Dimension::Points(20.0000),
1199 margin: stretch::style::Edges {
1200 top: stretch::style::Dimension::Points(100.0000),
1201 ..Default::default()
1202 },
1203 ..Default::default()
1204 }],
1205 ..Default::default()
1206 });
1207
1208 assert_eq!(layout.width, 20.0000);
1209 assert_eq!(layout.height, 80.0000);
1210 assert_eq!(layout.x, 0.0000);
1211 assert_eq!(layout.y, 0.0000);
1212
1213 assert_eq!(layout.children[0].width, 20.0000);
1214 assert_eq!(layout.children[0].height, 0.0000);
1215 assert_eq!(layout.children[0].x, 0.0000);
1216 assert_eq!(layout.children[0].y, 100.0000);
1217 }
1218
1219 #[test]
1220 fn absolute_layout_width_height_start_top_end_bottom() {
1221 let layout = stretch::compute(&stretch::style::Node {
1222 width: stretch::style::Dimension::Points(100.0000),
1223 height: stretch::style::Dimension::Points(100.0000),
1224 children: vec![stretch::style::Node {
1225 position: stretch::style::Position::Absolute,
1226 width: stretch::style::Dimension::Points(10.0000),
1227 height: stretch::style::Dimension::Points(10.0000),
1228 start: stretch::style::Dimension::Points(10.0000),
1229 end: stretch::style::Dimension::Points(10.0000),
1230 top: stretch::style::Dimension::Points(10.0000),
1231 bottom: stretch::style::Dimension::Points(10.0000),
1232 ..Default::default()
1233 }],
1234 ..Default::default()
1235 });
1236
1237 assert_eq!(layout.width, 100.0000);
1238 assert_eq!(layout.height, 100.0000);
1239 assert_eq!(layout.x, 0.0000);
1240 assert_eq!(layout.y, 0.0000);
1241
1242 assert_eq!(layout.children[0].width, 10.0000);
1243 assert_eq!(layout.children[0].height, 10.0000);
1244 assert_eq!(layout.children[0].x, 10.0000);
1245 assert_eq!(layout.children[0].y, 10.0000);
1246 }
1247
1248 #[test]
1249 fn overflow_main_axis() {
1250 let layout = stretch::compute(&stretch::style::Node {
1251 width: stretch::style::Dimension::Points(100.0000),
1252 height: stretch::style::Dimension::Points(100.0000),
1253 children: vec![stretch::style::Node {
1254 flex_shrink: 0.0000,
1255 width: stretch::style::Dimension::Points(200.0000),
1256 ..Default::default()
1257 }],
1258 ..Default::default()
1259 });
1260
1261 assert_eq!(layout.width, 100.0000);
1262 assert_eq!(layout.height, 100.0000);
1263 assert_eq!(layout.x, 0.0000);
1264 assert_eq!(layout.y, 0.0000);
1265
1266 assert_eq!(layout.children[0].width, 200.0000);
1267 assert_eq!(layout.children[0].height, 100.0000);
1268 assert_eq!(layout.children[0].x, 0.0000);
1269 assert_eq!(layout.children[0].y, 0.0000);
1270 }
1271
1272 #[test]
1273 fn flex_grow_to_min() {
1274 let layout = stretch::compute(&stretch::style::Node {
1275 flex_direction: stretch::style::FlexDirection::Column,
1276 width: stretch::style::Dimension::Points(100.0000),
1277 min_height: stretch::style::Dimension::Points(100.0000),
1278 max_height: stretch::style::Dimension::Points(500.0000),
1279 children: vec![
1280 stretch::style::Node { flex_grow: 1.0000, flex_shrink: 1.0000, ..Default::default() },
1281 stretch::style::Node { height: stretch::style::Dimension::Points(50.0000), ..Default::default() },
1282 ],
1283 ..Default::default()
1284 });
1285
1286 assert_eq!(layout.width, 100.0000);
1287 assert_eq!(layout.height, 100.0000);
1288 assert_eq!(layout.x, 0.0000);
1289 assert_eq!(layout.y, 0.0000);
1290
1291 assert_eq!(layout.children[0].width, 100.0000);
1292 assert_eq!(layout.children[0].height, 50.0000);
1293 assert_eq!(layout.children[0].x, 0.0000);
1294 assert_eq!(layout.children[0].y, 0.0000);
1295
1296 assert_eq!(layout.children[1].width, 100.0000);
1297 assert_eq!(layout.children[1].height, 50.0000);
1298 assert_eq!(layout.children[1].x, 0.0000);
1299 assert_eq!(layout.children[1].y, 50.0000);
1300 }
1301
1302 #[test]
1303 fn absolute_layout_align_items_and_justify_content_center_and_top_position() {
1304 let layout = stretch::compute(&stretch::style::Node {
1305 align_items: stretch::style::AlignItems::Center,
1306 justify_content: stretch::style::JustifyContent::Center,
1307 width: stretch::style::Dimension::Points(110.0000),
1308 height: stretch::style::Dimension::Points(100.0000),
1309 children: vec![stretch::style::Node {
1310 position: stretch::style::Position::Absolute,
1311 width: stretch::style::Dimension::Points(60.0000),
1312 height: stretch::style::Dimension::Points(40.0000),
1313 top: stretch::style::Dimension::Points(10.0000),
1314 ..Default::default()
1315 }],
1316 ..Default::default()
1317 });
1318
1319 assert_eq!(layout.width, 110.0000);
1320 assert_eq!(layout.height, 100.0000);
1321 assert_eq!(layout.x, 0.0000);
1322 assert_eq!(layout.y, 0.0000);
1323
1324 assert_eq!(layout.children[0].width, 60.0000);
1325 assert_eq!(layout.children[0].height, 40.0000);
1326 assert_eq!(layout.children[0].x, 25.0000);
1327 assert_eq!(layout.children[0].y, 10.0000);
1328 }
1329
1330 #[test]
1331 fn min_height() {
1332 let layout = stretch::compute(&stretch::style::Node {
1333 flex_direction: stretch::style::FlexDirection::Column,
1334 width: stretch::style::Dimension::Points(100.0000),
1335 height: stretch::style::Dimension::Points(100.0000),
1336 children: vec![
1337 stretch::style::Node {
1338 flex_grow: 1.0000,
1339 min_height: stretch::style::Dimension::Points(60.0000),
1340 ..Default::default()
1341 },
1342 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
1343 ],
1344 ..Default::default()
1345 });
1346
1347 assert_eq!(layout.width, 100.0000);
1348 assert_eq!(layout.height, 100.0000);
1349 assert_eq!(layout.x, 0.0000);
1350 assert_eq!(layout.y, 0.0000);
1351
1352 assert_eq!(layout.children[0].width, 100.0000);
1353 assert_eq!(layout.children[0].height, 80.0000);
1354 assert_eq!(layout.children[0].x, 0.0000);
1355 assert_eq!(layout.children[0].y, 0.0000);
1356
1357 assert_eq!(layout.children[1].width, 100.0000);
1358 assert_eq!(layout.children[1].height, 20.0000);
1359 assert_eq!(layout.children[1].x, 0.0000);
1360 assert_eq!(layout.children[1].y, 80.0000);
1361 }
1362
1363 #[test]
1364 fn justify_content_column_flex_start() {
1365 let layout = stretch::compute(&stretch::style::Node {
1366 flex_direction: stretch::style::FlexDirection::Column,
1367 width: stretch::style::Dimension::Points(100.0000),
1368 height: stretch::style::Dimension::Points(100.0000),
1369 children: vec![
1370 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
1371 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
1372 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
1373 ],
1374 ..Default::default()
1375 });
1376
1377 assert_eq!(layout.width, 100.0000);
1378 assert_eq!(layout.height, 100.0000);
1379 assert_eq!(layout.x, 0.0000);
1380 assert_eq!(layout.y, 0.0000);
1381
1382 assert_eq!(layout.children[0].width, 100.0000);
1383 assert_eq!(layout.children[0].height, 10.0000);
1384 assert_eq!(layout.children[0].x, 0.0000);
1385 assert_eq!(layout.children[0].y, 0.0000);
1386
1387 assert_eq!(layout.children[1].width, 100.0000);
1388 assert_eq!(layout.children[1].height, 10.0000);
1389 assert_eq!(layout.children[1].x, 0.0000);
1390 assert_eq!(layout.children[1].y, 10.0000);
1391
1392 assert_eq!(layout.children[2].width, 100.0000);
1393 assert_eq!(layout.children[2].height, 10.0000);
1394 assert_eq!(layout.children[2].x, 0.0000);
1395 assert_eq!(layout.children[2].y, 20.0000);
1396 }
1397
1398 #[test]
1399 fn absolute_layout_in_wrap_reverse_column_container() {
1400 let layout = stretch::compute(&stretch::style::Node {
1401 flex_direction: stretch::style::FlexDirection::Column,
1402 flex_wrap: stretch::style::FlexWrap::WrapReverse,
1403 width: stretch::style::Dimension::Points(100.0000),
1404 height: stretch::style::Dimension::Points(100.0000),
1405 children: vec![stretch::style::Node {
1406 position: stretch::style::Position::Absolute,
1407 width: stretch::style::Dimension::Points(20.0000),
1408 height: stretch::style::Dimension::Points(20.0000),
1409 ..Default::default()
1410 }],
1411 ..Default::default()
1412 });
1413
1414 assert_eq!(layout.width, 100.0000);
1415 assert_eq!(layout.height, 100.0000);
1416 assert_eq!(layout.x, 0.0000);
1417 assert_eq!(layout.y, 0.0000);
1418
1419 assert_eq!(layout.children[0].width, 20.0000);
1420 assert_eq!(layout.children[0].height, 20.0000);
1421 assert_eq!(layout.children[0].x, 80.0000);
1422 assert_eq!(layout.children[0].y, 0.0000);
1423 }
1424
1425 #[test]
1426 fn margin_should_not_be_part_of_max_width() {
1427 let layout = stretch::compute(&stretch::style::Node {
1428 width: stretch::style::Dimension::Points(250.0000),
1429 height: stretch::style::Dimension::Points(250.0000),
1430 children: vec![stretch::style::Node {
1431 width: stretch::style::Dimension::Points(100.0000),
1432 max_width: stretch::style::Dimension::Points(100.0000),
1433 height: stretch::style::Dimension::Points(100.0000),
1434 margin: stretch::style::Edges {
1435 start: stretch::style::Dimension::Points(20.0000),
1436 ..Default::default()
1437 },
1438 ..Default::default()
1439 }],
1440 ..Default::default()
1441 });
1442
1443 assert_eq!(layout.width, 250.0000);
1444 assert_eq!(layout.height, 250.0000);
1445 assert_eq!(layout.x, 0.0000);
1446 assert_eq!(layout.y, 0.0000);
1447
1448 assert_eq!(layout.children[0].width, 100.0000);
1449 assert_eq!(layout.children[0].height, 100.0000);
1450 assert_eq!(layout.children[0].x, 20.0000);
1451 assert_eq!(layout.children[0].y, 0.0000);
1452 }
1453
1454 #[test]
1455 fn border_flex_child() {
1456 let layout = stretch::compute(&stretch::style::Node {
1457 width: stretch::style::Dimension::Points(100.0000),
1458 height: stretch::style::Dimension::Points(100.0000),
1459 border: stretch::style::Edges {
1460 start: stretch::style::Dimension::Points(10.0000),
1461 end: stretch::style::Dimension::Points(10.0000),
1462 top: stretch::style::Dimension::Points(10.0000),
1463 bottom: stretch::style::Dimension::Points(10.0000),
1464 ..Default::default()
1465 },
1466 children: vec![stretch::style::Node {
1467 flex_grow: 1.0000,
1468 width: stretch::style::Dimension::Points(10.0000),
1469 ..Default::default()
1470 }],
1471 ..Default::default()
1472 });
1473
1474 assert_eq!(layout.width, 100.0000);
1475 assert_eq!(layout.height, 100.0000);
1476 assert_eq!(layout.x, 0.0000);
1477 assert_eq!(layout.y, 0.0000);
1478
1479 assert_eq!(layout.children[0].width, 80.0000);
1480 assert_eq!(layout.children[0].height, 80.0000);
1481 assert_eq!(layout.children[0].x, 10.0000);
1482 assert_eq!(layout.children[0].y, 10.0000);
1483 }
1484
1485 #[test]
1486 fn wrap_reverse_row() {
1487 let layout = stretch::compute(&stretch::style::Node {
1488 flex_wrap: stretch::style::FlexWrap::WrapReverse,
1489 width: stretch::style::Dimension::Points(100.0000),
1490 children: vec![
1491 stretch::style::Node {
1492 width: stretch::style::Dimension::Points(31.0000),
1493 height: stretch::style::Dimension::Points(30.0000),
1494 ..Default::default()
1495 },
1496 stretch::style::Node {
1497 width: stretch::style::Dimension::Points(32.0000),
1498 height: stretch::style::Dimension::Points(30.0000),
1499 ..Default::default()
1500 },
1501 stretch::style::Node {
1502 width: stretch::style::Dimension::Points(33.0000),
1503 height: stretch::style::Dimension::Points(30.0000),
1504 ..Default::default()
1505 },
1506 stretch::style::Node {
1507 width: stretch::style::Dimension::Points(34.0000),
1508 height: stretch::style::Dimension::Points(30.0000),
1509 ..Default::default()
1510 },
1511 ],
1512 ..Default::default()
1513 });
1514
1515 assert_eq!(layout.width, 100.0000);
1516 assert_eq!(layout.height, 60.0000);
1517 assert_eq!(layout.x, 0.0000);
1518 assert_eq!(layout.y, 0.0000);
1519
1520 assert_eq!(layout.children[0].width, 31.0000);
1521 assert_eq!(layout.children[0].height, 30.0000);
1522 assert_eq!(layout.children[0].x, 0.0000);
1523 assert_eq!(layout.children[0].y, 30.0000);
1524
1525 assert_eq!(layout.children[1].width, 32.0000);
1526 assert_eq!(layout.children[1].height, 30.0000);
1527 assert_eq!(layout.children[1].x, 31.0000);
1528 assert_eq!(layout.children[1].y, 30.0000);
1529
1530 assert_eq!(layout.children[2].width, 33.0000);
1531 assert_eq!(layout.children[2].height, 30.0000);
1532 assert_eq!(layout.children[2].x, 63.0000);
1533 assert_eq!(layout.children[2].y, 30.0000);
1534
1535 assert_eq!(layout.children[3].width, 34.0000);
1536 assert_eq!(layout.children[3].height, 30.0000);
1537 assert_eq!(layout.children[3].x, 0.0000);
1538 assert_eq!(layout.children[3].y, 0.0000);
1539 }
1540
1541 #[test]
1542 fn margin_right() {
1543 let layout = stretch::compute(&stretch::style::Node {
1544 justify_content: stretch::style::JustifyContent::FlexEnd,
1545 width: stretch::style::Dimension::Points(100.0000),
1546 height: stretch::style::Dimension::Points(100.0000),
1547 children: vec![stretch::style::Node {
1548 width: stretch::style::Dimension::Points(10.0000),
1549 margin: stretch::style::Edges { end: stretch::style::Dimension::Points(10.0000), ..Default::default() },
1550 ..Default::default()
1551 }],
1552 ..Default::default()
1553 });
1554
1555 assert_eq!(layout.width, 100.0000);
1556 assert_eq!(layout.height, 100.0000);
1557 assert_eq!(layout.x, 0.0000);
1558 assert_eq!(layout.y, 0.0000);
1559
1560 assert_eq!(layout.children[0].width, 10.0000);
1561 assert_eq!(layout.children[0].height, 100.0000);
1562 assert_eq!(layout.children[0].x, 80.0000);
1563 assert_eq!(layout.children[0].y, 0.0000);
1564 }
1565
1566 #[test]
1567 fn align_flex_start_with_shrinking_children_with_stretch() {
1568 let layout = stretch::compute(&stretch::style::Node {
1569 width: stretch::style::Dimension::Points(500.0000),
1570 height: stretch::style::Dimension::Points(500.0000),
1571 children: vec![stretch::style::Node {
1572 align_items: stretch::style::AlignItems::FlexStart,
1573 children: vec![stretch::style::Node {
1574 flex_grow: 1.0000,
1575 flex_shrink: 1.0000,
1576 children: vec![stretch::style::Node {
1577 flex_grow: 1.0000,
1578 flex_shrink: 1.0000,
1579 ..Default::default()
1580 }],
1581 ..Default::default()
1582 }],
1583 ..Default::default()
1584 }],
1585 ..Default::default()
1586 });
1587
1588 assert_eq!(layout.width, 500.0000);
1589 assert_eq!(layout.height, 500.0000);
1590 assert_eq!(layout.x, 0.0000);
1591 assert_eq!(layout.y, 0.0000);
1592
1593 assert_eq!(layout.children[0].width, 0.0000);
1594 assert_eq!(layout.children[0].height, 500.0000);
1595 assert_eq!(layout.children[0].x, 0.0000);
1596 assert_eq!(layout.children[0].y, 0.0000);
1597
1598 assert_eq!(layout.children[0].children[0].width, 0.0000);
1599 assert_eq!(layout.children[0].children[0].height, 0.0000);
1600 assert_eq!(layout.children[0].children[0].x, 0.0000);
1601 assert_eq!(layout.children[0].children[0].y, 0.0000);
1602
1603 assert_eq!(layout.children[0].children[0].children[0].width, 0.0000);
1604 assert_eq!(layout.children[0].children[0].children[0].height, 0.0000);
1605 assert_eq!(layout.children[0].children[0].children[0].x, 0.0000);
1606 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
1607 }
1608
1609 #[test]
1610 fn flex_basis_smaller_then_content_with_flex_grow_large_size() {
1611 let layout = stretch::compute(&stretch::style::Node {
1612 width: stretch::style::Dimension::Points(100.0000),
1613 children: vec![
1614 stretch::style::Node {
1615 flex_direction: stretch::style::FlexDirection::Column,
1616 flex_grow: 1.0000,
1617 flex_basis: stretch::style::Dimension::Points(0.0000),
1618 children: vec![stretch::style::Node {
1619 width: stretch::style::Dimension::Points(70.0000),
1620 height: stretch::style::Dimension::Points(100.0000),
1621 ..Default::default()
1622 }],
1623 ..Default::default()
1624 },
1625 stretch::style::Node {
1626 flex_direction: stretch::style::FlexDirection::Column,
1627 flex_grow: 1.0000,
1628 flex_basis: stretch::style::Dimension::Points(0.0000),
1629 children: vec![stretch::style::Node {
1630 width: stretch::style::Dimension::Points(20.0000),
1631 height: stretch::style::Dimension::Points(100.0000),
1632 ..Default::default()
1633 }],
1634 ..Default::default()
1635 },
1636 ],
1637 ..Default::default()
1638 });
1639
1640 assert_eq!(layout.width, 100.0000);
1641 assert_eq!(layout.height, 100.0000);
1642 assert_eq!(layout.x, 0.0000);
1643 assert_eq!(layout.y, 0.0000);
1644
1645 assert_eq!(layout.children[0].width, 70.0000);
1646 assert_eq!(layout.children[0].height, 100.0000);
1647 assert_eq!(layout.children[0].x, 0.0000);
1648 assert_eq!(layout.children[0].y, 0.0000);
1649
1650 assert_eq!(layout.children[0].children[0].width, 70.0000);
1651 assert_eq!(layout.children[0].children[0].height, 100.0000);
1652 assert_eq!(layout.children[0].children[0].x, 0.0000);
1653 assert_eq!(layout.children[0].children[0].y, 0.0000);
1654
1655 assert_eq!(layout.children[1].width, 30.0000);
1656 assert_eq!(layout.children[1].height, 100.0000);
1657 assert_eq!(layout.children[1].x, 70.0000);
1658 assert_eq!(layout.children[1].y, 0.0000);
1659
1660 assert_eq!(layout.children[1].children[0].width, 20.0000);
1661 assert_eq!(layout.children[1].children[0].height, 100.0000);
1662 assert_eq!(layout.children[1].children[0].x, 0.0000);
1663 assert_eq!(layout.children[1].children[0].y, 0.0000);
1664 }
1665
1666 #[test]
1667 fn align_items_stretch() {
1668 let layout = stretch::compute(&stretch::style::Node {
1669 width: stretch::style::Dimension::Points(100.0000),
1670 height: stretch::style::Dimension::Points(100.0000),
1671 children: vec![stretch::style::Node {
1672 width: stretch::style::Dimension::Points(10.0000),
1673 ..Default::default()
1674 }],
1675 ..Default::default()
1676 });
1677
1678 assert_eq!(layout.width, 100.0000);
1679 assert_eq!(layout.height, 100.0000);
1680 assert_eq!(layout.x, 0.0000);
1681 assert_eq!(layout.y, 0.0000);
1682
1683 assert_eq!(layout.children[0].width, 10.0000);
1684 assert_eq!(layout.children[0].height, 100.0000);
1685 assert_eq!(layout.children[0].x, 0.0000);
1686 assert_eq!(layout.children[0].y, 0.0000);
1687 }
1688
1689 #[test]
1690 fn parent_wrap_child_size_overflowing_parent() {
1691 let layout = stretch::compute(&stretch::style::Node {
1692 width: stretch::style::Dimension::Points(100.0000),
1693 height: stretch::style::Dimension::Points(100.0000),
1694 children: vec![stretch::style::Node {
1695 width: stretch::style::Dimension::Points(100.0000),
1696 children: vec![stretch::style::Node {
1697 width: stretch::style::Dimension::Points(100.0000),
1698 height: stretch::style::Dimension::Points(200.0000),
1699 ..Default::default()
1700 }],
1701 ..Default::default()
1702 }],
1703 ..Default::default()
1704 });
1705
1706 assert_eq!(layout.width, 100.0000);
1707 assert_eq!(layout.height, 100.0000);
1708 assert_eq!(layout.x, 0.0000);
1709 assert_eq!(layout.y, 0.0000);
1710
1711 assert_eq!(layout.children[0].width, 100.0000);
1712 assert_eq!(layout.children[0].height, 100.0000);
1713 assert_eq!(layout.children[0].x, 0.0000);
1714 assert_eq!(layout.children[0].y, 0.0000);
1715
1716 assert_eq!(layout.children[0].children[0].width, 100.0000);
1717 assert_eq!(layout.children[0].children[0].height, 200.0000);
1718 assert_eq!(layout.children[0].children[0].x, 0.0000);
1719 assert_eq!(layout.children[0].children[0].y, 0.0000);
1720 }
1721
1722 #[test]
1723 fn padding_stretch_child() {
1724 let layout = stretch::compute(&stretch::style::Node {
1725 width: stretch::style::Dimension::Points(100.0000),
1726 height: stretch::style::Dimension::Points(100.0000),
1727 padding: stretch::style::Edges {
1728 start: stretch::style::Dimension::Points(10.0000),
1729 end: stretch::style::Dimension::Points(10.0000),
1730 top: stretch::style::Dimension::Points(10.0000),
1731 bottom: stretch::style::Dimension::Points(10.0000),
1732 ..Default::default()
1733 },
1734 children: vec![stretch::style::Node {
1735 height: stretch::style::Dimension::Points(10.0000),
1736 ..Default::default()
1737 }],
1738 ..Default::default()
1739 });
1740
1741 assert_eq!(layout.width, 100.0000);
1742 assert_eq!(layout.height, 100.0000);
1743 assert_eq!(layout.x, 0.0000);
1744 assert_eq!(layout.y, 0.0000);
1745
1746 assert_eq!(layout.children[0].width, 0.0000);
1747 assert_eq!(layout.children[0].height, 10.0000);
1748 assert_eq!(layout.children[0].x, 10.0000);
1749 assert_eq!(layout.children[0].y, 10.0000);
1750 }
1751
1752 #[test]
1753 fn wrap_nodes_with_content_sizing_overflowing_margin() {
1754 let layout = stretch::compute(&stretch::style::Node {
1755 flex_direction: stretch::style::FlexDirection::Column,
1756 width: stretch::style::Dimension::Points(500.0000),
1757 height: stretch::style::Dimension::Points(500.0000),
1758 children: vec![stretch::style::Node {
1759 flex_wrap: stretch::style::FlexWrap::Wrap,
1760 width: stretch::style::Dimension::Points(85.0000),
1761 children: vec![
1762 stretch::style::Node {
1763 flex_direction: stretch::style::FlexDirection::Column,
1764 children: vec![stretch::style::Node {
1765 width: stretch::style::Dimension::Points(40.0000),
1766 height: stretch::style::Dimension::Points(40.0000),
1767 ..Default::default()
1768 }],
1769 ..Default::default()
1770 },
1771 stretch::style::Node {
1772 flex_direction: stretch::style::FlexDirection::Column,
1773 margin: stretch::style::Edges {
1774 end: stretch::style::Dimension::Points(10.0000),
1775 ..Default::default()
1776 },
1777 children: vec![stretch::style::Node {
1778 width: stretch::style::Dimension::Points(40.0000),
1779 height: stretch::style::Dimension::Points(40.0000),
1780 ..Default::default()
1781 }],
1782 ..Default::default()
1783 },
1784 ],
1785 ..Default::default()
1786 }],
1787 ..Default::default()
1788 });
1789
1790 assert_eq!(layout.width, 500.0000);
1791 assert_eq!(layout.height, 500.0000);
1792 assert_eq!(layout.x, 0.0000);
1793 assert_eq!(layout.y, 0.0000);
1794
1795 assert_eq!(layout.children[0].width, 85.0000);
1796 assert_eq!(layout.children[0].height, 80.0000);
1797 assert_eq!(layout.children[0].x, 0.0000);
1798 assert_eq!(layout.children[0].y, 0.0000);
1799
1800 assert_eq!(layout.children[0].children[0].width, 40.0000);
1801 assert_eq!(layout.children[0].children[0].height, 40.0000);
1802 assert_eq!(layout.children[0].children[0].x, 0.0000);
1803 assert_eq!(layout.children[0].children[0].y, 0.0000);
1804
1805 assert_eq!(layout.children[0].children[0].children[0].width, 40.0000);
1806 assert_eq!(layout.children[0].children[0].children[0].height, 40.0000);
1807 assert_eq!(layout.children[0].children[0].children[0].x, 0.0000);
1808 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
1809
1810 assert_eq!(layout.children[0].children[1].width, 40.0000);
1811 assert_eq!(layout.children[0].children[1].height, 40.0000);
1812 assert_eq!(layout.children[0].children[1].x, 0.0000);
1813 assert_eq!(layout.children[0].children[1].y, 40.0000);
1814
1815 assert_eq!(layout.children[0].children[1].children[0].width, 40.0000);
1816 assert_eq!(layout.children[0].children[1].children[0].height, 40.0000);
1817 assert_eq!(layout.children[0].children[1].children[0].x, 0.0000);
1818 assert_eq!(layout.children[0].children[1].children[0].y, 0.0000);
1819 }
1820
1821 #[test]
1822 fn flex_shrink_flex_grow_row() {
1823 let layout = stretch::compute(&stretch::style::Node {
1824 width: stretch::style::Dimension::Points(500.0000),
1825 height: stretch::style::Dimension::Points(500.0000),
1826 children: vec![
1827 stretch::style::Node {
1828 flex_grow: 0.0000,
1829 flex_shrink: 1.0000,
1830 width: stretch::style::Dimension::Points(500.0000),
1831 height: stretch::style::Dimension::Points(100.0000),
1832 ..Default::default()
1833 },
1834 stretch::style::Node {
1835 flex_grow: 0.0000,
1836 flex_shrink: 1.0000,
1837 width: stretch::style::Dimension::Points(500.0000),
1838 height: stretch::style::Dimension::Points(100.0000),
1839 ..Default::default()
1840 },
1841 ],
1842 ..Default::default()
1843 });
1844
1845 assert_eq!(layout.width, 500.0000);
1846 assert_eq!(layout.height, 500.0000);
1847 assert_eq!(layout.x, 0.0000);
1848 assert_eq!(layout.y, 0.0000);
1849
1850 assert_eq!(layout.children[0].width, 250.0000);
1851 assert_eq!(layout.children[0].height, 100.0000);
1852 assert_eq!(layout.children[0].x, 0.0000);
1853 assert_eq!(layout.children[0].y, 0.0000);
1854
1855 assert_eq!(layout.children[1].width, 250.0000);
1856 assert_eq!(layout.children[1].height, 100.0000);
1857 assert_eq!(layout.children[1].x, 250.0000);
1858 assert_eq!(layout.children[1].y, 0.0000);
1859 }
1860
1861 #[test]
1862 fn flex_basis_flex_shrink_column() {
1863 let layout = stretch::compute(&stretch::style::Node {
1864 flex_direction: stretch::style::FlexDirection::Column,
1865 width: stretch::style::Dimension::Points(100.0000),
1866 height: stretch::style::Dimension::Points(100.0000),
1867 children: vec![
1868 stretch::style::Node { flex_basis: stretch::style::Dimension::Points(100.0000), ..Default::default() },
1869 stretch::style::Node { flex_basis: stretch::style::Dimension::Points(50.0000), ..Default::default() },
1870 ],
1871 ..Default::default()
1872 });
1873
1874 assert_eq!(layout.width, 100.0000);
1875 assert_eq!(layout.height, 100.0000);
1876 assert_eq!(layout.x, 0.0000);
1877 assert_eq!(layout.y, 0.0000);
1878
1879 assert_eq!(layout.children[0].width, 100.0000);
1880 assert_eq!(layout.children[0].height, 67.0000);
1881 assert_eq!(layout.children[0].x, 0.0000);
1882 assert_eq!(layout.children[0].y, 0.0000);
1883
1884 assert_eq!(layout.children[1].width, 100.0000);
1885 assert_eq!(layout.children[1].height, 33.0000);
1886 assert_eq!(layout.children[1].x, 0.0000);
1887 assert_eq!(layout.children[1].y, 67.0000);
1888 }
1889
1890 #[test]
1891 fn align_items_min_max() {
1892 let layout = stretch::compute(&stretch::style::Node {
1893 flex_direction: stretch::style::FlexDirection::Column,
1894 align_items: stretch::style::AlignItems::Center,
1895 min_width: stretch::style::Dimension::Points(100.0000),
1896 max_width: stretch::style::Dimension::Points(200.0000),
1897 height: stretch::style::Dimension::Points(100.0000),
1898 children: vec![stretch::style::Node {
1899 width: stretch::style::Dimension::Points(60.0000),
1900 height: stretch::style::Dimension::Points(60.0000),
1901 ..Default::default()
1902 }],
1903 ..Default::default()
1904 });
1905
1906 assert_eq!(layout.width, 100.0000);
1907 assert_eq!(layout.height, 100.0000);
1908 assert_eq!(layout.x, 0.0000);
1909 assert_eq!(layout.y, 0.0000);
1910
1911 assert_eq!(layout.children[0].width, 60.0000);
1912 assert_eq!(layout.children[0].height, 60.0000);
1913 assert_eq!(layout.children[0].x, 20.0000);
1914 assert_eq!(layout.children[0].y, 0.0000);
1915 }
1916
1917 #[test]
1918 fn flex_basis_smaller_then_content_with_flex_grow_unconstraint_size() {
1919 let layout = stretch::compute(&stretch::style::Node {
1920 children: vec![
1921 stretch::style::Node {
1922 flex_direction: stretch::style::FlexDirection::Column,
1923 flex_grow: 1.0000,
1924 flex_basis: stretch::style::Dimension::Points(0.0000),
1925 children: vec![stretch::style::Node {
1926 width: stretch::style::Dimension::Points(70.0000),
1927 height: stretch::style::Dimension::Points(100.0000),
1928 ..Default::default()
1929 }],
1930 ..Default::default()
1931 },
1932 stretch::style::Node {
1933 flex_direction: stretch::style::FlexDirection::Column,
1934 flex_grow: 1.0000,
1935 flex_basis: stretch::style::Dimension::Points(0.0000),
1936 children: vec![stretch::style::Node {
1937 width: stretch::style::Dimension::Points(20.0000),
1938 height: stretch::style::Dimension::Points(100.0000),
1939 ..Default::default()
1940 }],
1941 ..Default::default()
1942 },
1943 ],
1944 ..Default::default()
1945 });
1946
1947 assert_eq!(layout.width, 90.0000);
1948 assert_eq!(layout.height, 100.0000);
1949 assert_eq!(layout.x, 0.0000);
1950 assert_eq!(layout.y, 0.0000);
1951
1952 assert_eq!(layout.children[0].width, 70.0000);
1953 assert_eq!(layout.children[0].height, 100.0000);
1954 assert_eq!(layout.children[0].x, 0.0000);
1955 assert_eq!(layout.children[0].y, 0.0000);
1956
1957 assert_eq!(layout.children[0].children[0].width, 70.0000);
1958 assert_eq!(layout.children[0].children[0].height, 100.0000);
1959 assert_eq!(layout.children[0].children[0].x, 0.0000);
1960 assert_eq!(layout.children[0].children[0].y, 0.0000);
1961
1962 assert_eq!(layout.children[1].width, 20.0000);
1963 assert_eq!(layout.children[1].height, 100.0000);
1964 assert_eq!(layout.children[1].x, 70.0000);
1965 assert_eq!(layout.children[1].y, 0.0000);
1966
1967 assert_eq!(layout.children[1].children[0].width, 20.0000);
1968 assert_eq!(layout.children[1].children[0].height, 100.0000);
1969 assert_eq!(layout.children[1].children[0].x, 0.0000);
1970 assert_eq!(layout.children[1].children[0].y, 0.0000);
1971 }
1972
1973 #[test]
1974 fn justify_content_row_min_width_and_margin() {
1975 let layout = stretch::compute(&stretch::style::Node {
1976 justify_content: stretch::style::JustifyContent::Center,
1977 min_width: stretch::style::Dimension::Points(50.0000),
1978 children: vec![stretch::style::Node {
1979 width: stretch::style::Dimension::Points(20.0000),
1980 height: stretch::style::Dimension::Points(20.0000),
1981 margin: stretch::style::Edges {
1982 start: stretch::style::Dimension::Points(10.0000),
1983 ..Default::default()
1984 },
1985 ..Default::default()
1986 }],
1987 ..Default::default()
1988 });
1989
1990 assert_eq!(layout.width, 50.0000);
1991 assert_eq!(layout.height, 20.0000);
1992 assert_eq!(layout.x, 0.0000);
1993 assert_eq!(layout.y, 0.0000);
1994
1995 assert_eq!(layout.children[0].width, 20.0000);
1996 assert_eq!(layout.children[0].height, 20.0000);
1997 assert_eq!(layout.children[0].x, 20.0000);
1998 assert_eq!(layout.children[0].y, 0.0000);
1999 }
2000
2001 #[test]
2002 fn align_self_flex_start() {
2003 let layout = stretch::compute(&stretch::style::Node {
2004 width: stretch::style::Dimension::Points(100.0000),
2005 height: stretch::style::Dimension::Points(100.0000),
2006 children: vec![stretch::style::Node {
2007 align_self: stretch::style::AlignSelf::FlexStart,
2008 width: stretch::style::Dimension::Points(10.0000),
2009 height: stretch::style::Dimension::Points(10.0000),
2010 ..Default::default()
2011 }],
2012 ..Default::default()
2013 });
2014
2015 assert_eq!(layout.width, 100.0000);
2016 assert_eq!(layout.height, 100.0000);
2017 assert_eq!(layout.x, 0.0000);
2018 assert_eq!(layout.y, 0.0000);
2019
2020 assert_eq!(layout.children[0].width, 10.0000);
2021 assert_eq!(layout.children[0].height, 10.0000);
2022 assert_eq!(layout.children[0].x, 0.0000);
2023 assert_eq!(layout.children[0].y, 0.0000);
2024 }
2025
2026 #[test]
2027 fn percentage_position_left_top() {
2028 let layout = stretch::compute(&stretch::style::Node {
2029 width: stretch::style::Dimension::Points(400.0000),
2030 height: stretch::style::Dimension::Points(400.0000),
2031 children: vec![stretch::style::Node {
2032 width: stretch::style::Dimension::Percent(0.4500),
2033 height: stretch::style::Dimension::Percent(0.5500),
2034 start: stretch::style::Dimension::Percent(0.1000),
2035 top: stretch::style::Dimension::Percent(0.2000),
2036 ..Default::default()
2037 }],
2038 ..Default::default()
2039 });
2040
2041 assert_eq!(layout.width, 400.0000);
2042 assert_eq!(layout.height, 400.0000);
2043 assert_eq!(layout.x, 0.0000);
2044 assert_eq!(layout.y, 0.0000);
2045
2046 assert_eq!(layout.children[0].width, 180.0000);
2047 assert_eq!(layout.children[0].height, 220.0000);
2048 assert_eq!(layout.children[0].x, 40.0000);
2049 assert_eq!(layout.children[0].y, 80.0000);
2050 }
2051
2052 #[test]
2053 fn border_stretch_child() {
2054 let layout = stretch::compute(&stretch::style::Node {
2055 width: stretch::style::Dimension::Points(100.0000),
2056 height: stretch::style::Dimension::Points(100.0000),
2057 border: stretch::style::Edges {
2058 start: stretch::style::Dimension::Points(10.0000),
2059 end: stretch::style::Dimension::Points(10.0000),
2060 top: stretch::style::Dimension::Points(10.0000),
2061 bottom: stretch::style::Dimension::Points(10.0000),
2062 ..Default::default()
2063 },
2064 children: vec![stretch::style::Node {
2065 width: stretch::style::Dimension::Points(10.0000),
2066 ..Default::default()
2067 }],
2068 ..Default::default()
2069 });
2070
2071 assert_eq!(layout.width, 100.0000);
2072 assert_eq!(layout.height, 100.0000);
2073 assert_eq!(layout.x, 0.0000);
2074 assert_eq!(layout.y, 0.0000);
2075
2076 assert_eq!(layout.children[0].width, 10.0000);
2077 assert_eq!(layout.children[0].height, 80.0000);
2078 assert_eq!(layout.children[0].x, 10.0000);
2079 assert_eq!(layout.children[0].y, 10.0000);
2080 }
2081
2082 #[test]
2083 fn rounding_fractial_input_2() {
2084 let layout = stretch::compute(&stretch::style::Node {
2085 flex_direction: stretch::style::FlexDirection::Column,
2086 width: stretch::style::Dimension::Points(100.0000),
2087 height: stretch::style::Dimension::Points(113.6000),
2088 children: vec![
2089 stretch::style::Node {
2090 flex_grow: 1.0000,
2091 flex_basis: stretch::style::Dimension::Points(50.0000),
2092 height: stretch::style::Dimension::Points(20.0000),
2093 ..Default::default()
2094 },
2095 stretch::style::Node {
2096 flex_grow: 1.0000,
2097 height: stretch::style::Dimension::Points(10.0000),
2098 ..Default::default()
2099 },
2100 stretch::style::Node {
2101 flex_grow: 1.0000,
2102 height: stretch::style::Dimension::Points(10.0000),
2103 ..Default::default()
2104 },
2105 ],
2106 ..Default::default()
2107 });
2108
2109 assert_eq!(layout.width, 100.0000);
2110 assert_eq!(layout.height, 114.0000);
2111 assert_eq!(layout.x, 0.0000);
2112 assert_eq!(layout.y, 0.0000);
2113
2114 assert_eq!(layout.children[0].width, 100.0000);
2115 assert_eq!(layout.children[0].height, 65.0000);
2116 assert_eq!(layout.children[0].x, 0.0000);
2117 assert_eq!(layout.children[0].y, 0.0000);
2118
2119 assert_eq!(layout.children[1].width, 100.0000);
2120 assert_eq!(layout.children[1].height, 24.0000);
2121 assert_eq!(layout.children[1].x, 0.0000);
2122 assert_eq!(layout.children[1].y, 65.0000);
2123
2124 assert_eq!(layout.children[2].width, 100.0000);
2125 assert_eq!(layout.children[2].height, 25.0000);
2126 assert_eq!(layout.children[2].x, 0.0000);
2127 assert_eq!(layout.children[2].y, 89.0000);
2128 }
2129
2130 #[test]
2131 fn percentage_flex_basis_main_max_width() {
2132 let layout = stretch::compute(&stretch::style::Node {
2133 width: stretch::style::Dimension::Points(200.0000),
2134 height: stretch::style::Dimension::Points(200.0000),
2135 children: vec![
2136 stretch::style::Node {
2137 flex_grow: 1.0000,
2138 flex_basis: stretch::style::Dimension::Percent(0.1500),
2139 max_width: stretch::style::Dimension::Percent(0.6000),
2140 ..Default::default()
2141 },
2142 stretch::style::Node {
2143 flex_grow: 4.0000,
2144 flex_basis: stretch::style::Dimension::Percent(0.1000),
2145 max_width: stretch::style::Dimension::Percent(0.2000),
2146 ..Default::default()
2147 },
2148 ],
2149 ..Default::default()
2150 });
2151
2152 assert_eq!(layout.width, 200.0000);
2153 assert_eq!(layout.height, 200.0000);
2154 assert_eq!(layout.x, 0.0000);
2155 assert_eq!(layout.y, 0.0000);
2156
2157 assert_eq!(layout.children[0].width, 120.0000);
2158 assert_eq!(layout.children[0].height, 200.0000);
2159 assert_eq!(layout.children[0].x, 0.0000);
2160 assert_eq!(layout.children[0].y, 0.0000);
2161
2162 assert_eq!(layout.children[1].width, 40.0000);
2163 assert_eq!(layout.children[1].height, 200.0000);
2164 assert_eq!(layout.children[1].x, 120.0000);
2165 assert_eq!(layout.children[1].y, 0.0000);
2166 }
2167
2168 #[test]
2169 fn margin_auto_top_and_bottom_strech() {
2170 let layout = stretch::compute(&stretch::style::Node {
2171 flex_direction: stretch::style::FlexDirection::Column,
2172 width: stretch::style::Dimension::Points(200.0000),
2173 height: stretch::style::Dimension::Points(200.0000),
2174 children: vec![
2175 stretch::style::Node {
2176 width: stretch::style::Dimension::Points(50.0000),
2177 height: stretch::style::Dimension::Points(50.0000),
2178 margin: stretch::style::Edges {
2179 top: stretch::style::Dimension::Auto,
2180 bottom: stretch::style::Dimension::Auto,
2181 ..Default::default()
2182 },
2183 ..Default::default()
2184 },
2185 stretch::style::Node {
2186 width: stretch::style::Dimension::Points(50.0000),
2187 height: stretch::style::Dimension::Points(50.0000),
2188 ..Default::default()
2189 },
2190 ],
2191 ..Default::default()
2192 });
2193
2194 assert_eq!(layout.width, 200.0000);
2195 assert_eq!(layout.height, 200.0000);
2196 assert_eq!(layout.x, 0.0000);
2197 assert_eq!(layout.y, 0.0000);
2198
2199 assert_eq!(layout.children[0].width, 50.0000);
2200 assert_eq!(layout.children[0].height, 50.0000);
2201 assert_eq!(layout.children[0].x, 0.0000);
2202 assert_eq!(layout.children[0].y, 50.0000);
2203
2204 assert_eq!(layout.children[1].width, 50.0000);
2205 assert_eq!(layout.children[1].height, 50.0000);
2206 assert_eq!(layout.children[1].x, 0.0000);
2207 assert_eq!(layout.children[1].y, 150.0000);
2208 }
2209
2210 #[test]
2211 fn percentage_multiple_nested_with_padding_margin_and_percentage_values() {
2212 let layout = stretch::compute(&stretch::style::Node {
2213 flex_direction: stretch::style::FlexDirection::Column,
2214 width: stretch::style::Dimension::Points(200.0000),
2215 height: stretch::style::Dimension::Points(200.0000),
2216 children: vec![
2217 stretch::style::Node {
2218 flex_direction: stretch::style::FlexDirection::Column,
2219 flex_grow: 1.0000,
2220 flex_basis: stretch::style::Dimension::Percent(0.1000),
2221 min_width: stretch::style::Dimension::Percent(0.6000),
2222 margin: stretch::style::Edges {
2223 start: stretch::style::Dimension::Points(5.0000),
2224 end: stretch::style::Dimension::Points(5.0000),
2225 top: stretch::style::Dimension::Points(5.0000),
2226 bottom: stretch::style::Dimension::Points(5.0000),
2227 ..Default::default()
2228 },
2229 padding: stretch::style::Edges {
2230 start: stretch::style::Dimension::Points(3.0000),
2231 end: stretch::style::Dimension::Points(3.0000),
2232 top: stretch::style::Dimension::Points(3.0000),
2233 bottom: stretch::style::Dimension::Points(3.0000),
2234 ..Default::default()
2235 },
2236 children: vec![stretch::style::Node {
2237 flex_direction: stretch::style::FlexDirection::Column,
2238 width: stretch::style::Dimension::Percent(0.5000),
2239 margin: stretch::style::Edges {
2240 start: stretch::style::Dimension::Points(5.0000),
2241 end: stretch::style::Dimension::Points(5.0000),
2242 top: stretch::style::Dimension::Points(5.0000),
2243 bottom: stretch::style::Dimension::Points(5.0000),
2244 ..Default::default()
2245 },
2246 padding: stretch::style::Edges {
2247 start: stretch::style::Dimension::Percent(0.0300),
2248 end: stretch::style::Dimension::Percent(0.0300),
2249 top: stretch::style::Dimension::Percent(0.0300),
2250 bottom: stretch::style::Dimension::Percent(0.0300),
2251 ..Default::default()
2252 },
2253 children: vec![stretch::style::Node {
2254 width: stretch::style::Dimension::Percent(0.4500),
2255 margin: stretch::style::Edges {
2256 start: stretch::style::Dimension::Percent(0.0500),
2257 end: stretch::style::Dimension::Percent(0.0500),
2258 top: stretch::style::Dimension::Percent(0.0500),
2259 bottom: stretch::style::Dimension::Percent(0.0500),
2260 ..Default::default()
2261 },
2262 padding: stretch::style::Edges {
2263 start: stretch::style::Dimension::Points(3.0000),
2264 end: stretch::style::Dimension::Points(3.0000),
2265 top: stretch::style::Dimension::Points(3.0000),
2266 bottom: stretch::style::Dimension::Points(3.0000),
2267 ..Default::default()
2268 },
2269 ..Default::default()
2270 }],
2271 ..Default::default()
2272 }],
2273 ..Default::default()
2274 },
2275 stretch::style::Node {
2276 flex_grow: 4.0000,
2277 flex_basis: stretch::style::Dimension::Percent(0.1500),
2278 min_width: stretch::style::Dimension::Percent(0.2000),
2279 ..Default::default()
2280 },
2281 ],
2282 ..Default::default()
2283 });
2284
2285 assert_eq!(layout.width, 200.0000);
2286 assert_eq!(layout.height, 200.0000);
2287 assert_eq!(layout.x, 0.0000);
2288 assert_eq!(layout.y, 0.0000);
2289
2290 assert_eq!(layout.children[0].width, 190.0000);
2291 assert_eq!(layout.children[0].height, 48.0000);
2292 assert_eq!(layout.children[0].x, 5.0000);
2293 assert_eq!(layout.children[0].y, 5.0000);
2294
2295 assert_eq!(layout.children[0].children[0].width, 92.0000);
2296 assert_eq!(layout.children[0].children[0].height, 25.0000);
2297 assert_eq!(layout.children[0].children[0].x, 8.0000);
2298 assert_eq!(layout.children[0].children[0].y, 8.0000);
2299
2300 assert_eq!(layout.children[0].children[0].children[0].width, 36.0000);
2301 assert_eq!(layout.children[0].children[0].children[0].height, 6.0000);
2302 assert_eq!(layout.children[0].children[0].children[0].x, 10.0000);
2303 assert_eq!(layout.children[0].children[0].children[0].y, 10.0000);
2304
2305 assert_eq!(layout.children[1].width, 200.0000);
2306 assert_eq!(layout.children[1].height, 142.0000);
2307 assert_eq!(layout.children[1].x, 0.0000);
2308 assert_eq!(layout.children[1].y, 58.0000);
2309 }
2310
2311 #[test]
2312 fn flex_grow_within_constrained_min_column() {
2313 let layout = stretch::compute(&stretch::style::Node {
2314 flex_direction: stretch::style::FlexDirection::Column,
2315 min_height: stretch::style::Dimension::Points(100.0000),
2316 children: vec![
2317 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
2318 stretch::style::Node { height: stretch::style::Dimension::Points(50.0000), ..Default::default() },
2319 ],
2320 ..Default::default()
2321 });
2322
2323 assert_eq!(layout.width, 0.0000);
2324 assert_eq!(layout.height, 100.0000);
2325 assert_eq!(layout.x, 0.0000);
2326 assert_eq!(layout.y, 0.0000);
2327
2328 assert_eq!(layout.children[0].width, 0.0000);
2329 assert_eq!(layout.children[0].height, 50.0000);
2330 assert_eq!(layout.children[0].x, 0.0000);
2331 assert_eq!(layout.children[0].y, 0.0000);
2332
2333 assert_eq!(layout.children[1].width, 0.0000);
2334 assert_eq!(layout.children[1].height, 50.0000);
2335 assert_eq!(layout.children[1].x, 0.0000);
2336 assert_eq!(layout.children[1].y, 50.0000);
2337 }
2338
2339 #[test]
2340 fn flex_grow_in_at_most_container() {
2341 let layout = stretch::compute(&stretch::style::Node {
2342 align_items: stretch::style::AlignItems::FlexStart,
2343 width: stretch::style::Dimension::Points(100.0000),
2344 height: stretch::style::Dimension::Points(100.0000),
2345 children: vec![stretch::style::Node {
2346 children: vec![stretch::style::Node {
2347 flex_grow: 1.0000,
2348 flex_basis: stretch::style::Dimension::Points(0.0000),
2349 ..Default::default()
2350 }],
2351 ..Default::default()
2352 }],
2353 ..Default::default()
2354 });
2355
2356 assert_eq!(layout.width, 100.0000);
2357 assert_eq!(layout.height, 100.0000);
2358 assert_eq!(layout.x, 0.0000);
2359 assert_eq!(layout.y, 0.0000);
2360
2361 assert_eq!(layout.children[0].width, 0.0000);
2362 assert_eq!(layout.children[0].height, 0.0000);
2363 assert_eq!(layout.children[0].x, 0.0000);
2364 assert_eq!(layout.children[0].y, 0.0000);
2365
2366 assert_eq!(layout.children[0].children[0].width, 0.0000);
2367 assert_eq!(layout.children[0].children[0].height, 0.0000);
2368 assert_eq!(layout.children[0].children[0].x, 0.0000);
2369 assert_eq!(layout.children[0].children[0].y, 0.0000);
2370 }
2371
2372 #[test]
2373 fn margin_auto_left() {
2374 let layout = stretch::compute(&stretch::style::Node {
2375 align_items: stretch::style::AlignItems::Center,
2376 width: stretch::style::Dimension::Points(200.0000),
2377 height: stretch::style::Dimension::Points(200.0000),
2378 children: vec![
2379 stretch::style::Node {
2380 width: stretch::style::Dimension::Points(50.0000),
2381 height: stretch::style::Dimension::Points(50.0000),
2382 margin: stretch::style::Edges { start: stretch::style::Dimension::Auto, ..Default::default() },
2383 ..Default::default()
2384 },
2385 stretch::style::Node {
2386 width: stretch::style::Dimension::Points(50.0000),
2387 height: stretch::style::Dimension::Points(50.0000),
2388 ..Default::default()
2389 },
2390 ],
2391 ..Default::default()
2392 });
2393
2394 assert_eq!(layout.width, 200.0000);
2395 assert_eq!(layout.height, 200.0000);
2396 assert_eq!(layout.x, 0.0000);
2397 assert_eq!(layout.y, 0.0000);
2398
2399 assert_eq!(layout.children[0].width, 50.0000);
2400 assert_eq!(layout.children[0].height, 50.0000);
2401 assert_eq!(layout.children[0].x, 100.0000);
2402 assert_eq!(layout.children[0].y, 75.0000);
2403
2404 assert_eq!(layout.children[1].width, 50.0000);
2405 assert_eq!(layout.children[1].height, 50.0000);
2406 assert_eq!(layout.children[1].x, 150.0000);
2407 assert_eq!(layout.children[1].y, 75.0000);
2408 }
2409
2410 #[test]
2411 fn percentage_flex_basis_cross() {
2412 let layout = stretch::compute(&stretch::style::Node {
2413 flex_direction: stretch::style::FlexDirection::Column,
2414 width: stretch::style::Dimension::Points(200.0000),
2415 height: stretch::style::Dimension::Points(200.0000),
2416 children: vec![
2417 stretch::style::Node {
2418 flex_grow: 1.0000,
2419 flex_basis: stretch::style::Dimension::Percent(0.5000),
2420 ..Default::default()
2421 },
2422 stretch::style::Node {
2423 flex_grow: 1.0000,
2424 flex_basis: stretch::style::Dimension::Percent(0.2500),
2425 ..Default::default()
2426 },
2427 ],
2428 ..Default::default()
2429 });
2430
2431 assert_eq!(layout.width, 200.0000);
2432 assert_eq!(layout.height, 200.0000);
2433 assert_eq!(layout.x, 0.0000);
2434 assert_eq!(layout.y, 0.0000);
2435
2436 assert_eq!(layout.children[0].width, 200.0000);
2437 assert_eq!(layout.children[0].height, 125.0000);
2438 assert_eq!(layout.children[0].x, 0.0000);
2439 assert_eq!(layout.children[0].y, 0.0000);
2440
2441 assert_eq!(layout.children[1].width, 200.0000);
2442 assert_eq!(layout.children[1].height, 75.0000);
2443 assert_eq!(layout.children[1].x, 0.0000);
2444 assert_eq!(layout.children[1].y, 125.0000);
2445 }
2446
2447 #[test]
2448 fn percentage_absolute_position() {
2449 let layout = stretch::compute(&stretch::style::Node {
2450 flex_direction: stretch::style::FlexDirection::Column,
2451 width: stretch::style::Dimension::Points(200.0000),
2452 height: stretch::style::Dimension::Points(100.0000),
2453 children: vec![stretch::style::Node {
2454 position: stretch::style::Position::Absolute,
2455 width: stretch::style::Dimension::Points(10.0000),
2456 height: stretch::style::Dimension::Points(10.0000),
2457 start: stretch::style::Dimension::Percent(0.3000),
2458 top: stretch::style::Dimension::Percent(0.1000),
2459 ..Default::default()
2460 }],
2461 ..Default::default()
2462 });
2463
2464 assert_eq!(layout.width, 200.0000);
2465 assert_eq!(layout.height, 100.0000);
2466 assert_eq!(layout.x, 0.0000);
2467 assert_eq!(layout.y, 0.0000);
2468
2469 assert_eq!(layout.children[0].width, 10.0000);
2470 assert_eq!(layout.children[0].height, 10.0000);
2471 assert_eq!(layout.children[0].x, 60.0000);
2472 assert_eq!(layout.children[0].y, 10.0000);
2473 }
2474
2475 #[test]
2476 fn flex_basis_flex_grow_row() {
2477 let layout = stretch::compute(&stretch::style::Node {
2478 width: stretch::style::Dimension::Points(100.0000),
2479 height: stretch::style::Dimension::Points(100.0000),
2480 children: vec![
2481 stretch::style::Node {
2482 flex_grow: 1.0000,
2483 flex_basis: stretch::style::Dimension::Points(50.0000),
2484 ..Default::default()
2485 },
2486 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
2487 ],
2488 ..Default::default()
2489 });
2490
2491 assert_eq!(layout.width, 100.0000);
2492 assert_eq!(layout.height, 100.0000);
2493 assert_eq!(layout.x, 0.0000);
2494 assert_eq!(layout.y, 0.0000);
2495
2496 assert_eq!(layout.children[0].width, 75.0000);
2497 assert_eq!(layout.children[0].height, 100.0000);
2498 assert_eq!(layout.children[0].x, 0.0000);
2499 assert_eq!(layout.children[0].y, 0.0000);
2500
2501 assert_eq!(layout.children[1].width, 25.0000);
2502 assert_eq!(layout.children[1].height, 100.0000);
2503 assert_eq!(layout.children[1].x, 75.0000);
2504 assert_eq!(layout.children[1].y, 0.0000);
2505 }
2506
2507 #[test]
2508 fn absolute_layout_in_wrap_reverse_column_container_flex_end() {
2509 let layout = stretch::compute(&stretch::style::Node {
2510 flex_direction: stretch::style::FlexDirection::Column,
2511 flex_wrap: stretch::style::FlexWrap::WrapReverse,
2512 width: stretch::style::Dimension::Points(100.0000),
2513 height: stretch::style::Dimension::Points(100.0000),
2514 children: vec![stretch::style::Node {
2515 position: stretch::style::Position::Absolute,
2516 align_self: stretch::style::AlignSelf::FlexEnd,
2517 width: stretch::style::Dimension::Points(20.0000),
2518 height: stretch::style::Dimension::Points(20.0000),
2519 ..Default::default()
2520 }],
2521 ..Default::default()
2522 });
2523
2524 assert_eq!(layout.width, 100.0000);
2525 assert_eq!(layout.height, 100.0000);
2526 assert_eq!(layout.x, 0.0000);
2527 assert_eq!(layout.y, 0.0000);
2528
2529 assert_eq!(layout.children[0].width, 20.0000);
2530 assert_eq!(layout.children[0].height, 20.0000);
2531 assert_eq!(layout.children[0].x, 0.0000);
2532 assert_eq!(layout.children[0].y, 0.0000);
2533 }
2534
2535 #[test]
2536 fn justify_content_row_flex_start() {
2537 let layout = stretch::compute(&stretch::style::Node {
2538 width: stretch::style::Dimension::Points(100.0000),
2539 height: stretch::style::Dimension::Points(100.0000),
2540 children: vec![
2541 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
2542 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
2543 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
2544 ],
2545 ..Default::default()
2546 });
2547
2548 assert_eq!(layout.width, 100.0000);
2549 assert_eq!(layout.height, 100.0000);
2550 assert_eq!(layout.x, 0.0000);
2551 assert_eq!(layout.y, 0.0000);
2552
2553 assert_eq!(layout.children[0].width, 10.0000);
2554 assert_eq!(layout.children[0].height, 100.0000);
2555 assert_eq!(layout.children[0].x, 0.0000);
2556 assert_eq!(layout.children[0].y, 0.0000);
2557
2558 assert_eq!(layout.children[1].width, 10.0000);
2559 assert_eq!(layout.children[1].height, 100.0000);
2560 assert_eq!(layout.children[1].x, 10.0000);
2561 assert_eq!(layout.children[1].y, 0.0000);
2562
2563 assert_eq!(layout.children[2].width, 10.0000);
2564 assert_eq!(layout.children[2].height, 100.0000);
2565 assert_eq!(layout.children[2].x, 20.0000);
2566 assert_eq!(layout.children[2].y, 0.0000);
2567 }
2568
2569 #[test]
2570 fn margin_auto_left_right_child_bigger_than_parent() {
2571 let layout = stretch::compute(&stretch::style::Node {
2572 justify_content: stretch::style::JustifyContent::Center,
2573 width: stretch::style::Dimension::Points(52.0000),
2574 height: stretch::style::Dimension::Points(52.0000),
2575 children: vec![stretch::style::Node {
2576 width: stretch::style::Dimension::Points(72.0000),
2577 height: stretch::style::Dimension::Points(72.0000),
2578 margin: stretch::style::Edges {
2579 start: stretch::style::Dimension::Auto,
2580 end: stretch::style::Dimension::Auto,
2581 ..Default::default()
2582 },
2583 ..Default::default()
2584 }],
2585 ..Default::default()
2586 });
2587
2588 assert_eq!(layout.width, 52.0000);
2589 assert_eq!(layout.height, 52.0000);
2590 assert_eq!(layout.x, 0.0000);
2591 assert_eq!(layout.y, 0.0000);
2592
2593 assert_eq!(layout.children[0].width, 52.0000);
2594 assert_eq!(layout.children[0].height, 72.0000);
2595 assert_eq!(layout.children[0].x, 0.0000);
2596 assert_eq!(layout.children[0].y, 0.0000);
2597 }
2598
2599 #[test]
2600 fn flex_basis_larger_than_content_column() {
2601 let layout = stretch::compute(&stretch::style::Node {
2602 flex_direction: stretch::style::FlexDirection::Column,
2603 height: stretch::style::Dimension::Points(100.0000),
2604 children: vec![stretch::style::Node {
2605 flex_direction: stretch::style::FlexDirection::Column,
2606 flex_basis: stretch::style::Dimension::Points(50.0000),
2607 children: vec![stretch::style::Node {
2608 width: stretch::style::Dimension::Points(100.0000),
2609 height: stretch::style::Dimension::Points(10.0000),
2610 ..Default::default()
2611 }],
2612 ..Default::default()
2613 }],
2614 ..Default::default()
2615 });
2616
2617 assert_eq!(layout.width, 100.0000);
2618 assert_eq!(layout.height, 100.0000);
2619 assert_eq!(layout.x, 0.0000);
2620 assert_eq!(layout.y, 0.0000);
2621
2622 assert_eq!(layout.children[0].width, 100.0000);
2623 assert_eq!(layout.children[0].height, 50.0000);
2624 assert_eq!(layout.children[0].x, 0.0000);
2625 assert_eq!(layout.children[0].y, 0.0000);
2626
2627 assert_eq!(layout.children[0].children[0].width, 100.0000);
2628 assert_eq!(layout.children[0].children[0].height, 10.0000);
2629 assert_eq!(layout.children[0].children[0].x, 0.0000);
2630 assert_eq!(layout.children[0].children[0].y, 0.0000);
2631 }
2632
2633 #[test]
2634 fn margin_fix_left_auto_right_child_bigger_than_parent() {
2635 let layout = stretch::compute(&stretch::style::Node {
2636 justify_content: stretch::style::JustifyContent::Center,
2637 width: stretch::style::Dimension::Points(52.0000),
2638 height: stretch::style::Dimension::Points(52.0000),
2639 children: vec![stretch::style::Node {
2640 width: stretch::style::Dimension::Points(72.0000),
2641 height: stretch::style::Dimension::Points(72.0000),
2642 margin: stretch::style::Edges {
2643 start: stretch::style::Dimension::Points(10.0000),
2644 end: stretch::style::Dimension::Auto,
2645 ..Default::default()
2646 },
2647 ..Default::default()
2648 }],
2649 ..Default::default()
2650 });
2651
2652 assert_eq!(layout.width, 52.0000);
2653 assert_eq!(layout.height, 52.0000);
2654 assert_eq!(layout.x, 0.0000);
2655 assert_eq!(layout.y, 0.0000);
2656
2657 assert_eq!(layout.children[0].width, 42.0000);
2658 assert_eq!(layout.children[0].height, 72.0000);
2659 assert_eq!(layout.children[0].x, 10.0000);
2660 assert_eq!(layout.children[0].y, 0.0000);
2661 }
2662
2663 #[test]
2664 fn percentage_container_in_wrapping_container() {
2665 let layout = stretch::compute(&stretch::style::Node {
2666 flex_direction: stretch::style::FlexDirection::Column,
2667 align_items: stretch::style::AlignItems::Center,
2668 justify_content: stretch::style::JustifyContent::Center,
2669 width: stretch::style::Dimension::Points(200.0000),
2670 height: stretch::style::Dimension::Points(200.0000),
2671 children: vec![stretch::style::Node {
2672 flex_direction: stretch::style::FlexDirection::Column,
2673 children: vec![stretch::style::Node {
2674 justify_content: stretch::style::JustifyContent::Center,
2675 width: stretch::style::Dimension::Percent(1.0000),
2676 children: vec![
2677 stretch::style::Node {
2678 width: stretch::style::Dimension::Points(50.0000),
2679 height: stretch::style::Dimension::Points(50.0000),
2680 ..Default::default()
2681 },
2682 stretch::style::Node {
2683 width: stretch::style::Dimension::Points(50.0000),
2684 height: stretch::style::Dimension::Points(50.0000),
2685 ..Default::default()
2686 },
2687 ],
2688 ..Default::default()
2689 }],
2690 ..Default::default()
2691 }],
2692 ..Default::default()
2693 });
2694
2695 assert_eq!(layout.width, 200.0000);
2696 assert_eq!(layout.height, 200.0000);
2697 assert_eq!(layout.x, 0.0000);
2698 assert_eq!(layout.y, 0.0000);
2699
2700 assert_eq!(layout.children[0].width, 100.0000);
2701 assert_eq!(layout.children[0].height, 50.0000);
2702 assert_eq!(layout.children[0].x, 50.0000);
2703 assert_eq!(layout.children[0].y, 75.0000);
2704
2705 assert_eq!(layout.children[0].children[0].width, 100.0000);
2706 assert_eq!(layout.children[0].children[0].height, 50.0000);
2707 assert_eq!(layout.children[0].children[0].x, 0.0000);
2708 assert_eq!(layout.children[0].children[0].y, 0.0000);
2709
2710 assert_eq!(layout.children[0].children[0].children[0].width, 50.0000);
2711 assert_eq!(layout.children[0].children[0].children[0].height, 50.0000);
2712 assert_eq!(layout.children[0].children[0].children[0].x, 0.0000);
2713 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
2714
2715 assert_eq!(layout.children[0].children[0].children[1].width, 50.0000);
2716 assert_eq!(layout.children[0].children[0].children[1].height, 50.0000);
2717 assert_eq!(layout.children[0].children[0].children[1].x, 50.0000);
2718 assert_eq!(layout.children[0].children[0].children[1].y, 0.0000);
2719 }
2720
2721 #[test]
2722 fn margin_auto_left_stretching_child() {
2723 let layout = stretch::compute(&stretch::style::Node {
2724 align_items: stretch::style::AlignItems::Center,
2725 width: stretch::style::Dimension::Points(200.0000),
2726 height: stretch::style::Dimension::Points(200.0000),
2727 children: vec![
2728 stretch::style::Node {
2729 flex_grow: 1.0000,
2730 flex_shrink: 1.0000,
2731 flex_basis: stretch::style::Dimension::Percent(0.0000),
2732 margin: stretch::style::Edges { start: stretch::style::Dimension::Auto, ..Default::default() },
2733 ..Default::default()
2734 },
2735 stretch::style::Node {
2736 width: stretch::style::Dimension::Points(50.0000),
2737 height: stretch::style::Dimension::Points(50.0000),
2738 ..Default::default()
2739 },
2740 ],
2741 ..Default::default()
2742 });
2743
2744 assert_eq!(layout.width, 200.0000);
2745 assert_eq!(layout.height, 200.0000);
2746 assert_eq!(layout.x, 0.0000);
2747 assert_eq!(layout.y, 0.0000);
2748
2749 assert_eq!(layout.children[0].width, 150.0000);
2750 assert_eq!(layout.children[0].height, 0.0000);
2751 assert_eq!(layout.children[0].x, 0.0000);
2752 assert_eq!(layout.children[0].y, 100.0000);
2753
2754 assert_eq!(layout.children[1].width, 50.0000);
2755 assert_eq!(layout.children[1].height, 50.0000);
2756 assert_eq!(layout.children[1].x, 150.0000);
2757 assert_eq!(layout.children[1].y, 75.0000);
2758 }
2759
2760 #[test]
2761 fn flex_basis_smaller_then_content_with_flex_grow_small_size() {
2762 let layout = stretch::compute(&stretch::style::Node {
2763 width: stretch::style::Dimension::Points(10.0000),
2764 children: vec![
2765 stretch::style::Node {
2766 flex_direction: stretch::style::FlexDirection::Column,
2767 flex_grow: 1.0000,
2768 flex_basis: stretch::style::Dimension::Points(0.0000),
2769 children: vec![stretch::style::Node {
2770 width: stretch::style::Dimension::Points(70.0000),
2771 height: stretch::style::Dimension::Points(100.0000),
2772 ..Default::default()
2773 }],
2774 ..Default::default()
2775 },
2776 stretch::style::Node {
2777 flex_direction: stretch::style::FlexDirection::Column,
2778 flex_grow: 1.0000,
2779 flex_basis: stretch::style::Dimension::Points(0.0000),
2780 children: vec![stretch::style::Node {
2781 width: stretch::style::Dimension::Points(20.0000),
2782 height: stretch::style::Dimension::Points(100.0000),
2783 ..Default::default()
2784 }],
2785 ..Default::default()
2786 },
2787 ],
2788 ..Default::default()
2789 });
2790
2791 assert_eq!(layout.width, 10.0000);
2792 assert_eq!(layout.height, 100.0000);
2793 assert_eq!(layout.x, 0.0000);
2794 assert_eq!(layout.y, 0.0000);
2795
2796 assert_eq!(layout.children[0].width, 70.0000);
2797 assert_eq!(layout.children[0].height, 100.0000);
2798 assert_eq!(layout.children[0].x, 0.0000);
2799 assert_eq!(layout.children[0].y, 0.0000);
2800
2801 assert_eq!(layout.children[0].children[0].width, 70.0000);
2802 assert_eq!(layout.children[0].children[0].height, 100.0000);
2803 assert_eq!(layout.children[0].children[0].x, 0.0000);
2804 assert_eq!(layout.children[0].children[0].y, 0.0000);
2805
2806 assert_eq!(layout.children[1].width, 20.0000);
2807 assert_eq!(layout.children[1].height, 100.0000);
2808 assert_eq!(layout.children[1].x, 70.0000);
2809 assert_eq!(layout.children[1].y, 0.0000);
2810
2811 assert_eq!(layout.children[1].children[0].width, 20.0000);
2812 assert_eq!(layout.children[1].children[0].height, 100.0000);
2813 assert_eq!(layout.children[1].children[0].x, 0.0000);
2814 assert_eq!(layout.children[1].children[0].y, 0.0000);
2815 }
2816
2817 #[test]
2818 fn percentage_flex_basis_cross_max_width() {
2819 let layout = stretch::compute(&stretch::style::Node {
2820 flex_direction: stretch::style::FlexDirection::Column,
2821 width: stretch::style::Dimension::Points(200.0000),
2822 height: stretch::style::Dimension::Points(200.0000),
2823 children: vec![
2824 stretch::style::Node {
2825 flex_grow: 1.0000,
2826 flex_basis: stretch::style::Dimension::Percent(0.1000),
2827 max_width: stretch::style::Dimension::Percent(0.6000),
2828 ..Default::default()
2829 },
2830 stretch::style::Node {
2831 flex_grow: 4.0000,
2832 flex_basis: stretch::style::Dimension::Percent(0.1500),
2833 max_width: stretch::style::Dimension::Percent(0.2000),
2834 ..Default::default()
2835 },
2836 ],
2837 ..Default::default()
2838 });
2839
2840 assert_eq!(layout.width, 200.0000);
2841 assert_eq!(layout.height, 200.0000);
2842 assert_eq!(layout.x, 0.0000);
2843 assert_eq!(layout.y, 0.0000);
2844
2845 assert_eq!(layout.children[0].width, 120.0000);
2846 assert_eq!(layout.children[0].height, 50.0000);
2847 assert_eq!(layout.children[0].x, 0.0000);
2848 assert_eq!(layout.children[0].y, 0.0000);
2849
2850 assert_eq!(layout.children[1].width, 40.0000);
2851 assert_eq!(layout.children[1].height, 150.0000);
2852 assert_eq!(layout.children[1].x, 0.0000);
2853 assert_eq!(layout.children[1].y, 50.0000);
2854 }
2855
2856 #[test]
2857 fn align_items_flex_end_child_without_margin_bigger_than_parent() {
2858 let layout = stretch::compute(&stretch::style::Node {
2859 align_items: stretch::style::AlignItems::Center,
2860 justify_content: stretch::style::JustifyContent::Center,
2861 width: stretch::style::Dimension::Points(50.0000),
2862 height: stretch::style::Dimension::Points(50.0000),
2863 children: vec![stretch::style::Node {
2864 align_items: stretch::style::AlignItems::FlexEnd,
2865 children: vec![stretch::style::Node {
2866 width: stretch::style::Dimension::Points(70.0000),
2867 height: stretch::style::Dimension::Points(70.0000),
2868 ..Default::default()
2869 }],
2870 ..Default::default()
2871 }],
2872 ..Default::default()
2873 });
2874
2875 assert_eq!(layout.width, 50.0000);
2876 assert_eq!(layout.height, 50.0000);
2877 assert_eq!(layout.x, 0.0000);
2878 assert_eq!(layout.y, 0.0000);
2879
2880 assert_eq!(layout.children[0].width, 70.0000);
2881 assert_eq!(layout.children[0].height, 70.0000);
2882 assert_eq!(layout.children[0].x, -10.0000);
2883 assert_eq!(layout.children[0].y, -10.0000);
2884
2885 assert_eq!(layout.children[0].children[0].width, 70.0000);
2886 assert_eq!(layout.children[0].children[0].height, 70.0000);
2887 assert_eq!(layout.children[0].children[0].x, 0.0000);
2888 assert_eq!(layout.children[0].children[0].y, 0.0000);
2889 }
2890
2891 #[test]
2892 fn width_smaller_then_content_with_flex_grow_very_large_size() {
2893 let layout = stretch::compute(&stretch::style::Node {
2894 width: stretch::style::Dimension::Points(200.0000),
2895 children: vec![
2896 stretch::style::Node {
2897 flex_direction: stretch::style::FlexDirection::Column,
2898 flex_grow: 1.0000,
2899 width: stretch::style::Dimension::Points(0.0000),
2900 children: vec![stretch::style::Node {
2901 width: stretch::style::Dimension::Points(70.0000),
2902 height: stretch::style::Dimension::Points(100.0000),
2903 ..Default::default()
2904 }],
2905 ..Default::default()
2906 },
2907 stretch::style::Node {
2908 flex_direction: stretch::style::FlexDirection::Column,
2909 flex_grow: 1.0000,
2910 width: stretch::style::Dimension::Points(0.0000),
2911 children: vec![stretch::style::Node {
2912 width: stretch::style::Dimension::Points(20.0000),
2913 height: stretch::style::Dimension::Points(100.0000),
2914 ..Default::default()
2915 }],
2916 ..Default::default()
2917 },
2918 ],
2919 ..Default::default()
2920 });
2921
2922 assert_eq!(layout.width, 200.0000);
2923 assert_eq!(layout.height, 100.0000);
2924 assert_eq!(layout.x, 0.0000);
2925 assert_eq!(layout.y, 0.0000);
2926
2927 assert_eq!(layout.children[0].width, 100.0000);
2928 assert_eq!(layout.children[0].height, 100.0000);
2929 assert_eq!(layout.children[0].x, 0.0000);
2930 assert_eq!(layout.children[0].y, 0.0000);
2931
2932 assert_eq!(layout.children[0].children[0].width, 70.0000);
2933 assert_eq!(layout.children[0].children[0].height, 100.0000);
2934 assert_eq!(layout.children[0].children[0].x, 0.0000);
2935 assert_eq!(layout.children[0].children[0].y, 0.0000);
2936
2937 assert_eq!(layout.children[1].width, 100.0000);
2938 assert_eq!(layout.children[1].height, 100.0000);
2939 assert_eq!(layout.children[1].x, 100.0000);
2940 assert_eq!(layout.children[1].y, 0.0000);
2941
2942 assert_eq!(layout.children[1].children[0].width, 20.0000);
2943 assert_eq!(layout.children[1].children[0].height, 100.0000);
2944 assert_eq!(layout.children[1].children[0].x, 0.0000);
2945 assert_eq!(layout.children[1].children[0].y, 0.0000);
2946 }
2947
2948 #[test]
2949 fn size_defined_by_child_with_padding() {
2950 let layout = stretch::compute(&stretch::style::Node {
2951 padding: stretch::style::Edges {
2952 start: stretch::style::Dimension::Points(10.0000),
2953 end: stretch::style::Dimension::Points(10.0000),
2954 top: stretch::style::Dimension::Points(10.0000),
2955 bottom: stretch::style::Dimension::Points(10.0000),
2956 ..Default::default()
2957 },
2958 children: vec![stretch::style::Node {
2959 width: stretch::style::Dimension::Points(10.0000),
2960 height: stretch::style::Dimension::Points(10.0000),
2961 ..Default::default()
2962 }],
2963 ..Default::default()
2964 });
2965
2966 assert_eq!(layout.width, 30.0000);
2967 assert_eq!(layout.height, 30.0000);
2968 assert_eq!(layout.x, 0.0000);
2969 assert_eq!(layout.y, 0.0000);
2970
2971 assert_eq!(layout.children[0].width, 10.0000);
2972 assert_eq!(layout.children[0].height, 10.0000);
2973 assert_eq!(layout.children[0].x, 10.0000);
2974 assert_eq!(layout.children[0].y, 10.0000);
2975 }
2976
2977 #[test]
2978 fn absolute_layout_within_border() {
2979 let layout = stretch::compute(&stretch::style::Node {
2980 width: stretch::style::Dimension::Points(100.0000),
2981 height: stretch::style::Dimension::Points(100.0000),
2982 padding: stretch::style::Edges {
2983 start: stretch::style::Dimension::Points(10.0000),
2984 end: stretch::style::Dimension::Points(10.0000),
2985 top: stretch::style::Dimension::Points(10.0000),
2986 bottom: stretch::style::Dimension::Points(10.0000),
2987 ..Default::default()
2988 },
2989 border: stretch::style::Edges {
2990 start: stretch::style::Dimension::Points(10.0000),
2991 end: stretch::style::Dimension::Points(10.0000),
2992 top: stretch::style::Dimension::Points(10.0000),
2993 bottom: stretch::style::Dimension::Points(10.0000),
2994 ..Default::default()
2995 },
2996 children: vec![
2997 stretch::style::Node {
2998 position: stretch::style::Position::Absolute,
2999 width: stretch::style::Dimension::Points(50.0000),
3000 height: stretch::style::Dimension::Points(50.0000),
3001 start: stretch::style::Dimension::Points(0.0000),
3002 top: stretch::style::Dimension::Points(0.0000),
3003 ..Default::default()
3004 },
3005 stretch::style::Node {
3006 position: stretch::style::Position::Absolute,
3007 width: stretch::style::Dimension::Points(50.0000),
3008 height: stretch::style::Dimension::Points(50.0000),
3009 end: stretch::style::Dimension::Points(0.0000),
3010 bottom: stretch::style::Dimension::Points(0.0000),
3011 ..Default::default()
3012 },
3013 stretch::style::Node {
3014 position: stretch::style::Position::Absolute,
3015 width: stretch::style::Dimension::Points(50.0000),
3016 height: stretch::style::Dimension::Points(50.0000),
3017 margin: stretch::style::Edges {
3018 start: stretch::style::Dimension::Points(10.0000),
3019 end: stretch::style::Dimension::Points(10.0000),
3020 top: stretch::style::Dimension::Points(10.0000),
3021 bottom: stretch::style::Dimension::Points(10.0000),
3022 ..Default::default()
3023 },
3024 start: stretch::style::Dimension::Points(0.0000),
3025 top: stretch::style::Dimension::Points(0.0000),
3026 ..Default::default()
3027 },
3028 stretch::style::Node {
3029 position: stretch::style::Position::Absolute,
3030 width: stretch::style::Dimension::Points(50.0000),
3031 height: stretch::style::Dimension::Points(50.0000),
3032 margin: stretch::style::Edges {
3033 start: stretch::style::Dimension::Points(10.0000),
3034 end: stretch::style::Dimension::Points(10.0000),
3035 top: stretch::style::Dimension::Points(10.0000),
3036 bottom: stretch::style::Dimension::Points(10.0000),
3037 ..Default::default()
3038 },
3039 end: stretch::style::Dimension::Points(0.0000),
3040 bottom: stretch::style::Dimension::Points(0.0000),
3041 ..Default::default()
3042 },
3043 ],
3044 ..Default::default()
3045 });
3046
3047 assert_eq!(layout.width, 100.0000);
3048 assert_eq!(layout.height, 100.0000);
3049 assert_eq!(layout.x, 0.0000);
3050 assert_eq!(layout.y, 0.0000);
3051
3052 assert_eq!(layout.children[0].width, 50.0000);
3053 assert_eq!(layout.children[0].height, 50.0000);
3054 assert_eq!(layout.children[0].x, 10.0000);
3055 assert_eq!(layout.children[0].y, 10.0000);
3056
3057 assert_eq!(layout.children[1].width, 50.0000);
3058 assert_eq!(layout.children[1].height, 50.0000);
3059 assert_eq!(layout.children[1].x, 40.0000);
3060 assert_eq!(layout.children[1].y, 40.0000);
3061
3062 assert_eq!(layout.children[2].width, 50.0000);
3063 assert_eq!(layout.children[2].height, 50.0000);
3064 assert_eq!(layout.children[2].x, 20.0000);
3065 assert_eq!(layout.children[2].y, 20.0000);
3066
3067 assert_eq!(layout.children[3].width, 50.0000);
3068 assert_eq!(layout.children[3].height, 50.0000);
3069 assert_eq!(layout.children[3].x, 30.0000);
3070 assert_eq!(layout.children[3].y, 30.0000);
3071 }
3072
3073 #[test]
3074 fn margin_auto_left_fix_right_child_bigger_than_parent() {
3075 let layout = stretch::compute(&stretch::style::Node {
3076 justify_content: stretch::style::JustifyContent::Center,
3077 width: stretch::style::Dimension::Points(52.0000),
3078 height: stretch::style::Dimension::Points(52.0000),
3079 children: vec![stretch::style::Node {
3080 width: stretch::style::Dimension::Points(72.0000),
3081 height: stretch::style::Dimension::Points(72.0000),
3082 margin: stretch::style::Edges {
3083 start: stretch::style::Dimension::Auto,
3084 end: stretch::style::Dimension::Points(10.0000),
3085 ..Default::default()
3086 },
3087 ..Default::default()
3088 }],
3089 ..Default::default()
3090 });
3091
3092 assert_eq!(layout.width, 52.0000);
3093 assert_eq!(layout.height, 52.0000);
3094 assert_eq!(layout.x, 0.0000);
3095 assert_eq!(layout.y, 0.0000);
3096
3097 assert_eq!(layout.children[0].width, 42.0000);
3098 assert_eq!(layout.children[0].height, 72.0000);
3099 assert_eq!(layout.children[0].x, 0.0000);
3100 assert_eq!(layout.children[0].y, 0.0000);
3101 }
3102
3103 #[test]
3104 fn justify_content_row_flex_end() {
3105 let layout = stretch::compute(&stretch::style::Node {
3106 justify_content: stretch::style::JustifyContent::FlexEnd,
3107 width: stretch::style::Dimension::Points(100.0000),
3108 height: stretch::style::Dimension::Points(100.0000),
3109 children: vec![
3110 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3111 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3112 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3113 ],
3114 ..Default::default()
3115 });
3116
3117 assert_eq!(layout.width, 100.0000);
3118 assert_eq!(layout.height, 100.0000);
3119 assert_eq!(layout.x, 0.0000);
3120 assert_eq!(layout.y, 0.0000);
3121
3122 assert_eq!(layout.children[0].width, 10.0000);
3123 assert_eq!(layout.children[0].height, 100.0000);
3124 assert_eq!(layout.children[0].x, 70.0000);
3125 assert_eq!(layout.children[0].y, 0.0000);
3126
3127 assert_eq!(layout.children[1].width, 10.0000);
3128 assert_eq!(layout.children[1].height, 100.0000);
3129 assert_eq!(layout.children[1].x, 80.0000);
3130 assert_eq!(layout.children[1].y, 0.0000);
3131
3132 assert_eq!(layout.children[2].width, 10.0000);
3133 assert_eq!(layout.children[2].height, 100.0000);
3134 assert_eq!(layout.children[2].x, 90.0000);
3135 assert_eq!(layout.children[2].y, 0.0000);
3136 }
3137
3138 #[test]
3139 fn margin_bottom() {
3140 let layout = stretch::compute(&stretch::style::Node {
3141 flex_direction: stretch::style::FlexDirection::Column,
3142 justify_content: stretch::style::JustifyContent::FlexEnd,
3143 width: stretch::style::Dimension::Points(100.0000),
3144 height: stretch::style::Dimension::Points(100.0000),
3145 children: vec![stretch::style::Node {
3146 height: stretch::style::Dimension::Points(10.0000),
3147 margin: stretch::style::Edges {
3148 bottom: stretch::style::Dimension::Points(10.0000),
3149 ..Default::default()
3150 },
3151 ..Default::default()
3152 }],
3153 ..Default::default()
3154 });
3155
3156 assert_eq!(layout.width, 100.0000);
3157 assert_eq!(layout.height, 100.0000);
3158 assert_eq!(layout.x, 0.0000);
3159 assert_eq!(layout.y, 0.0000);
3160
3161 assert_eq!(layout.children[0].width, 100.0000);
3162 assert_eq!(layout.children[0].height, 10.0000);
3163 assert_eq!(layout.children[0].x, 0.0000);
3164 assert_eq!(layout.children[0].y, 80.0000);
3165 }
3166
3167 #[test]
3168 fn margin_should_not_be_part_of_max_height() {
3169 let layout = stretch::compute(&stretch::style::Node {
3170 width: stretch::style::Dimension::Points(250.0000),
3171 height: stretch::style::Dimension::Points(250.0000),
3172 children: vec![stretch::style::Node {
3173 width: stretch::style::Dimension::Points(100.0000),
3174 height: stretch::style::Dimension::Points(100.0000),
3175 max_height: stretch::style::Dimension::Points(100.0000),
3176 margin: stretch::style::Edges { top: stretch::style::Dimension::Points(20.0000), ..Default::default() },
3177 ..Default::default()
3178 }],
3179 ..Default::default()
3180 });
3181
3182 assert_eq!(layout.width, 250.0000);
3183 assert_eq!(layout.height, 250.0000);
3184 assert_eq!(layout.x, 0.0000);
3185 assert_eq!(layout.y, 0.0000);
3186
3187 assert_eq!(layout.children[0].width, 100.0000);
3188 assert_eq!(layout.children[0].height, 100.0000);
3189 assert_eq!(layout.children[0].x, 0.0000);
3190 assert_eq!(layout.children[0].y, 20.0000);
3191 }
3192
3193 #[test]
3194 fn flex_basis_smaller_than_main_dimen_row() {
3195 let layout = stretch::compute(&stretch::style::Node {
3196 width: stretch::style::Dimension::Points(100.0000),
3197 children: vec![stretch::style::Node {
3198 flex_basis: stretch::style::Dimension::Points(10.0000),
3199 width: stretch::style::Dimension::Points(50.0000),
3200 height: stretch::style::Dimension::Points(50.0000),
3201 ..Default::default()
3202 }],
3203 ..Default::default()
3204 });
3205
3206 assert_eq!(layout.width, 100.0000);
3207 assert_eq!(layout.height, 50.0000);
3208 assert_eq!(layout.x, 0.0000);
3209 assert_eq!(layout.y, 0.0000);
3210
3211 assert_eq!(layout.children[0].width, 10.0000);
3212 assert_eq!(layout.children[0].height, 50.0000);
3213 assert_eq!(layout.children[0].x, 0.0000);
3214 assert_eq!(layout.children[0].y, 0.0000);
3215 }
3216
3217 #[test]
3218 fn percentage_flex_basis_cross_min_height() {
3219 let layout = stretch::compute(&stretch::style::Node {
3220 flex_direction: stretch::style::FlexDirection::Column,
3221 width: stretch::style::Dimension::Points(200.0000),
3222 height: stretch::style::Dimension::Points(200.0000),
3223 children: vec![
3224 stretch::style::Node {
3225 flex_grow: 1.0000,
3226 min_height: stretch::style::Dimension::Percent(0.6000),
3227 ..Default::default()
3228 },
3229 stretch::style::Node {
3230 flex_grow: 2.0000,
3231 min_height: stretch::style::Dimension::Percent(0.1000),
3232 ..Default::default()
3233 },
3234 ],
3235 ..Default::default()
3236 });
3237
3238 assert_eq!(layout.width, 200.0000);
3239 assert_eq!(layout.height, 200.0000);
3240 assert_eq!(layout.x, 0.0000);
3241 assert_eq!(layout.y, 0.0000);
3242
3243 assert_eq!(layout.children[0].width, 200.0000);
3244 assert_eq!(layout.children[0].height, 140.0000);
3245 assert_eq!(layout.children[0].x, 0.0000);
3246 assert_eq!(layout.children[0].y, 0.0000);
3247
3248 assert_eq!(layout.children[1].width, 200.0000);
3249 assert_eq!(layout.children[1].height, 60.0000);
3250 assert_eq!(layout.children[1].x, 0.0000);
3251 assert_eq!(layout.children[1].y, 140.0000);
3252 }
3253
3254 #[test]
3255 fn nested_overflowing_child_in_constraint_parent() {
3256 let layout = stretch::compute(&stretch::style::Node {
3257 width: stretch::style::Dimension::Points(100.0000),
3258 height: stretch::style::Dimension::Points(100.0000),
3259 children: vec![stretch::style::Node {
3260 width: stretch::style::Dimension::Points(100.0000),
3261 height: stretch::style::Dimension::Points(100.0000),
3262 children: vec![stretch::style::Node {
3263 width: stretch::style::Dimension::Points(200.0000),
3264 height: stretch::style::Dimension::Points(200.0000),
3265 ..Default::default()
3266 }],
3267 ..Default::default()
3268 }],
3269 ..Default::default()
3270 });
3271
3272 assert_eq!(layout.width, 100.0000);
3273 assert_eq!(layout.height, 100.0000);
3274 assert_eq!(layout.x, 0.0000);
3275 assert_eq!(layout.y, 0.0000);
3276
3277 assert_eq!(layout.children[0].width, 100.0000);
3278 assert_eq!(layout.children[0].height, 100.0000);
3279 assert_eq!(layout.children[0].x, 0.0000);
3280 assert_eq!(layout.children[0].y, 0.0000);
3281
3282 assert_eq!(layout.children[0].children[0].width, 100.0000);
3283 assert_eq!(layout.children[0].children[0].height, 200.0000);
3284 assert_eq!(layout.children[0].children[0].x, 0.0000);
3285 assert_eq!(layout.children[0].children[0].y, 0.0000);
3286 }
3287
3288 #[test]
3289 fn wrapped_row_within_align_items_center() {
3290 let layout = stretch::compute(&stretch::style::Node {
3291 flex_direction: stretch::style::FlexDirection::Column,
3292 align_items: stretch::style::AlignItems::Center,
3293 width: stretch::style::Dimension::Points(200.0000),
3294 height: stretch::style::Dimension::Points(200.0000),
3295 children: vec![stretch::style::Node {
3296 flex_wrap: stretch::style::FlexWrap::Wrap,
3297 children: vec![
3298 stretch::style::Node {
3299 width: stretch::style::Dimension::Points(150.0000),
3300 height: stretch::style::Dimension::Points(80.0000),
3301 ..Default::default()
3302 },
3303 stretch::style::Node {
3304 width: stretch::style::Dimension::Points(80.0000),
3305 height: stretch::style::Dimension::Points(80.0000),
3306 ..Default::default()
3307 },
3308 ],
3309 ..Default::default()
3310 }],
3311 ..Default::default()
3312 });
3313
3314 assert_eq!(layout.width, 200.0000);
3315 assert_eq!(layout.height, 200.0000);
3316 assert_eq!(layout.x, 0.0000);
3317 assert_eq!(layout.y, 0.0000);
3318
3319 assert_eq!(layout.children[0].width, 200.0000);
3320 assert_eq!(layout.children[0].height, 160.0000);
3321 assert_eq!(layout.children[0].x, 0.0000);
3322 assert_eq!(layout.children[0].y, 0.0000);
3323
3324 assert_eq!(layout.children[0].children[0].width, 150.0000);
3325 assert_eq!(layout.children[0].children[0].height, 80.0000);
3326 assert_eq!(layout.children[0].children[0].x, 0.0000);
3327 assert_eq!(layout.children[0].children[0].y, 0.0000);
3328
3329 assert_eq!(layout.children[0].children[1].width, 80.0000);
3330 assert_eq!(layout.children[0].children[1].height, 80.0000);
3331 assert_eq!(layout.children[0].children[1].x, 0.0000);
3332 assert_eq!(layout.children[0].children[1].y, 80.0000);
3333 }
3334
3335 #[test]
3336 fn justify_content_column_center() {
3337 let layout = stretch::compute(&stretch::style::Node {
3338 flex_direction: stretch::style::FlexDirection::Column,
3339 justify_content: stretch::style::JustifyContent::Center,
3340 width: stretch::style::Dimension::Points(100.0000),
3341 height: stretch::style::Dimension::Points(100.0000),
3342 children: vec![
3343 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3344 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3345 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3346 ],
3347 ..Default::default()
3348 });
3349
3350 assert_eq!(layout.width, 100.0000);
3351 assert_eq!(layout.height, 100.0000);
3352 assert_eq!(layout.x, 0.0000);
3353 assert_eq!(layout.y, 0.0000);
3354
3355 assert_eq!(layout.children[0].width, 100.0000);
3356 assert_eq!(layout.children[0].height, 10.0000);
3357 assert_eq!(layout.children[0].x, 0.0000);
3358 assert_eq!(layout.children[0].y, 35.0000);
3359
3360 assert_eq!(layout.children[1].width, 100.0000);
3361 assert_eq!(layout.children[1].height, 10.0000);
3362 assert_eq!(layout.children[1].x, 0.0000);
3363 assert_eq!(layout.children[1].y, 45.0000);
3364
3365 assert_eq!(layout.children[2].width, 100.0000);
3366 assert_eq!(layout.children[2].height, 10.0000);
3367 assert_eq!(layout.children[2].x, 0.0000);
3368 assert_eq!(layout.children[2].y, 55.0000);
3369 }
3370
3371 #[test]
3372 fn align_items_center_child_with_margin_bigger_than_parent() {
3373 let layout = stretch::compute(&stretch::style::Node {
3374 align_items: stretch::style::AlignItems::Center,
3375 justify_content: stretch::style::JustifyContent::Center,
3376 width: stretch::style::Dimension::Points(50.0000),
3377 height: stretch::style::Dimension::Points(50.0000),
3378 children: vec![stretch::style::Node {
3379 align_items: stretch::style::AlignItems::Center,
3380 children: vec![stretch::style::Node {
3381 width: stretch::style::Dimension::Points(50.0000),
3382 height: stretch::style::Dimension::Points(50.0000),
3383 margin: stretch::style::Edges {
3384 start: stretch::style::Dimension::Points(10.0000),
3385 end: stretch::style::Dimension::Points(10.0000),
3386 ..Default::default()
3387 },
3388 ..Default::default()
3389 }],
3390 ..Default::default()
3391 }],
3392 ..Default::default()
3393 });
3394
3395 assert_eq!(layout.width, 50.0000);
3396 assert_eq!(layout.height, 50.0000);
3397 assert_eq!(layout.x, 0.0000);
3398 assert_eq!(layout.y, 0.0000);
3399
3400 assert_eq!(layout.children[0].width, 70.0000);
3401 assert_eq!(layout.children[0].height, 50.0000);
3402 assert_eq!(layout.children[0].x, -10.0000);
3403 assert_eq!(layout.children[0].y, 0.0000);
3404
3405 assert_eq!(layout.children[0].children[0].width, 50.0000);
3406 assert_eq!(layout.children[0].children[0].height, 50.0000);
3407 assert_eq!(layout.children[0].children[0].x, 10.0000);
3408 assert_eq!(layout.children[0].children[0].y, 0.0000);
3409 }
3410
3411 #[test]
3412 fn percentage_width_height() {
3413 let layout = stretch::compute(&stretch::style::Node {
3414 width: stretch::style::Dimension::Points(200.0000),
3415 height: stretch::style::Dimension::Points(200.0000),
3416 children: vec![stretch::style::Node {
3417 width: stretch::style::Dimension::Percent(0.3000),
3418 height: stretch::style::Dimension::Percent(0.3000),
3419 ..Default::default()
3420 }],
3421 ..Default::default()
3422 });
3423
3424 assert_eq!(layout.width, 200.0000);
3425 assert_eq!(layout.height, 200.0000);
3426 assert_eq!(layout.x, 0.0000);
3427 assert_eq!(layout.y, 0.0000);
3428
3429 assert_eq!(layout.children[0].width, 60.0000);
3430 assert_eq!(layout.children[0].height, 60.0000);
3431 assert_eq!(layout.children[0].x, 0.0000);
3432 assert_eq!(layout.children[0].y, 0.0000);
3433 }
3434
3435 #[test]
3436 fn margin_auto_mutiple_children_column() {
3437 let layout = stretch::compute(&stretch::style::Node {
3438 flex_direction: stretch::style::FlexDirection::Column,
3439 align_items: stretch::style::AlignItems::Center,
3440 width: stretch::style::Dimension::Points(200.0000),
3441 height: stretch::style::Dimension::Points(200.0000),
3442 children: vec![
3443 stretch::style::Node {
3444 width: stretch::style::Dimension::Points(50.0000),
3445 height: stretch::style::Dimension::Points(50.0000),
3446 margin: stretch::style::Edges { top: stretch::style::Dimension::Auto, ..Default::default() },
3447 ..Default::default()
3448 },
3449 stretch::style::Node {
3450 width: stretch::style::Dimension::Points(50.0000),
3451 height: stretch::style::Dimension::Points(50.0000),
3452 margin: stretch::style::Edges { top: stretch::style::Dimension::Auto, ..Default::default() },
3453 ..Default::default()
3454 },
3455 stretch::style::Node {
3456 width: stretch::style::Dimension::Points(50.0000),
3457 height: stretch::style::Dimension::Points(50.0000),
3458 ..Default::default()
3459 },
3460 ],
3461 ..Default::default()
3462 });
3463
3464 assert_eq!(layout.width, 200.0000);
3465 assert_eq!(layout.height, 200.0000);
3466 assert_eq!(layout.x, 0.0000);
3467 assert_eq!(layout.y, 0.0000);
3468
3469 assert_eq!(layout.children[0].width, 50.0000);
3470 assert_eq!(layout.children[0].height, 50.0000);
3471 assert_eq!(layout.children[0].x, 75.0000);
3472 assert_eq!(layout.children[0].y, 25.0000);
3473
3474 assert_eq!(layout.children[1].width, 50.0000);
3475 assert_eq!(layout.children[1].height, 50.0000);
3476 assert_eq!(layout.children[1].x, 75.0000);
3477 assert_eq!(layout.children[1].y, 100.0000);
3478
3479 assert_eq!(layout.children[2].width, 50.0000);
3480 assert_eq!(layout.children[2].height, 50.0000);
3481 assert_eq!(layout.children[2].x, 75.0000);
3482 assert_eq!(layout.children[2].y, 150.0000);
3483 }
3484
3485 #[test]
3486 fn min_width_overrides_width_on_root() {
3487 let layout = stretch::compute(&stretch::style::Node {
3488 width: stretch::style::Dimension::Points(50.0000),
3489 min_width: stretch::style::Dimension::Points(100.0000),
3490 ..Default::default()
3491 });
3492
3493 assert_eq!(layout.width, 100.0000);
3494 assert_eq!(layout.height, 0.0000);
3495 assert_eq!(layout.x, 0.0000);
3496 assert_eq!(layout.y, 0.0000);
3497 }
3498
3499 #[test]
3500 fn flex_wrap_wrap_to_child_height() {
3501 let layout = stretch::compute(&stretch::style::Node {
3502 flex_direction: stretch::style::FlexDirection::Column,
3503 children: vec![
3504 stretch::style::Node {
3505 flex_wrap: stretch::style::FlexWrap::Wrap,
3506 align_items: stretch::style::AlignItems::FlexStart,
3507 children: vec![stretch::style::Node {
3508 flex_direction: stretch::style::FlexDirection::Column,
3509 width: stretch::style::Dimension::Points(100.0000),
3510 children: vec![stretch::style::Node {
3511 width: stretch::style::Dimension::Points(100.0000),
3512 height: stretch::style::Dimension::Points(100.0000),
3513 ..Default::default()
3514 }],
3515 ..Default::default()
3516 }],
3517 ..Default::default()
3518 },
3519 stretch::style::Node {
3520 width: stretch::style::Dimension::Points(100.0000),
3521 height: stretch::style::Dimension::Points(100.0000),
3522 ..Default::default()
3523 },
3524 ],
3525 ..Default::default()
3526 });
3527
3528 assert_eq!(layout.width, 100.0000);
3529 assert_eq!(layout.height, 200.0000);
3530 assert_eq!(layout.x, 0.0000);
3531 assert_eq!(layout.y, 0.0000);
3532
3533 assert_eq!(layout.children[0].width, 100.0000);
3534 assert_eq!(layout.children[0].height, 100.0000);
3535 assert_eq!(layout.children[0].x, 0.0000);
3536 assert_eq!(layout.children[0].y, 0.0000);
3537
3538 assert_eq!(layout.children[0].children[0].width, 100.0000);
3539 assert_eq!(layout.children[0].children[0].height, 100.0000);
3540 assert_eq!(layout.children[0].children[0].x, 0.0000);
3541 assert_eq!(layout.children[0].children[0].y, 0.0000);
3542
3543 assert_eq!(layout.children[0].children[0].children[0].width, 100.0000);
3544 assert_eq!(layout.children[0].children[0].children[0].height, 100.0000);
3545 assert_eq!(layout.children[0].children[0].children[0].x, 0.0000);
3546 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
3547
3548 assert_eq!(layout.children[1].width, 100.0000);
3549 assert_eq!(layout.children[1].height, 100.0000);
3550 assert_eq!(layout.children[1].x, 0.0000);
3551 assert_eq!(layout.children[1].y, 100.0000);
3552 }
3553
3554 #[test]
3555 fn wrap_nodes_with_content_sizing_margin_cross() {
3556 let layout = stretch::compute(&stretch::style::Node {
3557 flex_direction: stretch::style::FlexDirection::Column,
3558 width: stretch::style::Dimension::Points(500.0000),
3559 height: stretch::style::Dimension::Points(500.0000),
3560 children: vec![stretch::style::Node {
3561 flex_wrap: stretch::style::FlexWrap::Wrap,
3562 width: stretch::style::Dimension::Points(70.0000),
3563 children: vec![
3564 stretch::style::Node {
3565 flex_direction: stretch::style::FlexDirection::Column,
3566 children: vec![stretch::style::Node {
3567 width: stretch::style::Dimension::Points(40.0000),
3568 height: stretch::style::Dimension::Points(40.0000),
3569 ..Default::default()
3570 }],
3571 ..Default::default()
3572 },
3573 stretch::style::Node {
3574 flex_direction: stretch::style::FlexDirection::Column,
3575 margin: stretch::style::Edges {
3576 top: stretch::style::Dimension::Points(10.0000),
3577 ..Default::default()
3578 },
3579 children: vec![stretch::style::Node {
3580 width: stretch::style::Dimension::Points(40.0000),
3581 height: stretch::style::Dimension::Points(40.0000),
3582 ..Default::default()
3583 }],
3584 ..Default::default()
3585 },
3586 ],
3587 ..Default::default()
3588 }],
3589 ..Default::default()
3590 });
3591
3592 assert_eq!(layout.width, 500.0000);
3593 assert_eq!(layout.height, 500.0000);
3594 assert_eq!(layout.x, 0.0000);
3595 assert_eq!(layout.y, 0.0000);
3596
3597 assert_eq!(layout.children[0].width, 70.0000);
3598 assert_eq!(layout.children[0].height, 90.0000);
3599 assert_eq!(layout.children[0].x, 0.0000);
3600 assert_eq!(layout.children[0].y, 0.0000);
3601
3602 assert_eq!(layout.children[0].children[0].width, 40.0000);
3603 assert_eq!(layout.children[0].children[0].height, 40.0000);
3604 assert_eq!(layout.children[0].children[0].x, 0.0000);
3605 assert_eq!(layout.children[0].children[0].y, 0.0000);
3606
3607 assert_eq!(layout.children[0].children[0].children[0].width, 40.0000);
3608 assert_eq!(layout.children[0].children[0].children[0].height, 40.0000);
3609 assert_eq!(layout.children[0].children[0].children[0].x, 0.0000);
3610 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
3611
3612 assert_eq!(layout.children[0].children[1].width, 40.0000);
3613 assert_eq!(layout.children[0].children[1].height, 40.0000);
3614 assert_eq!(layout.children[0].children[1].x, 0.0000);
3615 assert_eq!(layout.children[0].children[1].y, 50.0000);
3616
3617 assert_eq!(layout.children[0].children[1].children[0].width, 40.0000);
3618 assert_eq!(layout.children[0].children[1].children[0].height, 40.0000);
3619 assert_eq!(layout.children[0].children[1].children[0].x, 0.0000);
3620 assert_eq!(layout.children[0].children[1].children[0].y, 0.0000);
3621 }
3622
3623 #[test]
3624 fn align_baseline() {
3625 let layout = stretch::compute(&stretch::style::Node {
3626 align_items: stretch::style::AlignItems::Baseline,
3627 width: stretch::style::Dimension::Points(100.0000),
3628 height: stretch::style::Dimension::Points(100.0000),
3629 children: vec![
3630 stretch::style::Node {
3631 width: stretch::style::Dimension::Points(50.0000),
3632 height: stretch::style::Dimension::Points(50.0000),
3633 ..Default::default()
3634 },
3635 stretch::style::Node {
3636 width: stretch::style::Dimension::Points(50.0000),
3637 height: stretch::style::Dimension::Points(20.0000),
3638 ..Default::default()
3639 },
3640 ],
3641 ..Default::default()
3642 });
3643
3644 assert_eq!(layout.width, 100.0000);
3645 assert_eq!(layout.height, 100.0000);
3646 assert_eq!(layout.x, 0.0000);
3647 assert_eq!(layout.y, 0.0000);
3648
3649 assert_eq!(layout.children[0].width, 50.0000);
3650 assert_eq!(layout.children[0].height, 50.0000);
3651 assert_eq!(layout.children[0].x, 0.0000);
3652 assert_eq!(layout.children[0].y, 0.0000);
3653
3654 assert_eq!(layout.children[1].width, 50.0000);
3655 assert_eq!(layout.children[1].height, 20.0000);
3656 assert_eq!(layout.children[1].x, 50.0000);
3657 assert_eq!(layout.children[1].y, 30.0000);
3658 }
3659
3660 #[test]
3661 fn margin_with_sibling_row() {
3662 let layout = stretch::compute(&stretch::style::Node {
3663 width: stretch::style::Dimension::Points(100.0000),
3664 height: stretch::style::Dimension::Points(100.0000),
3665 children: vec![
3666 stretch::style::Node {
3667 flex_grow: 1.0000,
3668 margin: stretch::style::Edges {
3669 end: stretch::style::Dimension::Points(10.0000),
3670 ..Default::default()
3671 },
3672 ..Default::default()
3673 },
3674 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
3675 ],
3676 ..Default::default()
3677 });
3678
3679 assert_eq!(layout.width, 100.0000);
3680 assert_eq!(layout.height, 100.0000);
3681 assert_eq!(layout.x, 0.0000);
3682 assert_eq!(layout.y, 0.0000);
3683
3684 assert_eq!(layout.children[0].width, 45.0000);
3685 assert_eq!(layout.children[0].height, 100.0000);
3686 assert_eq!(layout.children[0].x, 0.0000);
3687 assert_eq!(layout.children[0].y, 0.0000);
3688
3689 assert_eq!(layout.children[1].width, 45.0000);
3690 assert_eq!(layout.children[1].height, 100.0000);
3691 assert_eq!(layout.children[1].x, 55.0000);
3692 assert_eq!(layout.children[1].y, 0.0000);
3693 }
3694
3695 #[test]
3696 fn wrap_reverse_row_align_content_space_around() {
3697 let layout = stretch::compute(&stretch::style::Node {
3698 flex_wrap: stretch::style::FlexWrap::WrapReverse,
3699 align_content: stretch::style::AlignContent::SpaceAround,
3700 width: stretch::style::Dimension::Points(100.0000),
3701 children: vec![
3702 stretch::style::Node {
3703 width: stretch::style::Dimension::Points(30.0000),
3704 height: stretch::style::Dimension::Points(10.0000),
3705 ..Default::default()
3706 },
3707 stretch::style::Node {
3708 width: stretch::style::Dimension::Points(30.0000),
3709 height: stretch::style::Dimension::Points(20.0000),
3710 ..Default::default()
3711 },
3712 stretch::style::Node {
3713 width: stretch::style::Dimension::Points(30.0000),
3714 height: stretch::style::Dimension::Points(30.0000),
3715 ..Default::default()
3716 },
3717 stretch::style::Node {
3718 width: stretch::style::Dimension::Points(30.0000),
3719 height: stretch::style::Dimension::Points(40.0000),
3720 ..Default::default()
3721 },
3722 stretch::style::Node {
3723 width: stretch::style::Dimension::Points(30.0000),
3724 height: stretch::style::Dimension::Points(50.0000),
3725 ..Default::default()
3726 },
3727 ],
3728 ..Default::default()
3729 });
3730
3731 assert_eq!(layout.width, 100.0000);
3732 assert_eq!(layout.height, 80.0000);
3733 assert_eq!(layout.x, 0.0000);
3734 assert_eq!(layout.y, 0.0000);
3735
3736 assert_eq!(layout.children[0].width, 30.0000);
3737 assert_eq!(layout.children[0].height, 10.0000);
3738 assert_eq!(layout.children[0].x, 0.0000);
3739 assert_eq!(layout.children[0].y, 70.0000);
3740
3741 assert_eq!(layout.children[1].width, 30.0000);
3742 assert_eq!(layout.children[1].height, 20.0000);
3743 assert_eq!(layout.children[1].x, 30.0000);
3744 assert_eq!(layout.children[1].y, 60.0000);
3745
3746 assert_eq!(layout.children[2].width, 30.0000);
3747 assert_eq!(layout.children[2].height, 30.0000);
3748 assert_eq!(layout.children[2].x, 60.0000);
3749 assert_eq!(layout.children[2].y, 50.0000);
3750
3751 assert_eq!(layout.children[3].width, 30.0000);
3752 assert_eq!(layout.children[3].height, 40.0000);
3753 assert_eq!(layout.children[3].x, 0.0000);
3754 assert_eq!(layout.children[3].y, 10.0000);
3755
3756 assert_eq!(layout.children[4].width, 30.0000);
3757 assert_eq!(layout.children[4].height, 50.0000);
3758 assert_eq!(layout.children[4].x, 30.0000);
3759 assert_eq!(layout.children[4].y, 0.0000);
3760 }
3761
3762 #[test]
3763 fn wrap_reverse_column() {
3764 let layout = stretch::compute(&stretch::style::Node {
3765 flex_direction: stretch::style::FlexDirection::Column,
3766 flex_wrap: stretch::style::FlexWrap::WrapReverse,
3767 width: stretch::style::Dimension::Points(100.0000),
3768 height: stretch::style::Dimension::Points(100.0000),
3769 children: vec![
3770 stretch::style::Node {
3771 width: stretch::style::Dimension::Points(30.0000),
3772 height: stretch::style::Dimension::Points(31.0000),
3773 ..Default::default()
3774 },
3775 stretch::style::Node {
3776 width: stretch::style::Dimension::Points(30.0000),
3777 height: stretch::style::Dimension::Points(32.0000),
3778 ..Default::default()
3779 },
3780 stretch::style::Node {
3781 width: stretch::style::Dimension::Points(30.0000),
3782 height: stretch::style::Dimension::Points(33.0000),
3783 ..Default::default()
3784 },
3785 stretch::style::Node {
3786 width: stretch::style::Dimension::Points(30.0000),
3787 height: stretch::style::Dimension::Points(34.0000),
3788 ..Default::default()
3789 },
3790 ],
3791 ..Default::default()
3792 });
3793
3794 assert_eq!(layout.width, 100.0000);
3795 assert_eq!(layout.height, 100.0000);
3796 assert_eq!(layout.x, 0.0000);
3797 assert_eq!(layout.y, 0.0000);
3798
3799 assert_eq!(layout.children[0].width, 30.0000);
3800 assert_eq!(layout.children[0].height, 31.0000);
3801 assert_eq!(layout.children[0].x, 70.0000);
3802 assert_eq!(layout.children[0].y, 0.0000);
3803
3804 assert_eq!(layout.children[1].width, 30.0000);
3805 assert_eq!(layout.children[1].height, 32.0000);
3806 assert_eq!(layout.children[1].x, 70.0000);
3807 assert_eq!(layout.children[1].y, 31.0000);
3808
3809 assert_eq!(layout.children[2].width, 30.0000);
3810 assert_eq!(layout.children[2].height, 33.0000);
3811 assert_eq!(layout.children[2].x, 70.0000);
3812 assert_eq!(layout.children[2].y, 63.0000);
3813
3814 assert_eq!(layout.children[3].width, 30.0000);
3815 assert_eq!(layout.children[3].height, 34.0000);
3816 assert_eq!(layout.children[3].x, 20.0000);
3817 assert_eq!(layout.children[3].y, 0.0000);
3818 }
3819
3820 #[test]
3821 fn align_items_center_with_child_margin() {
3822 let layout = stretch::compute(&stretch::style::Node {
3823 align_items: stretch::style::AlignItems::Center,
3824 width: stretch::style::Dimension::Points(100.0000),
3825 height: stretch::style::Dimension::Points(100.0000),
3826 children: vec![stretch::style::Node {
3827 width: stretch::style::Dimension::Points(10.0000),
3828 height: stretch::style::Dimension::Points(10.0000),
3829 margin: stretch::style::Edges { top: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3830 ..Default::default()
3831 }],
3832 ..Default::default()
3833 });
3834
3835 assert_eq!(layout.width, 100.0000);
3836 assert_eq!(layout.height, 100.0000);
3837 assert_eq!(layout.x, 0.0000);
3838 assert_eq!(layout.y, 0.0000);
3839
3840 assert_eq!(layout.children[0].width, 10.0000);
3841 assert_eq!(layout.children[0].height, 10.0000);
3842 assert_eq!(layout.children[0].x, 0.0000);
3843 assert_eq!(layout.children[0].y, 50.0000);
3844 }
3845
3846 #[test]
3847 fn flex_direction_column_reverse() {
3848 let layout = stretch::compute(&stretch::style::Node {
3849 flex_direction: stretch::style::FlexDirection::ColumnReverse,
3850 width: stretch::style::Dimension::Points(100.0000),
3851 height: stretch::style::Dimension::Points(100.0000),
3852 children: vec![
3853 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3854 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3855 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3856 ],
3857 ..Default::default()
3858 });
3859
3860 assert_eq!(layout.width, 100.0000);
3861 assert_eq!(layout.height, 100.0000);
3862 assert_eq!(layout.x, 0.0000);
3863 assert_eq!(layout.y, 0.0000);
3864
3865 assert_eq!(layout.children[0].width, 100.0000);
3866 assert_eq!(layout.children[0].height, 10.0000);
3867 assert_eq!(layout.children[0].x, 0.0000);
3868 assert_eq!(layout.children[0].y, 90.0000);
3869
3870 assert_eq!(layout.children[1].width, 100.0000);
3871 assert_eq!(layout.children[1].height, 10.0000);
3872 assert_eq!(layout.children[1].x, 0.0000);
3873 assert_eq!(layout.children[1].y, 80.0000);
3874
3875 assert_eq!(layout.children[2].width, 100.0000);
3876 assert_eq!(layout.children[2].height, 10.0000);
3877 assert_eq!(layout.children[2].x, 0.0000);
3878 assert_eq!(layout.children[2].y, 70.0000);
3879 }
3880
3881 #[test]
3882 fn flex_direction_column() {
3883 let layout = stretch::compute(&stretch::style::Node {
3884 flex_direction: stretch::style::FlexDirection::Column,
3885 width: stretch::style::Dimension::Points(100.0000),
3886 height: stretch::style::Dimension::Points(100.0000),
3887 children: vec![
3888 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3889 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3890 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
3891 ],
3892 ..Default::default()
3893 });
3894
3895 assert_eq!(layout.width, 100.0000);
3896 assert_eq!(layout.height, 100.0000);
3897 assert_eq!(layout.x, 0.0000);
3898 assert_eq!(layout.y, 0.0000);
3899
3900 assert_eq!(layout.children[0].width, 100.0000);
3901 assert_eq!(layout.children[0].height, 10.0000);
3902 assert_eq!(layout.children[0].x, 0.0000);
3903 assert_eq!(layout.children[0].y, 0.0000);
3904
3905 assert_eq!(layout.children[1].width, 100.0000);
3906 assert_eq!(layout.children[1].height, 10.0000);
3907 assert_eq!(layout.children[1].x, 0.0000);
3908 assert_eq!(layout.children[1].y, 10.0000);
3909
3910 assert_eq!(layout.children[2].width, 100.0000);
3911 assert_eq!(layout.children[2].height, 10.0000);
3912 assert_eq!(layout.children[2].x, 0.0000);
3913 assert_eq!(layout.children[2].y, 20.0000);
3914 }
3915
3916 #[test]
3917 fn align_items_center_child_without_margin_bigger_than_parent() {
3918 let layout = stretch::compute(&stretch::style::Node {
3919 align_items: stretch::style::AlignItems::Center,
3920 justify_content: stretch::style::JustifyContent::Center,
3921 width: stretch::style::Dimension::Points(50.0000),
3922 height: stretch::style::Dimension::Points(50.0000),
3923 children: vec![stretch::style::Node {
3924 align_items: stretch::style::AlignItems::Center,
3925 children: vec![stretch::style::Node {
3926 width: stretch::style::Dimension::Points(70.0000),
3927 height: stretch::style::Dimension::Points(70.0000),
3928 ..Default::default()
3929 }],
3930 ..Default::default()
3931 }],
3932 ..Default::default()
3933 });
3934
3935 assert_eq!(layout.width, 50.0000);
3936 assert_eq!(layout.height, 50.0000);
3937 assert_eq!(layout.x, 0.0000);
3938 assert_eq!(layout.y, 0.0000);
3939
3940 assert_eq!(layout.children[0].width, 70.0000);
3941 assert_eq!(layout.children[0].height, 70.0000);
3942 assert_eq!(layout.children[0].x, -10.0000);
3943 assert_eq!(layout.children[0].y, -10.0000);
3944
3945 assert_eq!(layout.children[0].children[0].width, 70.0000);
3946 assert_eq!(layout.children[0].children[0].height, 70.0000);
3947 assert_eq!(layout.children[0].children[0].x, 0.0000);
3948 assert_eq!(layout.children[0].children[0].y, 0.0000);
3949 }
3950
3951 #[test]
3952 fn align_self_flex_end_override_flex_start() {
3953 let layout = stretch::compute(&stretch::style::Node {
3954 align_items: stretch::style::AlignItems::FlexStart,
3955 width: stretch::style::Dimension::Points(100.0000),
3956 height: stretch::style::Dimension::Points(100.0000),
3957 children: vec![stretch::style::Node {
3958 align_self: stretch::style::AlignSelf::FlexEnd,
3959 width: stretch::style::Dimension::Points(10.0000),
3960 height: stretch::style::Dimension::Points(10.0000),
3961 ..Default::default()
3962 }],
3963 ..Default::default()
3964 });
3965
3966 assert_eq!(layout.width, 100.0000);
3967 assert_eq!(layout.height, 100.0000);
3968 assert_eq!(layout.x, 0.0000);
3969 assert_eq!(layout.y, 0.0000);
3970
3971 assert_eq!(layout.children[0].width, 10.0000);
3972 assert_eq!(layout.children[0].height, 10.0000);
3973 assert_eq!(layout.children[0].x, 0.0000);
3974 assert_eq!(layout.children[0].y, 90.0000);
3975 }
3976
3977 #[test]
3978 fn rounding_total_fractial() {
3979 let layout = stretch::compute(&stretch::style::Node {
3980 flex_direction: stretch::style::FlexDirection::Column,
3981 width: stretch::style::Dimension::Points(87.4000),
3982 height: stretch::style::Dimension::Points(113.4000),
3983 children: vec![
3984 stretch::style::Node {
3985 flex_grow: 0.7000,
3986 flex_basis: stretch::style::Dimension::Points(50.3000),
3987 height: stretch::style::Dimension::Points(20.3000),
3988 ..Default::default()
3989 },
3990 stretch::style::Node {
3991 flex_grow: 1.6000,
3992 height: stretch::style::Dimension::Points(10.0000),
3993 ..Default::default()
3994 },
3995 stretch::style::Node {
3996 flex_grow: 1.1000,
3997 height: stretch::style::Dimension::Points(10.7000),
3998 ..Default::default()
3999 },
4000 ],
4001 ..Default::default()
4002 });
4003
4004 assert_eq!(layout.width, 87.0000);
4005 assert_eq!(layout.height, 113.0000);
4006 assert_eq!(layout.x, 0.0000);
4007 assert_eq!(layout.y, 0.0000);
4008
4009 assert_eq!(layout.children[0].width, 87.0000);
4010 assert_eq!(layout.children[0].height, 59.0000);
4011 assert_eq!(layout.children[0].x, 0.0000);
4012 assert_eq!(layout.children[0].y, 0.0000);
4013
4014 assert_eq!(layout.children[1].width, 87.0000);
4015 assert_eq!(layout.children[1].height, 30.0000);
4016 assert_eq!(layout.children[1].x, 0.0000);
4017 assert_eq!(layout.children[1].y, 59.0000);
4018
4019 assert_eq!(layout.children[2].width, 87.0000);
4020 assert_eq!(layout.children[2].height, 24.0000);
4021 assert_eq!(layout.children[2].x, 0.0000);
4022 assert_eq!(layout.children[2].y, 89.0000);
4023 }
4024
4025 #[test]
4026 fn align_baseline_child_multiline() {
4027 let layout = stretch::compute(&stretch::style::Node {
4028 align_items: stretch::style::AlignItems::Baseline,
4029 width: stretch::style::Dimension::Points(100.0000),
4030 children: vec![
4031 stretch::style::Node {
4032 width: stretch::style::Dimension::Points(50.0000),
4033 height: stretch::style::Dimension::Points(60.0000),
4034 ..Default::default()
4035 },
4036 stretch::style::Node {
4037 flex_wrap: stretch::style::FlexWrap::Wrap,
4038 width: stretch::style::Dimension::Points(50.0000),
4039 children: vec![
4040 stretch::style::Node {
4041 width: stretch::style::Dimension::Points(25.0000),
4042 height: stretch::style::Dimension::Points(20.0000),
4043 ..Default::default()
4044 },
4045 stretch::style::Node {
4046 width: stretch::style::Dimension::Points(25.0000),
4047 height: stretch::style::Dimension::Points(10.0000),
4048 ..Default::default()
4049 },
4050 stretch::style::Node {
4051 width: stretch::style::Dimension::Points(25.0000),
4052 height: stretch::style::Dimension::Points(20.0000),
4053 ..Default::default()
4054 },
4055 stretch::style::Node {
4056 width: stretch::style::Dimension::Points(25.0000),
4057 height: stretch::style::Dimension::Points(10.0000),
4058 ..Default::default()
4059 },
4060 ],
4061 ..Default::default()
4062 },
4063 ],
4064 ..Default::default()
4065 });
4066
4067 assert_eq!(layout.width, 100.0000);
4068 assert_eq!(layout.height, 80.0000);
4069 assert_eq!(layout.x, 0.0000);
4070 assert_eq!(layout.y, 0.0000);
4071
4072 assert_eq!(layout.children[0].width, 50.0000);
4073 assert_eq!(layout.children[0].height, 60.0000);
4074 assert_eq!(layout.children[0].x, 0.0000);
4075 assert_eq!(layout.children[0].y, 0.0000);
4076
4077 assert_eq!(layout.children[1].width, 50.0000);
4078 assert_eq!(layout.children[1].height, 40.0000);
4079 assert_eq!(layout.children[1].x, 50.0000);
4080 assert_eq!(layout.children[1].y, 40.0000);
4081
4082 assert_eq!(layout.children[1].children[0].width, 25.0000);
4083 assert_eq!(layout.children[1].children[0].height, 20.0000);
4084 assert_eq!(layout.children[1].children[0].x, 0.0000);
4085 assert_eq!(layout.children[1].children[0].y, 0.0000);
4086
4087 assert_eq!(layout.children[1].children[1].width, 25.0000);
4088 assert_eq!(layout.children[1].children[1].height, 10.0000);
4089 assert_eq!(layout.children[1].children[1].x, 25.0000);
4090 assert_eq!(layout.children[1].children[1].y, 0.0000);
4091
4092 assert_eq!(layout.children[1].children[2].width, 25.0000);
4093 assert_eq!(layout.children[1].children[2].height, 20.0000);
4094 assert_eq!(layout.children[1].children[2].x, 0.0000);
4095 assert_eq!(layout.children[1].children[2].y, 20.0000);
4096
4097 assert_eq!(layout.children[1].children[3].width, 25.0000);
4098 assert_eq!(layout.children[1].children[3].height, 10.0000);
4099 assert_eq!(layout.children[1].children[3].x, 25.0000);
4100 assert_eq!(layout.children[1].children[3].y, 20.0000);
4101 }
4102
4103 #[test]
4104 fn absolute_layout_align_items_center_on_child_only() {
4105 let layout = stretch::compute(&stretch::style::Node {
4106 width: stretch::style::Dimension::Points(110.0000),
4107 height: stretch::style::Dimension::Points(100.0000),
4108 children: vec![stretch::style::Node {
4109 position: stretch::style::Position::Absolute,
4110 align_self: stretch::style::AlignSelf::Center,
4111 width: stretch::style::Dimension::Points(60.0000),
4112 height: stretch::style::Dimension::Points(40.0000),
4113 ..Default::default()
4114 }],
4115 ..Default::default()
4116 });
4117
4118 assert_eq!(layout.width, 110.0000);
4119 assert_eq!(layout.height, 100.0000);
4120 assert_eq!(layout.x, 0.0000);
4121 assert_eq!(layout.y, 0.0000);
4122
4123 assert_eq!(layout.children[0].width, 60.0000);
4124 assert_eq!(layout.children[0].height, 40.0000);
4125 assert_eq!(layout.children[0].x, 0.0000);
4126 assert_eq!(layout.children[0].y, 30.0000);
4127 }
4128
4129 #[test]
4130 fn wrap_reverse_row_single_line_different_size() {
4131 let layout = stretch::compute(&stretch::style::Node {
4132 flex_wrap: stretch::style::FlexWrap::WrapReverse,
4133 align_content: stretch::style::AlignContent::FlexStart,
4134 width: stretch::style::Dimension::Points(300.0000),
4135 children: vec![
4136 stretch::style::Node {
4137 width: stretch::style::Dimension::Points(30.0000),
4138 height: stretch::style::Dimension::Points(10.0000),
4139 ..Default::default()
4140 },
4141 stretch::style::Node {
4142 width: stretch::style::Dimension::Points(30.0000),
4143 height: stretch::style::Dimension::Points(20.0000),
4144 ..Default::default()
4145 },
4146 stretch::style::Node {
4147 width: stretch::style::Dimension::Points(30.0000),
4148 height: stretch::style::Dimension::Points(30.0000),
4149 ..Default::default()
4150 },
4151 stretch::style::Node {
4152 width: stretch::style::Dimension::Points(30.0000),
4153 height: stretch::style::Dimension::Points(40.0000),
4154 ..Default::default()
4155 },
4156 stretch::style::Node {
4157 width: stretch::style::Dimension::Points(30.0000),
4158 height: stretch::style::Dimension::Points(50.0000),
4159 ..Default::default()
4160 },
4161 ],
4162 ..Default::default()
4163 });
4164
4165 assert_eq!(layout.width, 300.0000);
4166 assert_eq!(layout.height, 50.0000);
4167 assert_eq!(layout.x, 0.0000);
4168 assert_eq!(layout.y, 0.0000);
4169
4170 assert_eq!(layout.children[0].width, 30.0000);
4171 assert_eq!(layout.children[0].height, 10.0000);
4172 assert_eq!(layout.children[0].x, 0.0000);
4173 assert_eq!(layout.children[0].y, 40.0000);
4174
4175 assert_eq!(layout.children[1].width, 30.0000);
4176 assert_eq!(layout.children[1].height, 20.0000);
4177 assert_eq!(layout.children[1].x, 30.0000);
4178 assert_eq!(layout.children[1].y, 30.0000);
4179
4180 assert_eq!(layout.children[2].width, 30.0000);
4181 assert_eq!(layout.children[2].height, 30.0000);
4182 assert_eq!(layout.children[2].x, 60.0000);
4183 assert_eq!(layout.children[2].y, 20.0000);
4184
4185 assert_eq!(layout.children[3].width, 30.0000);
4186 assert_eq!(layout.children[3].height, 40.0000);
4187 assert_eq!(layout.children[3].x, 90.0000);
4188 assert_eq!(layout.children[3].y, 10.0000);
4189
4190 assert_eq!(layout.children[4].width, 30.0000);
4191 assert_eq!(layout.children[4].height, 50.0000);
4192 assert_eq!(layout.children[4].x, 120.0000);
4193 assert_eq!(layout.children[4].y, 0.0000);
4194 }
4195
4196 #[test]
4197 fn rounding_fractial_input_4() {
4198 let layout = stretch::compute(&stretch::style::Node {
4199 flex_direction: stretch::style::FlexDirection::Column,
4200 width: stretch::style::Dimension::Points(100.0000),
4201 height: stretch::style::Dimension::Points(113.4000),
4202 children: vec![
4203 stretch::style::Node {
4204 flex_grow: 1.0000,
4205 flex_basis: stretch::style::Dimension::Points(50.0000),
4206 height: stretch::style::Dimension::Points(20.0000),
4207 ..Default::default()
4208 },
4209 stretch::style::Node {
4210 flex_grow: 1.0000,
4211 height: stretch::style::Dimension::Points(10.0000),
4212 ..Default::default()
4213 },
4214 stretch::style::Node {
4215 flex_grow: 1.0000,
4216 height: stretch::style::Dimension::Points(10.0000),
4217 ..Default::default()
4218 },
4219 ],
4220 ..Default::default()
4221 });
4222
4223 assert_eq!(layout.width, 100.0000);
4224 assert_eq!(layout.height, 113.0000);
4225 assert_eq!(layout.x, 0.0000);
4226 assert_eq!(layout.y, 0.0000);
4227
4228 assert_eq!(layout.children[0].width, 100.0000);
4229 assert_eq!(layout.children[0].height, 64.0000);
4230 assert_eq!(layout.children[0].x, 0.0000);
4231 assert_eq!(layout.children[0].y, 0.0000);
4232
4233 assert_eq!(layout.children[1].width, 100.0000);
4234 assert_eq!(layout.children[1].height, 25.0000);
4235 assert_eq!(layout.children[1].x, 0.0000);
4236 assert_eq!(layout.children[1].y, 64.0000);
4237
4238 assert_eq!(layout.children[2].width, 100.0000);
4239 assert_eq!(layout.children[2].height, 24.0000);
4240 assert_eq!(layout.children[2].x, 0.0000);
4241 assert_eq!(layout.children[2].y, 89.0000);
4242 }
4243
4244 #[test]
4245 fn width_smaller_then_content_with_flex_grow_unconstraint_size() {
4246 let layout = stretch::compute(&stretch::style::Node {
4247 children: vec![
4248 stretch::style::Node {
4249 flex_direction: stretch::style::FlexDirection::Column,
4250 flex_grow: 1.0000,
4251 width: stretch::style::Dimension::Points(0.0000),
4252 children: vec![stretch::style::Node {
4253 width: stretch::style::Dimension::Points(70.0000),
4254 height: stretch::style::Dimension::Points(100.0000),
4255 ..Default::default()
4256 }],
4257 ..Default::default()
4258 },
4259 stretch::style::Node {
4260 flex_direction: stretch::style::FlexDirection::Column,
4261 flex_grow: 1.0000,
4262 width: stretch::style::Dimension::Points(0.0000),
4263 children: vec![stretch::style::Node {
4264 width: stretch::style::Dimension::Points(20.0000),
4265 height: stretch::style::Dimension::Points(100.0000),
4266 ..Default::default()
4267 }],
4268 ..Default::default()
4269 },
4270 ],
4271 ..Default::default()
4272 });
4273
4274 assert_eq!(layout.width, 0.0000);
4275 assert_eq!(layout.height, 100.0000);
4276 assert_eq!(layout.x, 0.0000);
4277 assert_eq!(layout.y, 0.0000);
4278
4279 assert_eq!(layout.children[0].width, 0.0000);
4280 assert_eq!(layout.children[0].height, 100.0000);
4281 assert_eq!(layout.children[0].x, 0.0000);
4282 assert_eq!(layout.children[0].y, 0.0000);
4283
4284 assert_eq!(layout.children[0].children[0].width, 70.0000);
4285 assert_eq!(layout.children[0].children[0].height, 100.0000);
4286 assert_eq!(layout.children[0].children[0].x, 0.0000);
4287 assert_eq!(layout.children[0].children[0].y, 0.0000);
4288
4289 assert_eq!(layout.children[1].width, 0.0000);
4290 assert_eq!(layout.children[1].height, 100.0000);
4291 assert_eq!(layout.children[1].x, 0.0000);
4292 assert_eq!(layout.children[1].y, 0.0000);
4293
4294 assert_eq!(layout.children[1].children[0].width, 20.0000);
4295 assert_eq!(layout.children[1].children[0].height, 100.0000);
4296 assert_eq!(layout.children[1].children[0].x, 0.0000);
4297 assert_eq!(layout.children[1].children[0].y, 0.0000);
4298 }
4299
4300 #[test]
4301 fn padding_flex_child() {
4302 let layout = stretch::compute(&stretch::style::Node {
4303 width: stretch::style::Dimension::Points(100.0000),
4304 height: stretch::style::Dimension::Points(100.0000),
4305 padding: stretch::style::Edges {
4306 start: stretch::style::Dimension::Points(10.0000),
4307 end: stretch::style::Dimension::Points(10.0000),
4308 top: stretch::style::Dimension::Points(10.0000),
4309 bottom: stretch::style::Dimension::Points(10.0000),
4310 ..Default::default()
4311 },
4312 children: vec![stretch::style::Node {
4313 flex_grow: 1.0000,
4314 width: stretch::style::Dimension::Points(10.0000),
4315 ..Default::default()
4316 }],
4317 ..Default::default()
4318 });
4319
4320 assert_eq!(layout.width, 100.0000);
4321 assert_eq!(layout.height, 100.0000);
4322 assert_eq!(layout.x, 0.0000);
4323 assert_eq!(layout.y, 0.0000);
4324
4325 assert_eq!(layout.children[0].width, 80.0000);
4326 assert_eq!(layout.children[0].height, 80.0000);
4327 assert_eq!(layout.children[0].x, 10.0000);
4328 assert_eq!(layout.children[0].y, 10.0000);
4329 }
4330
4331 #[test]
4332 fn flex_direction_row_reverse() {
4333 let layout = stretch::compute(&stretch::style::Node {
4334 flex_direction: stretch::style::FlexDirection::RowReverse,
4335 width: stretch::style::Dimension::Points(100.0000),
4336 height: stretch::style::Dimension::Points(100.0000),
4337 children: vec![
4338 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
4339 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
4340 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
4341 ],
4342 ..Default::default()
4343 });
4344
4345 assert_eq!(layout.width, 100.0000);
4346 assert_eq!(layout.height, 100.0000);
4347 assert_eq!(layout.x, 0.0000);
4348 assert_eq!(layout.y, 0.0000);
4349
4350 assert_eq!(layout.children[0].width, 10.0000);
4351 assert_eq!(layout.children[0].height, 100.0000);
4352 assert_eq!(layout.children[0].x, 90.0000);
4353 assert_eq!(layout.children[0].y, 0.0000);
4354
4355 assert_eq!(layout.children[1].width, 10.0000);
4356 assert_eq!(layout.children[1].height, 100.0000);
4357 assert_eq!(layout.children[1].x, 80.0000);
4358 assert_eq!(layout.children[1].y, 0.0000);
4359
4360 assert_eq!(layout.children[2].width, 10.0000);
4361 assert_eq!(layout.children[2].height, 100.0000);
4362 assert_eq!(layout.children[2].x, 70.0000);
4363 assert_eq!(layout.children[2].y, 0.0000);
4364 }
4365
4366 #[test]
4367 fn wrap_reverse_row_align_content_stretch() {
4368 let layout = stretch::compute(&stretch::style::Node {
4369 flex_wrap: stretch::style::FlexWrap::WrapReverse,
4370 width: stretch::style::Dimension::Points(100.0000),
4371 children: vec![
4372 stretch::style::Node {
4373 width: stretch::style::Dimension::Points(30.0000),
4374 height: stretch::style::Dimension::Points(10.0000),
4375 ..Default::default()
4376 },
4377 stretch::style::Node {
4378 width: stretch::style::Dimension::Points(30.0000),
4379 height: stretch::style::Dimension::Points(20.0000),
4380 ..Default::default()
4381 },
4382 stretch::style::Node {
4383 width: stretch::style::Dimension::Points(30.0000),
4384 height: stretch::style::Dimension::Points(30.0000),
4385 ..Default::default()
4386 },
4387 stretch::style::Node {
4388 width: stretch::style::Dimension::Points(30.0000),
4389 height: stretch::style::Dimension::Points(40.0000),
4390 ..Default::default()
4391 },
4392 stretch::style::Node {
4393 width: stretch::style::Dimension::Points(30.0000),
4394 height: stretch::style::Dimension::Points(50.0000),
4395 ..Default::default()
4396 },
4397 ],
4398 ..Default::default()
4399 });
4400
4401 assert_eq!(layout.width, 100.0000);
4402 assert_eq!(layout.height, 80.0000);
4403 assert_eq!(layout.x, 0.0000);
4404 assert_eq!(layout.y, 0.0000);
4405
4406 assert_eq!(layout.children[0].width, 30.0000);
4407 assert_eq!(layout.children[0].height, 10.0000);
4408 assert_eq!(layout.children[0].x, 0.0000);
4409 assert_eq!(layout.children[0].y, 70.0000);
4410
4411 assert_eq!(layout.children[1].width, 30.0000);
4412 assert_eq!(layout.children[1].height, 20.0000);
4413 assert_eq!(layout.children[1].x, 30.0000);
4414 assert_eq!(layout.children[1].y, 60.0000);
4415
4416 assert_eq!(layout.children[2].width, 30.0000);
4417 assert_eq!(layout.children[2].height, 30.0000);
4418 assert_eq!(layout.children[2].x, 60.0000);
4419 assert_eq!(layout.children[2].y, 50.0000);
4420
4421 assert_eq!(layout.children[3].width, 30.0000);
4422 assert_eq!(layout.children[3].height, 40.0000);
4423 assert_eq!(layout.children[3].x, 0.0000);
4424 assert_eq!(layout.children[3].y, 10.0000);
4425
4426 assert_eq!(layout.children[4].width, 30.0000);
4427 assert_eq!(layout.children[4].height, 50.0000);
4428 assert_eq!(layout.children[4].x, 30.0000);
4429 assert_eq!(layout.children[4].y, 0.0000);
4430 }
4431
4432 #[test]
4433 fn margin_auto_top() {
4434 let layout = stretch::compute(&stretch::style::Node {
4435 align_items: stretch::style::AlignItems::Center,
4436 width: stretch::style::Dimension::Points(200.0000),
4437 height: stretch::style::Dimension::Points(200.0000),
4438 children: vec![
4439 stretch::style::Node {
4440 width: stretch::style::Dimension::Points(50.0000),
4441 height: stretch::style::Dimension::Points(50.0000),
4442 margin: stretch::style::Edges { top: stretch::style::Dimension::Auto, ..Default::default() },
4443 ..Default::default()
4444 },
4445 stretch::style::Node {
4446 width: stretch::style::Dimension::Points(50.0000),
4447 height: stretch::style::Dimension::Points(50.0000),
4448 ..Default::default()
4449 },
4450 ],
4451 ..Default::default()
4452 });
4453
4454 assert_eq!(layout.width, 200.0000);
4455 assert_eq!(layout.height, 200.0000);
4456 assert_eq!(layout.x, 0.0000);
4457 assert_eq!(layout.y, 0.0000);
4458
4459 assert_eq!(layout.children[0].width, 50.0000);
4460 assert_eq!(layout.children[0].height, 50.0000);
4461 assert_eq!(layout.children[0].x, 0.0000);
4462 assert_eq!(layout.children[0].y, 150.0000);
4463
4464 assert_eq!(layout.children[1].width, 50.0000);
4465 assert_eq!(layout.children[1].height, 50.0000);
4466 assert_eq!(layout.children[1].x, 50.0000);
4467 assert_eq!(layout.children[1].y, 75.0000);
4468 }
4469
4470 #[test]
4471 fn flex_grow_within_constrained_max_row() {
4472 let layout = stretch::compute(&stretch::style::Node {
4473 flex_direction: stretch::style::FlexDirection::Column,
4474 width: stretch::style::Dimension::Points(200.0000),
4475 children: vec![stretch::style::Node {
4476 max_width: stretch::style::Dimension::Points(100.0000),
4477 height: stretch::style::Dimension::Points(100.0000),
4478 children: vec![
4479 stretch::style::Node {
4480 flex_shrink: 1.0000,
4481 flex_basis: stretch::style::Dimension::Points(100.0000),
4482 ..Default::default()
4483 },
4484 stretch::style::Node { width: stretch::style::Dimension::Points(50.0000), ..Default::default() },
4485 ],
4486 ..Default::default()
4487 }],
4488 ..Default::default()
4489 });
4490
4491 assert_eq!(layout.width, 200.0000);
4492 assert_eq!(layout.height, 100.0000);
4493 assert_eq!(layout.x, 0.0000);
4494 assert_eq!(layout.y, 0.0000);
4495
4496 assert_eq!(layout.children[0].width, 100.0000);
4497 assert_eq!(layout.children[0].height, 100.0000);
4498 assert_eq!(layout.children[0].x, 0.0000);
4499 assert_eq!(layout.children[0].y, 0.0000);
4500
4501 assert_eq!(layout.children[0].children[0].width, 67.0000);
4502 assert_eq!(layout.children[0].children[0].height, 100.0000);
4503 assert_eq!(layout.children[0].children[0].x, 0.0000);
4504 assert_eq!(layout.children[0].children[0].y, 0.0000);
4505
4506 assert_eq!(layout.children[0].children[1].width, 33.0000);
4507 assert_eq!(layout.children[0].children[1].height, 100.0000);
4508 assert_eq!(layout.children[0].children[1].x, 67.0000);
4509 assert_eq!(layout.children[0].children[1].y, 0.0000);
4510 }
4511
4512 #[test]
4513 fn absolute_layout_align_items_and_justify_content_center() {
4514 let layout = stretch::compute(&stretch::style::Node {
4515 align_items: stretch::style::AlignItems::Center,
4516 justify_content: stretch::style::JustifyContent::Center,
4517 width: stretch::style::Dimension::Points(110.0000),
4518 height: stretch::style::Dimension::Points(100.0000),
4519 children: vec![stretch::style::Node {
4520 position: stretch::style::Position::Absolute,
4521 width: stretch::style::Dimension::Points(60.0000),
4522 height: stretch::style::Dimension::Points(40.0000),
4523 ..Default::default()
4524 }],
4525 ..Default::default()
4526 });
4527
4528 assert_eq!(layout.width, 110.0000);
4529 assert_eq!(layout.height, 100.0000);
4530 assert_eq!(layout.x, 0.0000);
4531 assert_eq!(layout.y, 0.0000);
4532
4533 assert_eq!(layout.children[0].width, 60.0000);
4534 assert_eq!(layout.children[0].height, 40.0000);
4535 assert_eq!(layout.children[0].x, 25.0000);
4536 assert_eq!(layout.children[0].y, 30.0000);
4537 }
4538
4539 #[test]
4540 fn align_self_flex_end() {
4541 let layout = stretch::compute(&stretch::style::Node {
4542 width: stretch::style::Dimension::Points(100.0000),
4543 height: stretch::style::Dimension::Points(100.0000),
4544 children: vec![stretch::style::Node {
4545 align_self: stretch::style::AlignSelf::FlexEnd,
4546 width: stretch::style::Dimension::Points(10.0000),
4547 height: stretch::style::Dimension::Points(10.0000),
4548 ..Default::default()
4549 }],
4550 ..Default::default()
4551 });
4552
4553 assert_eq!(layout.width, 100.0000);
4554 assert_eq!(layout.height, 100.0000);
4555 assert_eq!(layout.x, 0.0000);
4556 assert_eq!(layout.y, 0.0000);
4557
4558 assert_eq!(layout.children[0].width, 10.0000);
4559 assert_eq!(layout.children[0].height, 10.0000);
4560 assert_eq!(layout.children[0].x, 0.0000);
4561 assert_eq!(layout.children[0].y, 90.0000);
4562 }
4563
4564 #[test]
4565 fn margin_auto_left_child_bigger_than_parent() {
4566 let layout = stretch::compute(&stretch::style::Node {
4567 justify_content: stretch::style::JustifyContent::Center,
4568 width: stretch::style::Dimension::Points(52.0000),
4569 height: stretch::style::Dimension::Points(52.0000),
4570 children: vec![stretch::style::Node {
4571 width: stretch::style::Dimension::Points(72.0000),
4572 height: stretch::style::Dimension::Points(72.0000),
4573 margin: stretch::style::Edges { start: stretch::style::Dimension::Auto, ..Default::default() },
4574 ..Default::default()
4575 }],
4576 ..Default::default()
4577 });
4578
4579 assert_eq!(layout.width, 52.0000);
4580 assert_eq!(layout.height, 52.0000);
4581 assert_eq!(layout.x, 0.0000);
4582 assert_eq!(layout.y, 0.0000);
4583
4584 assert_eq!(layout.children[0].width, 52.0000);
4585 assert_eq!(layout.children[0].height, 72.0000);
4586 assert_eq!(layout.children[0].x, 0.0000);
4587 assert_eq!(layout.children[0].y, 0.0000);
4588 }
4589
4590 #[test]
4591 fn wrapped_row_within_align_items_flex_end() {
4592 let layout = stretch::compute(&stretch::style::Node {
4593 flex_direction: stretch::style::FlexDirection::Column,
4594 align_items: stretch::style::AlignItems::FlexEnd,
4595 width: stretch::style::Dimension::Points(200.0000),
4596 height: stretch::style::Dimension::Points(200.0000),
4597 children: vec![stretch::style::Node {
4598 flex_wrap: stretch::style::FlexWrap::Wrap,
4599 children: vec![
4600 stretch::style::Node {
4601 width: stretch::style::Dimension::Points(150.0000),
4602 height: stretch::style::Dimension::Points(80.0000),
4603 ..Default::default()
4604 },
4605 stretch::style::Node {
4606 width: stretch::style::Dimension::Points(80.0000),
4607 height: stretch::style::Dimension::Points(80.0000),
4608 ..Default::default()
4609 },
4610 ],
4611 ..Default::default()
4612 }],
4613 ..Default::default()
4614 });
4615
4616 assert_eq!(layout.width, 200.0000);
4617 assert_eq!(layout.height, 200.0000);
4618 assert_eq!(layout.x, 0.0000);
4619 assert_eq!(layout.y, 0.0000);
4620
4621 assert_eq!(layout.children[0].width, 200.0000);
4622 assert_eq!(layout.children[0].height, 160.0000);
4623 assert_eq!(layout.children[0].x, 0.0000);
4624 assert_eq!(layout.children[0].y, 0.0000);
4625
4626 assert_eq!(layout.children[0].children[0].width, 150.0000);
4627 assert_eq!(layout.children[0].children[0].height, 80.0000);
4628 assert_eq!(layout.children[0].children[0].x, 0.0000);
4629 assert_eq!(layout.children[0].children[0].y, 0.0000);
4630
4631 assert_eq!(layout.children[0].children[1].width, 80.0000);
4632 assert_eq!(layout.children[0].children[1].height, 80.0000);
4633 assert_eq!(layout.children[0].children[1].x, 0.0000);
4634 assert_eq!(layout.children[0].children[1].y, 80.0000);
4635 }
4636
4637 #[test]
4638 fn min_height_overrides_height() {
4639 let layout = stretch::compute(&stretch::style::Node {
4640 children: vec![stretch::style::Node {
4641 height: stretch::style::Dimension::Points(50.0000),
4642 min_height: stretch::style::Dimension::Points(100.0000),
4643 ..Default::default()
4644 }],
4645 ..Default::default()
4646 });
4647
4648 assert_eq!(layout.width, 0.0000);
4649 assert_eq!(layout.height, 100.0000);
4650 assert_eq!(layout.x, 0.0000);
4651 assert_eq!(layout.y, 0.0000);
4652
4653 assert_eq!(layout.children[0].width, 0.0000);
4654 assert_eq!(layout.children[0].height, 100.0000);
4655 assert_eq!(layout.children[0].x, 0.0000);
4656 assert_eq!(layout.children[0].y, 0.0000);
4657 }
4658
4659 #[test]
4660 fn align_strech_should_size_based_on_parent() {
4661 let layout = stretch::compute(&stretch::style::Node {
4662 width: stretch::style::Dimension::Points(100.0000),
4663 height: stretch::style::Dimension::Points(100.0000),
4664 children: vec![stretch::style::Node {
4665 justify_content: stretch::style::JustifyContent::Center,
4666 flex_grow: 0.0000,
4667 flex_shrink: 1.0000,
4668 children: vec![stretch::style::Node {
4669 flex_grow: 1.0000,
4670 flex_shrink: 1.0000,
4671 children: vec![stretch::style::Node {
4672 width: stretch::style::Dimension::Points(20.0000),
4673 height: stretch::style::Dimension::Points(20.0000),
4674 ..Default::default()
4675 }],
4676 ..Default::default()
4677 }],
4678 ..Default::default()
4679 }],
4680 ..Default::default()
4681 });
4682
4683 assert_eq!(layout.width, 100.0000);
4684 assert_eq!(layout.height, 100.0000);
4685 assert_eq!(layout.x, 0.0000);
4686 assert_eq!(layout.y, 0.0000);
4687
4688 assert_eq!(layout.children[0].width, 20.0000);
4689 assert_eq!(layout.children[0].height, 100.0000);
4690 assert_eq!(layout.children[0].x, 0.0000);
4691 assert_eq!(layout.children[0].y, 0.0000);
4692
4693 assert_eq!(layout.children[0].children[0].width, 20.0000);
4694 assert_eq!(layout.children[0].children[0].height, 100.0000);
4695 assert_eq!(layout.children[0].children[0].x, 0.0000);
4696 assert_eq!(layout.children[0].children[0].y, 0.0000);
4697
4698 assert_eq!(layout.children[0].children[0].children[0].width, 20.0000);
4699 assert_eq!(layout.children[0].children[0].children[0].height, 20.0000);
4700 assert_eq!(layout.children[0].children[0].children[0].x, 0.0000);
4701 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
4702 }
4703
4704 #[test]
4705 fn wrap_row_align_items_flex_end() {
4706 let layout = stretch::compute(&stretch::style::Node {
4707 flex_wrap: stretch::style::FlexWrap::Wrap,
4708 align_items: stretch::style::AlignItems::FlexEnd,
4709 width: stretch::style::Dimension::Points(100.0000),
4710 children: vec![
4711 stretch::style::Node {
4712 width: stretch::style::Dimension::Points(30.0000),
4713 height: stretch::style::Dimension::Points(10.0000),
4714 ..Default::default()
4715 },
4716 stretch::style::Node {
4717 width: stretch::style::Dimension::Points(30.0000),
4718 height: stretch::style::Dimension::Points(20.0000),
4719 ..Default::default()
4720 },
4721 stretch::style::Node {
4722 width: stretch::style::Dimension::Points(30.0000),
4723 height: stretch::style::Dimension::Points(30.0000),
4724 ..Default::default()
4725 },
4726 stretch::style::Node {
4727 width: stretch::style::Dimension::Points(30.0000),
4728 height: stretch::style::Dimension::Points(30.0000),
4729 ..Default::default()
4730 },
4731 ],
4732 ..Default::default()
4733 });
4734
4735 assert_eq!(layout.width, 100.0000);
4736 assert_eq!(layout.height, 60.0000);
4737 assert_eq!(layout.x, 0.0000);
4738 assert_eq!(layout.y, 0.0000);
4739
4740 assert_eq!(layout.children[0].width, 30.0000);
4741 assert_eq!(layout.children[0].height, 10.0000);
4742 assert_eq!(layout.children[0].x, 0.0000);
4743 assert_eq!(layout.children[0].y, 20.0000);
4744
4745 assert_eq!(layout.children[1].width, 30.0000);
4746 assert_eq!(layout.children[1].height, 20.0000);
4747 assert_eq!(layout.children[1].x, 30.0000);
4748 assert_eq!(layout.children[1].y, 10.0000);
4749
4750 assert_eq!(layout.children[2].width, 30.0000);
4751 assert_eq!(layout.children[2].height, 30.0000);
4752 assert_eq!(layout.children[2].x, 60.0000);
4753 assert_eq!(layout.children[2].y, 0.0000);
4754
4755 assert_eq!(layout.children[3].width, 30.0000);
4756 assert_eq!(layout.children[3].height, 30.0000);
4757 assert_eq!(layout.children[3].x, 0.0000);
4758 assert_eq!(layout.children[3].y, 30.0000);
4759 }
4760
4761 #[test]
4762 fn size_defined_by_child_with_border() {
4763 let layout = stretch::compute(&stretch::style::Node {
4764 border: stretch::style::Edges {
4765 start: stretch::style::Dimension::Points(10.0000),
4766 end: stretch::style::Dimension::Points(10.0000),
4767 top: stretch::style::Dimension::Points(10.0000),
4768 bottom: stretch::style::Dimension::Points(10.0000),
4769 ..Default::default()
4770 },
4771 children: vec![stretch::style::Node {
4772 width: stretch::style::Dimension::Points(10.0000),
4773 height: stretch::style::Dimension::Points(10.0000),
4774 ..Default::default()
4775 }],
4776 ..Default::default()
4777 });
4778
4779 assert_eq!(layout.width, 30.0000);
4780 assert_eq!(layout.height, 30.0000);
4781 assert_eq!(layout.x, 0.0000);
4782 assert_eq!(layout.y, 0.0000);
4783
4784 assert_eq!(layout.children[0].width, 10.0000);
4785 assert_eq!(layout.children[0].height, 10.0000);
4786 assert_eq!(layout.children[0].x, 10.0000);
4787 assert_eq!(layout.children[0].y, 10.0000);
4788 }
4789
4790 #[test]
4791 fn margin_auto_bottom_and_top_justify_center() {
4792 let layout = stretch::compute(&stretch::style::Node {
4793 justify_content: stretch::style::JustifyContent::Center,
4794 width: stretch::style::Dimension::Points(200.0000),
4795 height: stretch::style::Dimension::Points(200.0000),
4796 children: vec![
4797 stretch::style::Node {
4798 width: stretch::style::Dimension::Points(50.0000),
4799 height: stretch::style::Dimension::Points(50.0000),
4800 margin: stretch::style::Edges {
4801 top: stretch::style::Dimension::Auto,
4802 bottom: stretch::style::Dimension::Auto,
4803 ..Default::default()
4804 },
4805 ..Default::default()
4806 },
4807 stretch::style::Node {
4808 width: stretch::style::Dimension::Points(50.0000),
4809 height: stretch::style::Dimension::Points(50.0000),
4810 ..Default::default()
4811 },
4812 ],
4813 ..Default::default()
4814 });
4815
4816 assert_eq!(layout.width, 200.0000);
4817 assert_eq!(layout.height, 200.0000);
4818 assert_eq!(layout.x, 0.0000);
4819 assert_eq!(layout.y, 0.0000);
4820
4821 assert_eq!(layout.children[0].width, 50.0000);
4822 assert_eq!(layout.children[0].height, 50.0000);
4823 assert_eq!(layout.children[0].x, 50.0000);
4824 assert_eq!(layout.children[0].y, 75.0000);
4825
4826 assert_eq!(layout.children[1].width, 50.0000);
4827 assert_eq!(layout.children[1].height, 50.0000);
4828 assert_eq!(layout.children[1].x, 100.0000);
4829 assert_eq!(layout.children[1].y, 0.0000);
4830 }
4831
4832 #[test]
4833 fn flex_basis_overrides_main_size() {
4834 let layout = stretch::compute(&stretch::style::Node {
4835 width: stretch::style::Dimension::Points(100.0000),
4836 height: stretch::style::Dimension::Points(100.0000),
4837 children: vec![
4838 stretch::style::Node {
4839 flex_grow: 1.0000,
4840 flex_basis: stretch::style::Dimension::Points(50.0000),
4841 width: stretch::style::Dimension::Points(20.0000),
4842 ..Default::default()
4843 },
4844 stretch::style::Node {
4845 flex_grow: 1.0000,
4846 width: stretch::style::Dimension::Points(10.0000),
4847 ..Default::default()
4848 },
4849 stretch::style::Node {
4850 flex_grow: 1.0000,
4851 width: stretch::style::Dimension::Points(10.0000),
4852 ..Default::default()
4853 },
4854 ],
4855 ..Default::default()
4856 });
4857
4858 assert_eq!(layout.width, 100.0000);
4859 assert_eq!(layout.height, 100.0000);
4860 assert_eq!(layout.x, 0.0000);
4861 assert_eq!(layout.y, 0.0000);
4862
4863 assert_eq!(layout.children[0].width, 60.0000);
4864 assert_eq!(layout.children[0].height, 100.0000);
4865 assert_eq!(layout.children[0].x, 0.0000);
4866 assert_eq!(layout.children[0].y, 0.0000);
4867
4868 assert_eq!(layout.children[1].width, 20.0000);
4869 assert_eq!(layout.children[1].height, 100.0000);
4870 assert_eq!(layout.children[1].x, 60.0000);
4871 assert_eq!(layout.children[1].y, 0.0000);
4872
4873 assert_eq!(layout.children[2].width, 20.0000);
4874 assert_eq!(layout.children[2].height, 100.0000);
4875 assert_eq!(layout.children[2].x, 80.0000);
4876 assert_eq!(layout.children[2].y, 0.0000);
4877 }
4878
4879 #[test]
4880 fn wrapped_row_within_align_items_flex_start() {
4881 let layout = stretch::compute(&stretch::style::Node {
4882 flex_direction: stretch::style::FlexDirection::Column,
4883 align_items: stretch::style::AlignItems::FlexStart,
4884 width: stretch::style::Dimension::Points(200.0000),
4885 height: stretch::style::Dimension::Points(200.0000),
4886 children: vec![stretch::style::Node {
4887 flex_wrap: stretch::style::FlexWrap::Wrap,
4888 children: vec![
4889 stretch::style::Node {
4890 width: stretch::style::Dimension::Points(150.0000),
4891 height: stretch::style::Dimension::Points(80.0000),
4892 ..Default::default()
4893 },
4894 stretch::style::Node {
4895 width: stretch::style::Dimension::Points(80.0000),
4896 height: stretch::style::Dimension::Points(80.0000),
4897 ..Default::default()
4898 },
4899 ],
4900 ..Default::default()
4901 }],
4902 ..Default::default()
4903 });
4904
4905 assert_eq!(layout.width, 200.0000);
4906 assert_eq!(layout.height, 200.0000);
4907 assert_eq!(layout.x, 0.0000);
4908 assert_eq!(layout.y, 0.0000);
4909
4910 assert_eq!(layout.children[0].width, 200.0000);
4911 assert_eq!(layout.children[0].height, 160.0000);
4912 assert_eq!(layout.children[0].x, 0.0000);
4913 assert_eq!(layout.children[0].y, 0.0000);
4914
4915 assert_eq!(layout.children[0].children[0].width, 150.0000);
4916 assert_eq!(layout.children[0].children[0].height, 80.0000);
4917 assert_eq!(layout.children[0].children[0].x, 0.0000);
4918 assert_eq!(layout.children[0].children[0].y, 0.0000);
4919
4920 assert_eq!(layout.children[0].children[1].width, 80.0000);
4921 assert_eq!(layout.children[0].children[1].height, 80.0000);
4922 assert_eq!(layout.children[0].children[1].x, 0.0000);
4923 assert_eq!(layout.children[0].children[1].y, 80.0000);
4924 }
4925
4926 #[test]
4927 fn align_center_should_size_based_on_content() {
4928 let layout = stretch::compute(&stretch::style::Node {
4929 align_items: stretch::style::AlignItems::Center,
4930 width: stretch::style::Dimension::Points(100.0000),
4931 height: stretch::style::Dimension::Points(100.0000),
4932 children: vec![stretch::style::Node {
4933 justify_content: stretch::style::JustifyContent::Center,
4934 flex_grow: 0.0000,
4935 flex_shrink: 1.0000,
4936 children: vec![stretch::style::Node {
4937 flex_grow: 1.0000,
4938 flex_shrink: 1.0000,
4939 children: vec![stretch::style::Node {
4940 width: stretch::style::Dimension::Points(20.0000),
4941 height: stretch::style::Dimension::Points(20.0000),
4942 ..Default::default()
4943 }],
4944 ..Default::default()
4945 }],
4946 ..Default::default()
4947 }],
4948 ..Default::default()
4949 });
4950
4951 assert_eq!(layout.width, 100.0000);
4952 assert_eq!(layout.height, 100.0000);
4953 assert_eq!(layout.x, 0.0000);
4954 assert_eq!(layout.y, 0.0000);
4955
4956 assert_eq!(layout.children[0].width, 20.0000);
4957 assert_eq!(layout.children[0].height, 20.0000);
4958 assert_eq!(layout.children[0].x, 0.0000);
4959 assert_eq!(layout.children[0].y, 40.0000);
4960
4961 assert_eq!(layout.children[0].children[0].width, 20.0000);
4962 assert_eq!(layout.children[0].children[0].height, 20.0000);
4963 assert_eq!(layout.children[0].children[0].x, 0.0000);
4964 assert_eq!(layout.children[0].children[0].y, 0.0000);
4965
4966 assert_eq!(layout.children[0].children[0].children[0].width, 20.0000);
4967 assert_eq!(layout.children[0].children[0].children[0].height, 20.0000);
4968 assert_eq!(layout.children[0].children[0].children[0].x, 0.0000);
4969 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
4970 }
4971
4972 #[test]
4973 fn margin_auto_right() {
4974 let layout = stretch::compute(&stretch::style::Node {
4975 align_items: stretch::style::AlignItems::Center,
4976 width: stretch::style::Dimension::Points(200.0000),
4977 height: stretch::style::Dimension::Points(200.0000),
4978 children: vec![
4979 stretch::style::Node {
4980 width: stretch::style::Dimension::Points(50.0000),
4981 height: stretch::style::Dimension::Points(50.0000),
4982 margin: stretch::style::Edges { end: stretch::style::Dimension::Auto, ..Default::default() },
4983 ..Default::default()
4984 },
4985 stretch::style::Node {
4986 width: stretch::style::Dimension::Points(50.0000),
4987 height: stretch::style::Dimension::Points(50.0000),
4988 ..Default::default()
4989 },
4990 ],
4991 ..Default::default()
4992 });
4993
4994 assert_eq!(layout.width, 200.0000);
4995 assert_eq!(layout.height, 200.0000);
4996 assert_eq!(layout.x, 0.0000);
4997 assert_eq!(layout.y, 0.0000);
4998
4999 assert_eq!(layout.children[0].width, 50.0000);
5000 assert_eq!(layout.children[0].height, 50.0000);
5001 assert_eq!(layout.children[0].x, 0.0000);
5002 assert_eq!(layout.children[0].y, 75.0000);
5003
5004 assert_eq!(layout.children[1].width, 50.0000);
5005 assert_eq!(layout.children[1].height, 50.0000);
5006 assert_eq!(layout.children[1].x, 150.0000);
5007 assert_eq!(layout.children[1].y, 75.0000);
5008 }
5009
5010 #[test]
5011 fn wrap_reverse_row_align_content_center() {
5012 let layout = stretch::compute(&stretch::style::Node {
5013 flex_wrap: stretch::style::FlexWrap::WrapReverse,
5014 align_content: stretch::style::AlignContent::Center,
5015 width: stretch::style::Dimension::Points(100.0000),
5016 children: vec![
5017 stretch::style::Node {
5018 width: stretch::style::Dimension::Points(30.0000),
5019 height: stretch::style::Dimension::Points(10.0000),
5020 ..Default::default()
5021 },
5022 stretch::style::Node {
5023 width: stretch::style::Dimension::Points(30.0000),
5024 height: stretch::style::Dimension::Points(20.0000),
5025 ..Default::default()
5026 },
5027 stretch::style::Node {
5028 width: stretch::style::Dimension::Points(30.0000),
5029 height: stretch::style::Dimension::Points(30.0000),
5030 ..Default::default()
5031 },
5032 stretch::style::Node {
5033 width: stretch::style::Dimension::Points(30.0000),
5034 height: stretch::style::Dimension::Points(40.0000),
5035 ..Default::default()
5036 },
5037 stretch::style::Node {
5038 width: stretch::style::Dimension::Points(30.0000),
5039 height: stretch::style::Dimension::Points(50.0000),
5040 ..Default::default()
5041 },
5042 ],
5043 ..Default::default()
5044 });
5045
5046 assert_eq!(layout.width, 100.0000);
5047 assert_eq!(layout.height, 80.0000);
5048 assert_eq!(layout.x, 0.0000);
5049 assert_eq!(layout.y, 0.0000);
5050
5051 assert_eq!(layout.children[0].width, 30.0000);
5052 assert_eq!(layout.children[0].height, 10.0000);
5053 assert_eq!(layout.children[0].x, 0.0000);
5054 assert_eq!(layout.children[0].y, 70.0000);
5055
5056 assert_eq!(layout.children[1].width, 30.0000);
5057 assert_eq!(layout.children[1].height, 20.0000);
5058 assert_eq!(layout.children[1].x, 30.0000);
5059 assert_eq!(layout.children[1].y, 60.0000);
5060
5061 assert_eq!(layout.children[2].width, 30.0000);
5062 assert_eq!(layout.children[2].height, 30.0000);
5063 assert_eq!(layout.children[2].x, 60.0000);
5064 assert_eq!(layout.children[2].y, 50.0000);
5065
5066 assert_eq!(layout.children[3].width, 30.0000);
5067 assert_eq!(layout.children[3].height, 40.0000);
5068 assert_eq!(layout.children[3].x, 0.0000);
5069 assert_eq!(layout.children[3].y, 10.0000);
5070
5071 assert_eq!(layout.children[4].width, 30.0000);
5072 assert_eq!(layout.children[4].height, 50.0000);
5073 assert_eq!(layout.children[4].x, 30.0000);
5074 assert_eq!(layout.children[4].y, 0.0000);
5075 }
5076
5077 #[test]
5078 fn padding_no_child() {
5079 let layout = stretch::compute(&stretch::style::Node {
5080 padding: stretch::style::Edges {
5081 start: stretch::style::Dimension::Points(10.0000),
5082 end: stretch::style::Dimension::Points(10.0000),
5083 top: stretch::style::Dimension::Points(10.0000),
5084 bottom: stretch::style::Dimension::Points(10.0000),
5085 ..Default::default()
5086 },
5087 ..Default::default()
5088 });
5089
5090 assert_eq!(layout.width, 20.0000);
5091 assert_eq!(layout.height, 20.0000);
5092 assert_eq!(layout.x, 0.0000);
5093 assert_eq!(layout.y, 0.0000);
5094 }
5095
5096 #[test]
5097 fn margin_with_sibling_column() {
5098 let layout = stretch::compute(&stretch::style::Node {
5099 flex_direction: stretch::style::FlexDirection::Column,
5100 width: stretch::style::Dimension::Points(100.0000),
5101 height: stretch::style::Dimension::Points(100.0000),
5102 children: vec![
5103 stretch::style::Node {
5104 flex_grow: 1.0000,
5105 margin: stretch::style::Edges {
5106 bottom: stretch::style::Dimension::Points(10.0000),
5107 ..Default::default()
5108 },
5109 ..Default::default()
5110 },
5111 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
5112 ],
5113 ..Default::default()
5114 });
5115
5116 assert_eq!(layout.width, 100.0000);
5117 assert_eq!(layout.height, 100.0000);
5118 assert_eq!(layout.x, 0.0000);
5119 assert_eq!(layout.y, 0.0000);
5120
5121 assert_eq!(layout.children[0].width, 100.0000);
5122 assert_eq!(layout.children[0].height, 45.0000);
5123 assert_eq!(layout.children[0].x, 0.0000);
5124 assert_eq!(layout.children[0].y, 0.0000);
5125
5126 assert_eq!(layout.children[1].width, 100.0000);
5127 assert_eq!(layout.children[1].height, 45.0000);
5128 assert_eq!(layout.children[1].x, 0.0000);
5129 assert_eq!(layout.children[1].y, 55.0000);
5130 }
5131
5132 #[test]
5133 fn flex_direction_row_no_width() {
5134 let layout = stretch::compute(&stretch::style::Node {
5135 height: stretch::style::Dimension::Points(100.0000),
5136 children: vec![
5137 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
5138 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
5139 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
5140 ],
5141 ..Default::default()
5142 });
5143
5144 assert_eq!(layout.width, 30.0000);
5145 assert_eq!(layout.height, 100.0000);
5146 assert_eq!(layout.x, 0.0000);
5147 assert_eq!(layout.y, 0.0000);
5148
5149 assert_eq!(layout.children[0].width, 10.0000);
5150 assert_eq!(layout.children[0].height, 100.0000);
5151 assert_eq!(layout.children[0].x, 0.0000);
5152 assert_eq!(layout.children[0].y, 0.0000);
5153
5154 assert_eq!(layout.children[1].width, 10.0000);
5155 assert_eq!(layout.children[1].height, 100.0000);
5156 assert_eq!(layout.children[1].x, 10.0000);
5157 assert_eq!(layout.children[1].y, 0.0000);
5158
5159 assert_eq!(layout.children[2].width, 10.0000);
5160 assert_eq!(layout.children[2].height, 100.0000);
5161 assert_eq!(layout.children[2].x, 20.0000);
5162 assert_eq!(layout.children[2].y, 0.0000);
5163 }
5164
5165 #[test]
5166 fn max_width_overrides_width_on_root() {
5167 let layout = stretch::compute(&stretch::style::Node {
5168 width: stretch::style::Dimension::Points(200.0000),
5169 max_width: stretch::style::Dimension::Points(100.0000),
5170 ..Default::default()
5171 });
5172
5173 assert_eq!(layout.width, 100.0000);
5174 assert_eq!(layout.height, 0.0000);
5175 assert_eq!(layout.x, 0.0000);
5176 assert_eq!(layout.y, 0.0000);
5177 }
5178
5179 #[test]
5180 fn margin_auto_left_and_right() {
5181 let layout = stretch::compute(&stretch::style::Node {
5182 width: stretch::style::Dimension::Points(200.0000),
5183 height: stretch::style::Dimension::Points(200.0000),
5184 children: vec![
5185 stretch::style::Node {
5186 width: stretch::style::Dimension::Points(50.0000),
5187 height: stretch::style::Dimension::Points(50.0000),
5188 margin: stretch::style::Edges {
5189 start: stretch::style::Dimension::Auto,
5190 end: stretch::style::Dimension::Auto,
5191 ..Default::default()
5192 },
5193 ..Default::default()
5194 },
5195 stretch::style::Node {
5196 width: stretch::style::Dimension::Points(50.0000),
5197 height: stretch::style::Dimension::Points(50.0000),
5198 ..Default::default()
5199 },
5200 ],
5201 ..Default::default()
5202 });
5203
5204 assert_eq!(layout.width, 200.0000);
5205 assert_eq!(layout.height, 200.0000);
5206 assert_eq!(layout.x, 0.0000);
5207 assert_eq!(layout.y, 0.0000);
5208
5209 assert_eq!(layout.children[0].width, 50.0000);
5210 assert_eq!(layout.children[0].height, 50.0000);
5211 assert_eq!(layout.children[0].x, 50.0000);
5212 assert_eq!(layout.children[0].y, 0.0000);
5213
5214 assert_eq!(layout.children[1].width, 50.0000);
5215 assert_eq!(layout.children[1].height, 50.0000);
5216 assert_eq!(layout.children[1].x, 150.0000);
5217 assert_eq!(layout.children[1].y, 0.0000);
5218 }
5219
5220 #[test]
5221 fn flex_direction_column_no_height() {
5222 let layout = stretch::compute(&stretch::style::Node {
5223 flex_direction: stretch::style::FlexDirection::Column,
5224 width: stretch::style::Dimension::Points(100.0000),
5225 children: vec![
5226 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
5227 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
5228 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
5229 ],
5230 ..Default::default()
5231 });
5232
5233 assert_eq!(layout.width, 100.0000);
5234 assert_eq!(layout.height, 30.0000);
5235 assert_eq!(layout.x, 0.0000);
5236 assert_eq!(layout.y, 0.0000);
5237
5238 assert_eq!(layout.children[0].width, 100.0000);
5239 assert_eq!(layout.children[0].height, 10.0000);
5240 assert_eq!(layout.children[0].x, 0.0000);
5241 assert_eq!(layout.children[0].y, 0.0000);
5242
5243 assert_eq!(layout.children[1].width, 100.0000);
5244 assert_eq!(layout.children[1].height, 10.0000);
5245 assert_eq!(layout.children[1].x, 0.0000);
5246 assert_eq!(layout.children[1].y, 10.0000);
5247
5248 assert_eq!(layout.children[2].width, 100.0000);
5249 assert_eq!(layout.children[2].height, 10.0000);
5250 assert_eq!(layout.children[2].x, 0.0000);
5251 assert_eq!(layout.children[2].y, 20.0000);
5252 }
5253
5254 #[test]
5255 fn flex_basis_unconstraint_column() {
5256 let layout = stretch::compute(&stretch::style::Node {
5257 flex_direction: stretch::style::FlexDirection::Column,
5258 children: vec![stretch::style::Node {
5259 flex_basis: stretch::style::Dimension::Points(50.0000),
5260 width: stretch::style::Dimension::Points(100.0000),
5261 ..Default::default()
5262 }],
5263 ..Default::default()
5264 });
5265
5266 assert_eq!(layout.width, 100.0000);
5267 assert_eq!(layout.height, 50.0000);
5268 assert_eq!(layout.x, 0.0000);
5269 assert_eq!(layout.y, 0.0000);
5270
5271 assert_eq!(layout.children[0].width, 100.0000);
5272 assert_eq!(layout.children[0].height, 50.0000);
5273 assert_eq!(layout.children[0].x, 0.0000);
5274 assert_eq!(layout.children[0].y, 0.0000);
5275 }
5276
5277 #[test]
5278 fn width_smaller_then_content_with_flex_grow_small_size() {
5279 let layout = stretch::compute(&stretch::style::Node {
5280 width: stretch::style::Dimension::Points(10.0000),
5281 children: vec![
5282 stretch::style::Node {
5283 flex_direction: stretch::style::FlexDirection::Column,
5284 flex_grow: 1.0000,
5285 width: stretch::style::Dimension::Points(0.0000),
5286 children: vec![stretch::style::Node {
5287 width: stretch::style::Dimension::Points(70.0000),
5288 height: stretch::style::Dimension::Points(100.0000),
5289 ..Default::default()
5290 }],
5291 ..Default::default()
5292 },
5293 stretch::style::Node {
5294 flex_direction: stretch::style::FlexDirection::Column,
5295 flex_grow: 1.0000,
5296 width: stretch::style::Dimension::Points(0.0000),
5297 children: vec![stretch::style::Node {
5298 width: stretch::style::Dimension::Points(20.0000),
5299 height: stretch::style::Dimension::Points(100.0000),
5300 ..Default::default()
5301 }],
5302 ..Default::default()
5303 },
5304 ],
5305 ..Default::default()
5306 });
5307
5308 assert_eq!(layout.width, 10.0000);
5309 assert_eq!(layout.height, 100.0000);
5310 assert_eq!(layout.x, 0.0000);
5311 assert_eq!(layout.y, 0.0000);
5312
5313 assert_eq!(layout.children[0].width, 5.0000);
5314 assert_eq!(layout.children[0].height, 100.0000);
5315 assert_eq!(layout.children[0].x, 0.0000);
5316 assert_eq!(layout.children[0].y, 0.0000);
5317
5318 assert_eq!(layout.children[0].children[0].width, 70.0000);
5319 assert_eq!(layout.children[0].children[0].height, 100.0000);
5320 assert_eq!(layout.children[0].children[0].x, 0.0000);
5321 assert_eq!(layout.children[0].children[0].y, 0.0000);
5322
5323 assert_eq!(layout.children[1].width, 5.0000);
5324 assert_eq!(layout.children[1].height, 100.0000);
5325 assert_eq!(layout.children[1].x, 5.0000);
5326 assert_eq!(layout.children[1].y, 0.0000);
5327
5328 assert_eq!(layout.children[1].children[0].width, 20.0000);
5329 assert_eq!(layout.children[1].children[0].height, 100.0000);
5330 assert_eq!(layout.children[1].children[0].x, 0.0000);
5331 assert_eq!(layout.children[1].children[0].y, 0.0000);
5332 }
5333
5334 #[test]
5335 fn absolute_layout_in_wrap_reverse_row_container() {
5336 let layout = stretch::compute(&stretch::style::Node {
5337 flex_wrap: stretch::style::FlexWrap::WrapReverse,
5338 width: stretch::style::Dimension::Points(100.0000),
5339 height: stretch::style::Dimension::Points(100.0000),
5340 children: vec![stretch::style::Node {
5341 position: stretch::style::Position::Absolute,
5342 width: stretch::style::Dimension::Points(20.0000),
5343 height: stretch::style::Dimension::Points(20.0000),
5344 ..Default::default()
5345 }],
5346 ..Default::default()
5347 });
5348
5349 assert_eq!(layout.width, 100.0000);
5350 assert_eq!(layout.height, 100.0000);
5351 assert_eq!(layout.x, 0.0000);
5352 assert_eq!(layout.y, 0.0000);
5353
5354 assert_eq!(layout.children[0].width, 20.0000);
5355 assert_eq!(layout.children[0].height, 20.0000);
5356 assert_eq!(layout.children[0].x, 0.0000);
5357 assert_eq!(layout.children[0].y, 80.0000);
5358 }
5359
5360 #[test]
5361 fn flex_basis_and_main_dimen_set_when_flexing() {
5362 let layout = stretch::compute(&stretch::style::Node {
5363 width: stretch::style::Dimension::Points(100.0000),
5364 children: vec![
5365 stretch::style::Node {
5366 flex_grow: 1.0000,
5367 flex_basis: stretch::style::Dimension::Points(10.0000),
5368 width: stretch::style::Dimension::Points(50.0000),
5369 height: stretch::style::Dimension::Points(50.0000),
5370 ..Default::default()
5371 },
5372 stretch::style::Node {
5373 flex_grow: 1.0000,
5374 flex_basis: stretch::style::Dimension::Points(10.0000),
5375 width: stretch::style::Dimension::Points(0.0000),
5376 height: stretch::style::Dimension::Points(50.0000),
5377 ..Default::default()
5378 },
5379 ],
5380 ..Default::default()
5381 });
5382
5383 assert_eq!(layout.width, 100.0000);
5384 assert_eq!(layout.height, 50.0000);
5385 assert_eq!(layout.x, 0.0000);
5386 assert_eq!(layout.y, 0.0000);
5387
5388 assert_eq!(layout.children[0].width, 50.0000);
5389 assert_eq!(layout.children[0].height, 50.0000);
5390 assert_eq!(layout.children[0].x, 0.0000);
5391 assert_eq!(layout.children[0].y, 0.0000);
5392
5393 assert_eq!(layout.children[1].width, 50.0000);
5394 assert_eq!(layout.children[1].height, 50.0000);
5395 assert_eq!(layout.children[1].x, 50.0000);
5396 assert_eq!(layout.children[1].y, 0.0000);
5397 }
5398
5399 #[test]
5400 fn flex_basis_smaller_than_main_dimen_column() {
5401 let layout = stretch::compute(&stretch::style::Node {
5402 flex_direction: stretch::style::FlexDirection::Column,
5403 height: stretch::style::Dimension::Points(100.0000),
5404 children: vec![stretch::style::Node {
5405 flex_basis: stretch::style::Dimension::Points(10.0000),
5406 width: stretch::style::Dimension::Points(50.0000),
5407 height: stretch::style::Dimension::Points(50.0000),
5408 ..Default::default()
5409 }],
5410 ..Default::default()
5411 });
5412
5413 assert_eq!(layout.width, 50.0000);
5414 assert_eq!(layout.height, 100.0000);
5415 assert_eq!(layout.x, 0.0000);
5416 assert_eq!(layout.y, 0.0000);
5417
5418 assert_eq!(layout.children[0].width, 50.0000);
5419 assert_eq!(layout.children[0].height, 10.0000);
5420 assert_eq!(layout.children[0].x, 0.0000);
5421 assert_eq!(layout.children[0].y, 0.0000);
5422 }
5423
5424 #[test]
5425 fn percentage_margin_should_calculate_based_only_on_width() {
5426 let layout = stretch::compute(&stretch::style::Node {
5427 flex_direction: stretch::style::FlexDirection::Column,
5428 width: stretch::style::Dimension::Points(200.0000),
5429 height: stretch::style::Dimension::Points(100.0000),
5430 children: vec![stretch::style::Node {
5431 flex_direction: stretch::style::FlexDirection::Column,
5432 flex_grow: 1.0000,
5433 margin: stretch::style::Edges {
5434 start: stretch::style::Dimension::Percent(0.1000),
5435 end: stretch::style::Dimension::Percent(0.1000),
5436 top: stretch::style::Dimension::Percent(0.1000),
5437 bottom: stretch::style::Dimension::Percent(0.1000),
5438 ..Default::default()
5439 },
5440 children: vec![stretch::style::Node {
5441 width: stretch::style::Dimension::Points(10.0000),
5442 height: stretch::style::Dimension::Points(10.0000),
5443 ..Default::default()
5444 }],
5445 ..Default::default()
5446 }],
5447 ..Default::default()
5448 });
5449
5450 assert_eq!(layout.width, 200.0000);
5451 assert_eq!(layout.height, 100.0000);
5452 assert_eq!(layout.x, 0.0000);
5453 assert_eq!(layout.y, 0.0000);
5454
5455 assert_eq!(layout.children[0].width, 160.0000);
5456 assert_eq!(layout.children[0].height, 60.0000);
5457 assert_eq!(layout.children[0].x, 20.0000);
5458 assert_eq!(layout.children[0].y, 20.0000);
5459
5460 assert_eq!(layout.children[0].children[0].width, 10.0000);
5461 assert_eq!(layout.children[0].children[0].height, 10.0000);
5462 assert_eq!(layout.children[0].children[0].x, 0.0000);
5463 assert_eq!(layout.children[0].children[0].y, 0.0000);
5464 }
5465
5466 #[test]
5467 fn absolute_layout_start_top_end_bottom() {
5468 let layout = stretch::compute(&stretch::style::Node {
5469 width: stretch::style::Dimension::Points(100.0000),
5470 height: stretch::style::Dimension::Points(100.0000),
5471 children: vec![stretch::style::Node {
5472 position: stretch::style::Position::Absolute,
5473 start: stretch::style::Dimension::Points(10.0000),
5474 end: stretch::style::Dimension::Points(10.0000),
5475 top: stretch::style::Dimension::Points(10.0000),
5476 bottom: stretch::style::Dimension::Points(10.0000),
5477 ..Default::default()
5478 }],
5479 ..Default::default()
5480 });
5481
5482 assert_eq!(layout.width, 100.0000);
5483 assert_eq!(layout.height, 100.0000);
5484 assert_eq!(layout.x, 0.0000);
5485 assert_eq!(layout.y, 0.0000);
5486
5487 assert_eq!(layout.children[0].width, 80.0000);
5488 assert_eq!(layout.children[0].height, 80.0000);
5489 assert_eq!(layout.children[0].x, 10.0000);
5490 assert_eq!(layout.children[0].y, 10.0000);
5491 }
5492
5493 #[test]
5494 fn min_width() {
5495 let layout = stretch::compute(&stretch::style::Node {
5496 width: stretch::style::Dimension::Points(100.0000),
5497 height: stretch::style::Dimension::Points(100.0000),
5498 children: vec![
5499 stretch::style::Node {
5500 flex_grow: 1.0000,
5501 min_width: stretch::style::Dimension::Points(60.0000),
5502 ..Default::default()
5503 },
5504 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
5505 ],
5506 ..Default::default()
5507 });
5508
5509 assert_eq!(layout.width, 100.0000);
5510 assert_eq!(layout.height, 100.0000);
5511 assert_eq!(layout.x, 0.0000);
5512 assert_eq!(layout.y, 0.0000);
5513
5514 assert_eq!(layout.children[0].width, 80.0000);
5515 assert_eq!(layout.children[0].height, 100.0000);
5516 assert_eq!(layout.children[0].x, 0.0000);
5517 assert_eq!(layout.children[0].y, 0.0000);
5518
5519 assert_eq!(layout.children[1].width, 20.0000);
5520 assert_eq!(layout.children[1].height, 100.0000);
5521 assert_eq!(layout.children[1].x, 80.0000);
5522 assert_eq!(layout.children[1].y, 0.0000);
5523 }
5524
5525 #[test]
5526 fn min_height_overrides_height_on_root() {
5527 let layout = stretch::compute(&stretch::style::Node {
5528 height: stretch::style::Dimension::Points(50.0000),
5529 min_height: stretch::style::Dimension::Points(100.0000),
5530 ..Default::default()
5531 });
5532
5533 assert_eq!(layout.width, 0.0000);
5534 assert_eq!(layout.height, 100.0000);
5535 assert_eq!(layout.x, 0.0000);
5536 assert_eq!(layout.y, 0.0000);
5537 }
5538
5539 #[test]
5540 fn absolute_layout_width_height_end_bottom() {
5541 let layout = stretch::compute(&stretch::style::Node {
5542 width: stretch::style::Dimension::Points(100.0000),
5543 height: stretch::style::Dimension::Points(100.0000),
5544 children: vec![stretch::style::Node {
5545 position: stretch::style::Position::Absolute,
5546 width: stretch::style::Dimension::Points(10.0000),
5547 height: stretch::style::Dimension::Points(10.0000),
5548 end: stretch::style::Dimension::Points(10.0000),
5549 bottom: stretch::style::Dimension::Points(10.0000),
5550 ..Default::default()
5551 }],
5552 ..Default::default()
5553 });
5554
5555 assert_eq!(layout.width, 100.0000);
5556 assert_eq!(layout.height, 100.0000);
5557 assert_eq!(layout.x, 0.0000);
5558 assert_eq!(layout.y, 0.0000);
5559
5560 assert_eq!(layout.children[0].width, 10.0000);
5561 assert_eq!(layout.children[0].height, 10.0000);
5562 assert_eq!(layout.children[0].x, 80.0000);
5563 assert_eq!(layout.children[0].y, 80.0000);
5564 }
5565
5566 #[test]
5567 fn align_self_center() {
5568 let layout = stretch::compute(&stretch::style::Node {
5569 width: stretch::style::Dimension::Points(100.0000),
5570 height: stretch::style::Dimension::Points(100.0000),
5571 children: vec![stretch::style::Node {
5572 align_self: stretch::style::AlignSelf::Center,
5573 width: stretch::style::Dimension::Points(10.0000),
5574 height: stretch::style::Dimension::Points(10.0000),
5575 ..Default::default()
5576 }],
5577 ..Default::default()
5578 });
5579
5580 assert_eq!(layout.width, 100.0000);
5581 assert_eq!(layout.height, 100.0000);
5582 assert_eq!(layout.x, 0.0000);
5583 assert_eq!(layout.y, 0.0000);
5584
5585 assert_eq!(layout.children[0].width, 10.0000);
5586 assert_eq!(layout.children[0].height, 10.0000);
5587 assert_eq!(layout.children[0].x, 0.0000);
5588 assert_eq!(layout.children[0].y, 45.0000);
5589 }
5590
5591 #[test]
5592 fn wrapped_column_max_height() {
5593 let layout = stretch::compute(&stretch::style::Node {
5594 flex_direction: stretch::style::FlexDirection::Column,
5595 flex_wrap: stretch::style::FlexWrap::Wrap,
5596 align_items: stretch::style::AlignItems::Center,
5597 align_content: stretch::style::AlignContent::Center,
5598 justify_content: stretch::style::JustifyContent::Center,
5599 width: stretch::style::Dimension::Points(700.0000),
5600 height: stretch::style::Dimension::Points(500.0000),
5601 children: vec![
5602 stretch::style::Node {
5603 width: stretch::style::Dimension::Points(100.0000),
5604 height: stretch::style::Dimension::Points(500.0000),
5605 max_height: stretch::style::Dimension::Points(200.0000),
5606 ..Default::default()
5607 },
5608 stretch::style::Node {
5609 width: stretch::style::Dimension::Points(200.0000),
5610 height: stretch::style::Dimension::Points(200.0000),
5611 margin: stretch::style::Edges {
5612 start: stretch::style::Dimension::Points(20.0000),
5613 end: stretch::style::Dimension::Points(20.0000),
5614 top: stretch::style::Dimension::Points(20.0000),
5615 bottom: stretch::style::Dimension::Points(20.0000),
5616 ..Default::default()
5617 },
5618 ..Default::default()
5619 },
5620 stretch::style::Node {
5621 width: stretch::style::Dimension::Points(100.0000),
5622 height: stretch::style::Dimension::Points(100.0000),
5623 ..Default::default()
5624 },
5625 ],
5626 ..Default::default()
5627 });
5628
5629 assert_eq!(layout.width, 700.0000);
5630 assert_eq!(layout.height, 500.0000);
5631 assert_eq!(layout.x, 0.0000);
5632 assert_eq!(layout.y, 0.0000);
5633
5634 assert_eq!(layout.children[0].width, 100.0000);
5635 assert_eq!(layout.children[0].height, 200.0000);
5636 assert_eq!(layout.children[0].x, 250.0000);
5637 assert_eq!(layout.children[0].y, 30.0000);
5638
5639 assert_eq!(layout.children[1].width, 200.0000);
5640 assert_eq!(layout.children[1].height, 200.0000);
5641 assert_eq!(layout.children[1].x, 200.0000);
5642 assert_eq!(layout.children[1].y, 250.0000);
5643
5644 assert_eq!(layout.children[2].width, 100.0000);
5645 assert_eq!(layout.children[2].height, 100.0000);
5646 assert_eq!(layout.children[2].x, 420.0000);
5647 assert_eq!(layout.children[2].y, 200.0000);
5648 }
5649
5650 #[test]
5651 fn wrap_row() {
5652 let layout = stretch::compute(&stretch::style::Node {
5653 flex_wrap: stretch::style::FlexWrap::Wrap,
5654 width: stretch::style::Dimension::Points(100.0000),
5655 children: vec![
5656 stretch::style::Node {
5657 width: stretch::style::Dimension::Points(31.0000),
5658 height: stretch::style::Dimension::Points(30.0000),
5659 ..Default::default()
5660 },
5661 stretch::style::Node {
5662 width: stretch::style::Dimension::Points(32.0000),
5663 height: stretch::style::Dimension::Points(30.0000),
5664 ..Default::default()
5665 },
5666 stretch::style::Node {
5667 width: stretch::style::Dimension::Points(33.0000),
5668 height: stretch::style::Dimension::Points(30.0000),
5669 ..Default::default()
5670 },
5671 stretch::style::Node {
5672 width: stretch::style::Dimension::Points(34.0000),
5673 height: stretch::style::Dimension::Points(30.0000),
5674 ..Default::default()
5675 },
5676 ],
5677 ..Default::default()
5678 });
5679
5680 assert_eq!(layout.width, 100.0000);
5681 assert_eq!(layout.height, 60.0000);
5682 assert_eq!(layout.x, 0.0000);
5683 assert_eq!(layout.y, 0.0000);
5684
5685 assert_eq!(layout.children[0].width, 31.0000);
5686 assert_eq!(layout.children[0].height, 30.0000);
5687 assert_eq!(layout.children[0].x, 0.0000);
5688 assert_eq!(layout.children[0].y, 0.0000);
5689
5690 assert_eq!(layout.children[1].width, 32.0000);
5691 assert_eq!(layout.children[1].height, 30.0000);
5692 assert_eq!(layout.children[1].x, 31.0000);
5693 assert_eq!(layout.children[1].y, 0.0000);
5694
5695 assert_eq!(layout.children[2].width, 33.0000);
5696 assert_eq!(layout.children[2].height, 30.0000);
5697 assert_eq!(layout.children[2].x, 63.0000);
5698 assert_eq!(layout.children[2].y, 0.0000);
5699
5700 assert_eq!(layout.children[3].width, 34.0000);
5701 assert_eq!(layout.children[3].height, 30.0000);
5702 assert_eq!(layout.children[3].x, 0.0000);
5703 assert_eq!(layout.children[3].y, 30.0000);
5704 }
5705
5706 #[test]
5707 fn max_height() {
5708 let layout = stretch::compute(&stretch::style::Node {
5709 width: stretch::style::Dimension::Points(100.0000),
5710 height: stretch::style::Dimension::Points(100.0000),
5711 children: vec![stretch::style::Node {
5712 width: stretch::style::Dimension::Points(10.0000),
5713 max_height: stretch::style::Dimension::Points(50.0000),
5714 ..Default::default()
5715 }],
5716 ..Default::default()
5717 });
5718
5719 assert_eq!(layout.width, 100.0000);
5720 assert_eq!(layout.height, 100.0000);
5721 assert_eq!(layout.x, 0.0000);
5722 assert_eq!(layout.y, 0.0000);
5723
5724 assert_eq!(layout.children[0].width, 10.0000);
5725 assert_eq!(layout.children[0].height, 50.0000);
5726 assert_eq!(layout.children[0].x, 0.0000);
5727 assert_eq!(layout.children[0].y, 0.0000);
5728 }
5729
5730 #[test]
5731 fn flex_grow_child() {
5732 let layout = stretch::compute(&stretch::style::Node {
5733 children: vec![stretch::style::Node {
5734 flex_grow: 1.0000,
5735 flex_basis: stretch::style::Dimension::Points(0.0000),
5736 height: stretch::style::Dimension::Points(100.0000),
5737 ..Default::default()
5738 }],
5739 ..Default::default()
5740 });
5741
5742 assert_eq!(layout.width, 0.0000);
5743 assert_eq!(layout.height, 100.0000);
5744 assert_eq!(layout.x, 0.0000);
5745 assert_eq!(layout.y, 0.0000);
5746
5747 assert_eq!(layout.children[0].width, 0.0000);
5748 assert_eq!(layout.children[0].height, 100.0000);
5749 assert_eq!(layout.children[0].x, 0.0000);
5750 assert_eq!(layout.children[0].y, 0.0000);
5751 }
5752
5753 #[test]
5754 fn percentage_size_of_flex_basis() {
5755 let layout = stretch::compute(&stretch::style::Node {
5756 width: stretch::style::Dimension::Points(100.0000),
5757 children: vec![stretch::style::Node {
5758 flex_basis: stretch::style::Dimension::Points(50.0000),
5759 children: vec![stretch::style::Node {
5760 width: stretch::style::Dimension::Percent(1.0000),
5761 height: stretch::style::Dimension::Points(100.0000),
5762 ..Default::default()
5763 }],
5764 ..Default::default()
5765 }],
5766 ..Default::default()
5767 });
5768
5769 assert_eq!(layout.width, 100.0000);
5770 assert_eq!(layout.height, 100.0000);
5771 assert_eq!(layout.x, 0.0000);
5772 assert_eq!(layout.y, 0.0000);
5773
5774 assert_eq!(layout.children[0].width, 50.0000);
5775 assert_eq!(layout.children[0].height, 100.0000);
5776 assert_eq!(layout.children[0].x, 0.0000);
5777 assert_eq!(layout.children[0].y, 0.0000);
5778
5779 assert_eq!(layout.children[0].children[0].width, 50.0000);
5780 assert_eq!(layout.children[0].children[0].height, 100.0000);
5781 assert_eq!(layout.children[0].children[0].x, 0.0000);
5782 assert_eq!(layout.children[0].children[0].y, 0.0000);
5783 }
5784
5785 #[test]
5786 fn align_items_flex_end_child_with_margin_bigger_than_parent() {
5787 let layout = stretch::compute(&stretch::style::Node {
5788 align_items: stretch::style::AlignItems::Center,
5789 justify_content: stretch::style::JustifyContent::Center,
5790 width: stretch::style::Dimension::Points(50.0000),
5791 height: stretch::style::Dimension::Points(50.0000),
5792 children: vec![stretch::style::Node {
5793 align_items: stretch::style::AlignItems::FlexEnd,
5794 children: vec![stretch::style::Node {
5795 width: stretch::style::Dimension::Points(50.0000),
5796 height: stretch::style::Dimension::Points(50.0000),
5797 margin: stretch::style::Edges {
5798 start: stretch::style::Dimension::Points(10.0000),
5799 end: stretch::style::Dimension::Points(10.0000),
5800 ..Default::default()
5801 },
5802 ..Default::default()
5803 }],
5804 ..Default::default()
5805 }],
5806 ..Default::default()
5807 });
5808
5809 assert_eq!(layout.width, 50.0000);
5810 assert_eq!(layout.height, 50.0000);
5811 assert_eq!(layout.x, 0.0000);
5812 assert_eq!(layout.y, 0.0000);
5813
5814 assert_eq!(layout.children[0].width, 70.0000);
5815 assert_eq!(layout.children[0].height, 50.0000);
5816 assert_eq!(layout.children[0].x, -10.0000);
5817 assert_eq!(layout.children[0].y, 0.0000);
5818
5819 assert_eq!(layout.children[0].children[0].width, 50.0000);
5820 assert_eq!(layout.children[0].children[0].height, 50.0000);
5821 assert_eq!(layout.children[0].children[0].x, 10.0000);
5822 assert_eq!(layout.children[0].children[0].y, 0.0000);
5823 }
5824
5825 #[test]
5826 fn justify_content_row_max_width_and_margin() {
5827 let layout = stretch::compute(&stretch::style::Node {
5828 justify_content: stretch::style::JustifyContent::Center,
5829 width: stretch::style::Dimension::Points(100.0000),
5830 max_width: stretch::style::Dimension::Points(80.0000),
5831 children: vec![stretch::style::Node {
5832 width: stretch::style::Dimension::Points(20.0000),
5833 height: stretch::style::Dimension::Points(20.0000),
5834 margin: stretch::style::Edges {
5835 start: stretch::style::Dimension::Points(100.0000),
5836 ..Default::default()
5837 },
5838 ..Default::default()
5839 }],
5840 ..Default::default()
5841 });
5842
5843 assert_eq!(layout.width, 80.0000);
5844 assert_eq!(layout.height, 20.0000);
5845 assert_eq!(layout.x, 0.0000);
5846 assert_eq!(layout.y, 0.0000);
5847
5848 assert_eq!(layout.children[0].width, 0.0000);
5849 assert_eq!(layout.children[0].height, 20.0000);
5850 assert_eq!(layout.children[0].x, 90.0000);
5851 assert_eq!(layout.children[0].y, 0.0000);
5852 }
5853
5854 #[test]
5855 fn margin_left() {
5856 let layout = stretch::compute(&stretch::style::Node {
5857 width: stretch::style::Dimension::Points(100.0000),
5858 height: stretch::style::Dimension::Points(100.0000),
5859 children: vec![stretch::style::Node {
5860 width: stretch::style::Dimension::Points(10.0000),
5861 margin: stretch::style::Edges {
5862 start: stretch::style::Dimension::Points(10.0000),
5863 ..Default::default()
5864 },
5865 ..Default::default()
5866 }],
5867 ..Default::default()
5868 });
5869
5870 assert_eq!(layout.width, 100.0000);
5871 assert_eq!(layout.height, 100.0000);
5872 assert_eq!(layout.x, 0.0000);
5873 assert_eq!(layout.y, 0.0000);
5874
5875 assert_eq!(layout.children[0].width, 10.0000);
5876 assert_eq!(layout.children[0].height, 100.0000);
5877 assert_eq!(layout.children[0].x, 10.0000);
5878 assert_eq!(layout.children[0].y, 0.0000);
5879 }
5880
5881 #[test]
5882 fn size_defined_by_child() {
5883 let layout = stretch::compute(&stretch::style::Node {
5884 children: vec![stretch::style::Node {
5885 width: stretch::style::Dimension::Points(100.0000),
5886 height: stretch::style::Dimension::Points(100.0000),
5887 ..Default::default()
5888 }],
5889 ..Default::default()
5890 });
5891
5892 assert_eq!(layout.width, 100.0000);
5893 assert_eq!(layout.height, 100.0000);
5894 assert_eq!(layout.x, 0.0000);
5895 assert_eq!(layout.y, 0.0000);
5896
5897 assert_eq!(layout.children[0].width, 100.0000);
5898 assert_eq!(layout.children[0].height, 100.0000);
5899 assert_eq!(layout.children[0].x, 0.0000);
5900 assert_eq!(layout.children[0].y, 0.0000);
5901 }
5902
5903 #[test]
5904 fn rounding_total_fractial_nested() {
5905 let layout = stretch::compute(&stretch::style::Node {
5906 flex_direction: stretch::style::FlexDirection::Column,
5907 width: stretch::style::Dimension::Points(87.4000),
5908 height: stretch::style::Dimension::Points(113.4000),
5909 children: vec![
5910 stretch::style::Node {
5911 flex_direction: stretch::style::FlexDirection::Column,
5912 flex_grow: 0.7000,
5913 flex_basis: stretch::style::Dimension::Points(50.3000),
5914 height: stretch::style::Dimension::Points(20.3000),
5915 children: vec![
5916 stretch::style::Node {
5917 flex_grow: 1.0000,
5918 flex_basis: stretch::style::Dimension::Points(0.3000),
5919 height: stretch::style::Dimension::Points(9.9000),
5920 bottom: stretch::style::Dimension::Points(13.3000),
5921 ..Default::default()
5922 },
5923 stretch::style::Node {
5924 flex_grow: 4.0000,
5925 flex_basis: stretch::style::Dimension::Points(0.3000),
5926 height: stretch::style::Dimension::Points(1.1000),
5927 top: stretch::style::Dimension::Points(13.3000),
5928 ..Default::default()
5929 },
5930 ],
5931 ..Default::default()
5932 },
5933 stretch::style::Node {
5934 flex_grow: 1.6000,
5935 height: stretch::style::Dimension::Points(10.0000),
5936 ..Default::default()
5937 },
5938 stretch::style::Node {
5939 flex_grow: 1.1000,
5940 height: stretch::style::Dimension::Points(10.7000),
5941 ..Default::default()
5942 },
5943 ],
5944 ..Default::default()
5945 });
5946
5947 assert_eq!(layout.width, 87.0000);
5948 assert_eq!(layout.height, 113.0000);
5949 assert_eq!(layout.x, 0.0000);
5950 assert_eq!(layout.y, 0.0000);
5951
5952 assert_eq!(layout.children[0].width, 87.0000);
5953 assert_eq!(layout.children[0].height, 59.0000);
5954 assert_eq!(layout.children[0].x, 0.0000);
5955 assert_eq!(layout.children[0].y, 0.0000);
5956
5957 assert_eq!(layout.children[0].children[0].width, 87.0000);
5958 assert_eq!(layout.children[0].children[0].height, 12.0000);
5959 assert_eq!(layout.children[0].children[0].x, 0.0000);
5960 assert_eq!(layout.children[0].children[0].y, -13.0000);
5961
5962 assert_eq!(layout.children[0].children[1].width, 87.0000);
5963 assert_eq!(layout.children[0].children[1].height, 47.0000);
5964 assert_eq!(layout.children[0].children[1].x, 0.0000);
5965 assert_eq!(layout.children[0].children[1].y, 25.0000);
5966
5967 assert_eq!(layout.children[1].width, 87.0000);
5968 assert_eq!(layout.children[1].height, 30.0000);
5969 assert_eq!(layout.children[1].x, 0.0000);
5970 assert_eq!(layout.children[1].y, 59.0000);
5971
5972 assert_eq!(layout.children[2].width, 87.0000);
5973 assert_eq!(layout.children[2].height, 24.0000);
5974 assert_eq!(layout.children[2].x, 0.0000);
5975 assert_eq!(layout.children[2].y, 89.0000);
5976 }
5977
5978 #[test]
5979 fn min_max_percent_no_width_height() {
5980 let layout = stretch::compute(&stretch::style::Node {
5981 flex_direction: stretch::style::FlexDirection::Column,
5982 align_items: stretch::style::AlignItems::FlexStart,
5983 width: stretch::style::Dimension::Points(100.0000),
5984 height: stretch::style::Dimension::Points(100.0000),
5985 children: vec![stretch::style::Node {
5986 min_width: stretch::style::Dimension::Percent(0.1000),
5987 max_width: stretch::style::Dimension::Percent(0.1000),
5988 min_height: stretch::style::Dimension::Percent(0.1000),
5989 max_height: stretch::style::Dimension::Percent(0.1000),
5990 ..Default::default()
5991 }],
5992 ..Default::default()
5993 });
5994
5995 assert_eq!(layout.width, 100.0000);
5996 assert_eq!(layout.height, 100.0000);
5997 assert_eq!(layout.x, 0.0000);
5998 assert_eq!(layout.y, 0.0000);
5999
6000 assert_eq!(layout.children[0].width, 10.0000);
6001 assert_eq!(layout.children[0].height, 10.0000);
6002 assert_eq!(layout.children[0].x, 0.0000);
6003 assert_eq!(layout.children[0].y, 0.0000);
6004 }
6005
6006 #[test]
6007 fn flex_basis_smaller_then_content_with_flex_grow_very_large_size() {
6008 let layout = stretch::compute(&stretch::style::Node {
6009 width: stretch::style::Dimension::Points(200.0000),
6010 children: vec![
6011 stretch::style::Node {
6012 flex_direction: stretch::style::FlexDirection::Column,
6013 flex_grow: 1.0000,
6014 flex_basis: stretch::style::Dimension::Points(0.0000),
6015 children: vec![stretch::style::Node {
6016 width: stretch::style::Dimension::Points(70.0000),
6017 height: stretch::style::Dimension::Points(100.0000),
6018 ..Default::default()
6019 }],
6020 ..Default::default()
6021 },
6022 stretch::style::Node {
6023 flex_direction: stretch::style::FlexDirection::Column,
6024 flex_grow: 1.0000,
6025 flex_basis: stretch::style::Dimension::Points(0.0000),
6026 children: vec![stretch::style::Node {
6027 width: stretch::style::Dimension::Points(20.0000),
6028 height: stretch::style::Dimension::Points(100.0000),
6029 ..Default::default()
6030 }],
6031 ..Default::default()
6032 },
6033 ],
6034 ..Default::default()
6035 });
6036
6037 assert_eq!(layout.width, 200.0000);
6038 assert_eq!(layout.height, 100.0000);
6039 assert_eq!(layout.x, 0.0000);
6040 assert_eq!(layout.y, 0.0000);
6041
6042 assert_eq!(layout.children[0].width, 100.0000);
6043 assert_eq!(layout.children[0].height, 100.0000);
6044 assert_eq!(layout.children[0].x, 0.0000);
6045 assert_eq!(layout.children[0].y, 0.0000);
6046
6047 assert_eq!(layout.children[0].children[0].width, 70.0000);
6048 assert_eq!(layout.children[0].children[0].height, 100.0000);
6049 assert_eq!(layout.children[0].children[0].x, 0.0000);
6050 assert_eq!(layout.children[0].children[0].y, 0.0000);
6051
6052 assert_eq!(layout.children[1].width, 100.0000);
6053 assert_eq!(layout.children[1].height, 100.0000);
6054 assert_eq!(layout.children[1].x, 100.0000);
6055 assert_eq!(layout.children[1].y, 0.0000);
6056
6057 assert_eq!(layout.children[1].children[0].width, 20.0000);
6058 assert_eq!(layout.children[1].children[0].height, 100.0000);
6059 assert_eq!(layout.children[1].children[0].x, 0.0000);
6060 assert_eq!(layout.children[1].children[0].y, 0.0000);
6061 }
6062
6063 #[test]
6064 fn percent_within_flex_grow() {
6065 let layout = stretch::compute(&stretch::style::Node {
6066 width: stretch::style::Dimension::Points(350.0000),
6067 height: stretch::style::Dimension::Points(100.0000),
6068 children: vec![
6069 stretch::style::Node { width: stretch::style::Dimension::Points(100.0000), ..Default::default() },
6070 stretch::style::Node {
6071 flex_direction: stretch::style::FlexDirection::Column,
6072 flex_grow: 1.0000,
6073 children: vec![stretch::style::Node {
6074 width: stretch::style::Dimension::Percent(1.0000),
6075 ..Default::default()
6076 }],
6077 ..Default::default()
6078 },
6079 stretch::style::Node { width: stretch::style::Dimension::Points(100.0000), ..Default::default() },
6080 ],
6081 ..Default::default()
6082 });
6083
6084 assert_eq!(layout.width, 350.0000);
6085 assert_eq!(layout.height, 100.0000);
6086 assert_eq!(layout.x, 0.0000);
6087 assert_eq!(layout.y, 0.0000);
6088
6089 assert_eq!(layout.children[0].width, 100.0000);
6090 assert_eq!(layout.children[0].height, 100.0000);
6091 assert_eq!(layout.children[0].x, 0.0000);
6092 assert_eq!(layout.children[0].y, 0.0000);
6093
6094 assert_eq!(layout.children[1].width, 150.0000);
6095 assert_eq!(layout.children[1].height, 100.0000);
6096 assert_eq!(layout.children[1].x, 100.0000);
6097 assert_eq!(layout.children[1].y, 0.0000);
6098
6099 assert_eq!(layout.children[1].children[0].width, 150.0000);
6100 assert_eq!(layout.children[1].children[0].height, 0.0000);
6101 assert_eq!(layout.children[1].children[0].x, 0.0000);
6102 assert_eq!(layout.children[1].children[0].y, 0.0000);
6103
6104 assert_eq!(layout.children[2].width, 100.0000);
6105 assert_eq!(layout.children[2].height, 100.0000);
6106 assert_eq!(layout.children[2].x, 250.0000);
6107 assert_eq!(layout.children[2].y, 0.0000);
6108 }
6109
6110 #[test]
6111 fn margin_and_stretch_row() {
6112 let layout = stretch::compute(&stretch::style::Node {
6113 width: stretch::style::Dimension::Points(100.0000),
6114 height: stretch::style::Dimension::Points(100.0000),
6115 children: vec![stretch::style::Node {
6116 flex_grow: 1.0000,
6117 margin: stretch::style::Edges {
6118 top: stretch::style::Dimension::Points(10.0000),
6119 bottom: stretch::style::Dimension::Points(10.0000),
6120 ..Default::default()
6121 },
6122 ..Default::default()
6123 }],
6124 ..Default::default()
6125 });
6126
6127 assert_eq!(layout.width, 100.0000);
6128 assert_eq!(layout.height, 100.0000);
6129 assert_eq!(layout.x, 0.0000);
6130 assert_eq!(layout.y, 0.0000);
6131
6132 assert_eq!(layout.children[0].width, 100.0000);
6133 assert_eq!(layout.children[0].height, 80.0000);
6134 assert_eq!(layout.children[0].x, 0.0000);
6135 assert_eq!(layout.children[0].y, 10.0000);
6136 }
6137
6138 #[test]
6139 fn margin_top() {
6140 let layout = stretch::compute(&stretch::style::Node {
6141 flex_direction: stretch::style::FlexDirection::Column,
6142 width: stretch::style::Dimension::Points(100.0000),
6143 height: stretch::style::Dimension::Points(100.0000),
6144 children: vec![stretch::style::Node {
6145 height: stretch::style::Dimension::Points(10.0000),
6146 margin: stretch::style::Edges { top: stretch::style::Dimension::Points(10.0000), ..Default::default() },
6147 ..Default::default()
6148 }],
6149 ..Default::default()
6150 });
6151
6152 assert_eq!(layout.width, 100.0000);
6153 assert_eq!(layout.height, 100.0000);
6154 assert_eq!(layout.x, 0.0000);
6155 assert_eq!(layout.y, 0.0000);
6156
6157 assert_eq!(layout.children[0].width, 100.0000);
6158 assert_eq!(layout.children[0].height, 10.0000);
6159 assert_eq!(layout.children[0].x, 0.0000);
6160 assert_eq!(layout.children[0].y, 10.0000);
6161 }
6162
6163 #[test]
6164 fn percentage_flex_basis_main_max_height() {
6165 let layout = stretch::compute(&stretch::style::Node {
6166 width: stretch::style::Dimension::Points(200.0000),
6167 height: stretch::style::Dimension::Points(200.0000),
6168 children: vec![
6169 stretch::style::Node {
6170 flex_grow: 1.0000,
6171 flex_basis: stretch::style::Dimension::Percent(0.1000),
6172 max_height: stretch::style::Dimension::Percent(0.6000),
6173 ..Default::default()
6174 },
6175 stretch::style::Node {
6176 flex_grow: 4.0000,
6177 flex_basis: stretch::style::Dimension::Percent(0.1000),
6178 max_height: stretch::style::Dimension::Percent(0.2000),
6179 ..Default::default()
6180 },
6181 ],
6182 ..Default::default()
6183 });
6184
6185 assert_eq!(layout.width, 200.0000);
6186 assert_eq!(layout.height, 200.0000);
6187 assert_eq!(layout.x, 0.0000);
6188 assert_eq!(layout.y, 0.0000);
6189
6190 assert_eq!(layout.children[0].width, 52.0000);
6191 assert_eq!(layout.children[0].height, 120.0000);
6192 assert_eq!(layout.children[0].x, 0.0000);
6193 assert_eq!(layout.children[0].y, 0.0000);
6194
6195 assert_eq!(layout.children[1].width, 148.0000);
6196 assert_eq!(layout.children[1].height, 40.0000);
6197 assert_eq!(layout.children[1].x, 52.0000);
6198 assert_eq!(layout.children[1].y, 0.0000);
6199 }
6200
6201 #[test]
6202 fn margin_auto_left_and_right_column() {
6203 let layout = stretch::compute(&stretch::style::Node {
6204 align_items: stretch::style::AlignItems::Center,
6205 width: stretch::style::Dimension::Points(200.0000),
6206 height: stretch::style::Dimension::Points(200.0000),
6207 children: vec![
6208 stretch::style::Node {
6209 width: stretch::style::Dimension::Points(50.0000),
6210 height: stretch::style::Dimension::Points(50.0000),
6211 margin: stretch::style::Edges {
6212 start: stretch::style::Dimension::Auto,
6213 end: stretch::style::Dimension::Auto,
6214 ..Default::default()
6215 },
6216 ..Default::default()
6217 },
6218 stretch::style::Node {
6219 width: stretch::style::Dimension::Points(50.0000),
6220 height: stretch::style::Dimension::Points(50.0000),
6221 ..Default::default()
6222 },
6223 ],
6224 ..Default::default()
6225 });
6226
6227 assert_eq!(layout.width, 200.0000);
6228 assert_eq!(layout.height, 200.0000);
6229 assert_eq!(layout.x, 0.0000);
6230 assert_eq!(layout.y, 0.0000);
6231
6232 assert_eq!(layout.children[0].width, 50.0000);
6233 assert_eq!(layout.children[0].height, 50.0000);
6234 assert_eq!(layout.children[0].x, 50.0000);
6235 assert_eq!(layout.children[0].y, 75.0000);
6236
6237 assert_eq!(layout.children[1].width, 50.0000);
6238 assert_eq!(layout.children[1].height, 50.0000);
6239 assert_eq!(layout.children[1].x, 150.0000);
6240 assert_eq!(layout.children[1].y, 75.0000);
6241 }
6242
6243 #[test]
6244 fn margin_and_flex_row() {
6245 let layout = stretch::compute(&stretch::style::Node {
6246 width: stretch::style::Dimension::Points(100.0000),
6247 height: stretch::style::Dimension::Points(100.0000),
6248 children: vec![stretch::style::Node {
6249 flex_grow: 1.0000,
6250 margin: stretch::style::Edges {
6251 start: stretch::style::Dimension::Points(10.0000),
6252 end: stretch::style::Dimension::Points(10.0000),
6253 ..Default::default()
6254 },
6255 ..Default::default()
6256 }],
6257 ..Default::default()
6258 });
6259
6260 assert_eq!(layout.width, 100.0000);
6261 assert_eq!(layout.height, 100.0000);
6262 assert_eq!(layout.x, 0.0000);
6263 assert_eq!(layout.y, 0.0000);
6264
6265 assert_eq!(layout.children[0].width, 80.0000);
6266 assert_eq!(layout.children[0].height, 100.0000);
6267 assert_eq!(layout.children[0].x, 10.0000);
6268 assert_eq!(layout.children[0].y, 0.0000);
6269 }
6270
6271 #[test]
6272 fn flex_wrap_children_with_min_main_overriding_flex_basis() {
6273 let layout = stretch::compute(&stretch::style::Node {
6274 flex_wrap: stretch::style::FlexWrap::Wrap,
6275 width: stretch::style::Dimension::Points(100.0000),
6276 children: vec![
6277 stretch::style::Node {
6278 flex_basis: stretch::style::Dimension::Points(50.0000),
6279 min_width: stretch::style::Dimension::Points(55.0000),
6280 height: stretch::style::Dimension::Points(50.0000),
6281 ..Default::default()
6282 },
6283 stretch::style::Node {
6284 flex_basis: stretch::style::Dimension::Points(50.0000),
6285 min_width: stretch::style::Dimension::Points(55.0000),
6286 height: stretch::style::Dimension::Points(50.0000),
6287 ..Default::default()
6288 },
6289 ],
6290 ..Default::default()
6291 });
6292
6293 assert_eq!(layout.width, 100.0000);
6294 assert_eq!(layout.height, 100.0000);
6295 assert_eq!(layout.x, 0.0000);
6296 assert_eq!(layout.y, 0.0000);
6297
6298 assert_eq!(layout.children[0].width, 55.0000);
6299 assert_eq!(layout.children[0].height, 50.0000);
6300 assert_eq!(layout.children[0].x, 0.0000);
6301 assert_eq!(layout.children[0].y, 0.0000);
6302
6303 assert_eq!(layout.children[1].width, 55.0000);
6304 assert_eq!(layout.children[1].height, 50.0000);
6305 assert_eq!(layout.children[1].x, 0.0000);
6306 assert_eq!(layout.children[1].y, 50.0000);
6307 }
6308
6309 #[test]
6310 fn wrap_row_align_items_center() {
6311 let layout = stretch::compute(&stretch::style::Node {
6312 flex_wrap: stretch::style::FlexWrap::Wrap,
6313 align_items: stretch::style::AlignItems::Center,
6314 width: stretch::style::Dimension::Points(100.0000),
6315 children: vec![
6316 stretch::style::Node {
6317 width: stretch::style::Dimension::Points(30.0000),
6318 height: stretch::style::Dimension::Points(10.0000),
6319 ..Default::default()
6320 },
6321 stretch::style::Node {
6322 width: stretch::style::Dimension::Points(30.0000),
6323 height: stretch::style::Dimension::Points(20.0000),
6324 ..Default::default()
6325 },
6326 stretch::style::Node {
6327 width: stretch::style::Dimension::Points(30.0000),
6328 height: stretch::style::Dimension::Points(30.0000),
6329 ..Default::default()
6330 },
6331 stretch::style::Node {
6332 width: stretch::style::Dimension::Points(30.0000),
6333 height: stretch::style::Dimension::Points(30.0000),
6334 ..Default::default()
6335 },
6336 ],
6337 ..Default::default()
6338 });
6339
6340 assert_eq!(layout.width, 100.0000);
6341 assert_eq!(layout.height, 60.0000);
6342 assert_eq!(layout.x, 0.0000);
6343 assert_eq!(layout.y, 0.0000);
6344
6345 assert_eq!(layout.children[0].width, 30.0000);
6346 assert_eq!(layout.children[0].height, 10.0000);
6347 assert_eq!(layout.children[0].x, 0.0000);
6348 assert_eq!(layout.children[0].y, 10.0000);
6349
6350 assert_eq!(layout.children[1].width, 30.0000);
6351 assert_eq!(layout.children[1].height, 20.0000);
6352 assert_eq!(layout.children[1].x, 30.0000);
6353 assert_eq!(layout.children[1].y, 5.0000);
6354
6355 assert_eq!(layout.children[2].width, 30.0000);
6356 assert_eq!(layout.children[2].height, 30.0000);
6357 assert_eq!(layout.children[2].x, 60.0000);
6358 assert_eq!(layout.children[2].y, 0.0000);
6359
6360 assert_eq!(layout.children[3].width, 30.0000);
6361 assert_eq!(layout.children[3].height, 30.0000);
6362 assert_eq!(layout.children[3].x, 0.0000);
6363 assert_eq!(layout.children[3].y, 30.0000);
6364 }
6365
6366 #[test]
6367 fn flex_basis_flex_grow_column() {
6368 let layout = stretch::compute(&stretch::style::Node {
6369 flex_direction: stretch::style::FlexDirection::Column,
6370 width: stretch::style::Dimension::Points(100.0000),
6371 height: stretch::style::Dimension::Points(100.0000),
6372 children: vec![
6373 stretch::style::Node {
6374 flex_grow: 1.0000,
6375 flex_basis: stretch::style::Dimension::Points(50.0000),
6376 ..Default::default()
6377 },
6378 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
6379 ],
6380 ..Default::default()
6381 });
6382
6383 assert_eq!(layout.width, 100.0000);
6384 assert_eq!(layout.height, 100.0000);
6385 assert_eq!(layout.x, 0.0000);
6386 assert_eq!(layout.y, 0.0000);
6387
6388 assert_eq!(layout.children[0].width, 100.0000);
6389 assert_eq!(layout.children[0].height, 75.0000);
6390 assert_eq!(layout.children[0].x, 0.0000);
6391 assert_eq!(layout.children[0].y, 0.0000);
6392
6393 assert_eq!(layout.children[1].width, 100.0000);
6394 assert_eq!(layout.children[1].height, 25.0000);
6395 assert_eq!(layout.children[1].x, 0.0000);
6396 assert_eq!(layout.children[1].y, 75.0000);
6397 }
6398
6399 #[test]
6400 fn absolute_layout_align_items_and_justify_content_center_and_right_position() {
6401 let layout = stretch::compute(&stretch::style::Node {
6402 align_items: stretch::style::AlignItems::Center,
6403 justify_content: stretch::style::JustifyContent::Center,
6404 width: stretch::style::Dimension::Points(110.0000),
6405 height: stretch::style::Dimension::Points(100.0000),
6406 children: vec![stretch::style::Node {
6407 position: stretch::style::Position::Absolute,
6408 width: stretch::style::Dimension::Points(60.0000),
6409 height: stretch::style::Dimension::Points(40.0000),
6410 end: stretch::style::Dimension::Points(5.0000),
6411 ..Default::default()
6412 }],
6413 ..Default::default()
6414 });
6415
6416 assert_eq!(layout.width, 110.0000);
6417 assert_eq!(layout.height, 100.0000);
6418 assert_eq!(layout.x, 0.0000);
6419 assert_eq!(layout.y, 0.0000);
6420
6421 assert_eq!(layout.children[0].width, 60.0000);
6422 assert_eq!(layout.children[0].height, 40.0000);
6423 assert_eq!(layout.children[0].x, 45.0000);
6424 assert_eq!(layout.children[0].y, 30.0000);
6425 }
6426
6427 #[test]
6428 fn overflow_cross_axis() {
6429 let layout = stretch::compute(&stretch::style::Node {
6430 width: stretch::style::Dimension::Points(100.0000),
6431 height: stretch::style::Dimension::Points(100.0000),
6432 children: vec![stretch::style::Node {
6433 width: stretch::style::Dimension::Points(100.0000),
6434 height: stretch::style::Dimension::Points(200.0000),
6435 ..Default::default()
6436 }],
6437 ..Default::default()
6438 });
6439
6440 assert_eq!(layout.width, 100.0000);
6441 assert_eq!(layout.height, 100.0000);
6442 assert_eq!(layout.x, 0.0000);
6443 assert_eq!(layout.y, 0.0000);
6444
6445 assert_eq!(layout.children[0].width, 100.0000);
6446 assert_eq!(layout.children[0].height, 200.0000);
6447 assert_eq!(layout.children[0].x, 0.0000);
6448 assert_eq!(layout.children[0].y, 0.0000);
6449 }
6450
6451 #[test]
6452 fn wrap_column() {
6453 let layout = stretch::compute(&stretch::style::Node {
6454 flex_direction: stretch::style::FlexDirection::Column,
6455 flex_wrap: stretch::style::FlexWrap::Wrap,
6456 width: stretch::style::Dimension::Points(100.0000),
6457 height: stretch::style::Dimension::Points(100.0000),
6458 children: vec![
6459 stretch::style::Node {
6460 width: stretch::style::Dimension::Points(30.0000),
6461 height: stretch::style::Dimension::Points(31.0000),
6462 ..Default::default()
6463 },
6464 stretch::style::Node {
6465 width: stretch::style::Dimension::Points(30.0000),
6466 height: stretch::style::Dimension::Points(32.0000),
6467 ..Default::default()
6468 },
6469 stretch::style::Node {
6470 width: stretch::style::Dimension::Points(30.0000),
6471 height: stretch::style::Dimension::Points(33.0000),
6472 ..Default::default()
6473 },
6474 stretch::style::Node {
6475 width: stretch::style::Dimension::Points(30.0000),
6476 height: stretch::style::Dimension::Points(34.0000),
6477 ..Default::default()
6478 },
6479 ],
6480 ..Default::default()
6481 });
6482
6483 assert_eq!(layout.width, 100.0000);
6484 assert_eq!(layout.height, 100.0000);
6485 assert_eq!(layout.x, 0.0000);
6486 assert_eq!(layout.y, 0.0000);
6487
6488 assert_eq!(layout.children[0].width, 30.0000);
6489 assert_eq!(layout.children[0].height, 31.0000);
6490 assert_eq!(layout.children[0].x, 0.0000);
6491 assert_eq!(layout.children[0].y, 0.0000);
6492
6493 assert_eq!(layout.children[1].width, 30.0000);
6494 assert_eq!(layout.children[1].height, 32.0000);
6495 assert_eq!(layout.children[1].x, 0.0000);
6496 assert_eq!(layout.children[1].y, 31.0000);
6497
6498 assert_eq!(layout.children[2].width, 30.0000);
6499 assert_eq!(layout.children[2].height, 33.0000);
6500 assert_eq!(layout.children[2].x, 0.0000);
6501 assert_eq!(layout.children[2].y, 63.0000);
6502
6503 assert_eq!(layout.children[3].width, 30.0000);
6504 assert_eq!(layout.children[3].height, 34.0000);
6505 assert_eq!(layout.children[3].x, 50.0000);
6506 assert_eq!(layout.children[3].y, 0.0000);
6507 }
6508
6509 #[test]
6510 fn justify_content_column_space_evenly() {
6511 let layout = stretch::compute(&stretch::style::Node {
6512 flex_direction: stretch::style::FlexDirection::Column,
6513 justify_content: stretch::style::JustifyContent::SpaceEvenly,
6514 width: stretch::style::Dimension::Points(100.0000),
6515 height: stretch::style::Dimension::Points(100.0000),
6516 children: vec![
6517 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
6518 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
6519 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
6520 ],
6521 ..Default::default()
6522 });
6523
6524 assert_eq!(layout.width, 100.0000);
6525 assert_eq!(layout.height, 100.0000);
6526 assert_eq!(layout.x, 0.0000);
6527 assert_eq!(layout.y, 0.0000);
6528
6529 assert_eq!(layout.children[0].width, 100.0000);
6530 assert_eq!(layout.children[0].height, 10.0000);
6531 assert_eq!(layout.children[0].x, 0.0000);
6532 assert_eq!(layout.children[0].y, 18.0000);
6533
6534 assert_eq!(layout.children[1].width, 100.0000);
6535 assert_eq!(layout.children[1].height, 10.0000);
6536 assert_eq!(layout.children[1].x, 0.0000);
6537 assert_eq!(layout.children[1].y, 45.0000);
6538
6539 assert_eq!(layout.children[2].width, 100.0000);
6540 assert_eq!(layout.children[2].height, 10.0000);
6541 assert_eq!(layout.children[2].x, 0.0000);
6542 assert_eq!(layout.children[2].y, 73.0000);
6543 }
6544
6545 #[test]
6546 fn flex_grow_within_constrained_max_column() {
6547 let layout = stretch::compute(&stretch::style::Node {
6548 flex_direction: stretch::style::FlexDirection::Column,
6549 width: stretch::style::Dimension::Points(100.0000),
6550 max_height: stretch::style::Dimension::Points(100.0000),
6551 children: vec![
6552 stretch::style::Node {
6553 flex_shrink: 1.0000,
6554 flex_basis: stretch::style::Dimension::Points(100.0000),
6555 ..Default::default()
6556 },
6557 stretch::style::Node { height: stretch::style::Dimension::Points(50.0000), ..Default::default() },
6558 ],
6559 ..Default::default()
6560 });
6561
6562 assert_eq!(layout.width, 100.0000);
6563 assert_eq!(layout.height, 100.0000);
6564 assert_eq!(layout.x, 0.0000);
6565 assert_eq!(layout.y, 0.0000);
6566
6567 assert_eq!(layout.children[0].width, 100.0000);
6568 assert_eq!(layout.children[0].height, 67.0000);
6569 assert_eq!(layout.children[0].x, 0.0000);
6570 assert_eq!(layout.children[0].y, 0.0000);
6571
6572 assert_eq!(layout.children[1].width, 100.0000);
6573 assert_eq!(layout.children[1].height, 33.0000);
6574 assert_eq!(layout.children[1].x, 0.0000);
6575 assert_eq!(layout.children[1].y, 67.0000);
6576 }
6577
6578 #[test]
6579 fn justify_content_column_space_around() {
6580 let layout = stretch::compute(&stretch::style::Node {
6581 flex_direction: stretch::style::FlexDirection::Column,
6582 justify_content: stretch::style::JustifyContent::SpaceAround,
6583 width: stretch::style::Dimension::Points(100.0000),
6584 height: stretch::style::Dimension::Points(100.0000),
6585 children: vec![
6586 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
6587 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
6588 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
6589 ],
6590 ..Default::default()
6591 });
6592
6593 assert_eq!(layout.width, 100.0000);
6594 assert_eq!(layout.height, 100.0000);
6595 assert_eq!(layout.x, 0.0000);
6596 assert_eq!(layout.y, 0.0000);
6597
6598 assert_eq!(layout.children[0].width, 100.0000);
6599 assert_eq!(layout.children[0].height, 10.0000);
6600 assert_eq!(layout.children[0].x, 0.0000);
6601 assert_eq!(layout.children[0].y, 12.0000);
6602
6603 assert_eq!(layout.children[1].width, 100.0000);
6604 assert_eq!(layout.children[1].height, 10.0000);
6605 assert_eq!(layout.children[1].x, 0.0000);
6606 assert_eq!(layout.children[1].y, 45.0000);
6607
6608 assert_eq!(layout.children[2].width, 100.0000);
6609 assert_eq!(layout.children[2].height, 10.0000);
6610 assert_eq!(layout.children[2].x, 0.0000);
6611 assert_eq!(layout.children[2].y, 78.0000);
6612 }
6613
6614 #[test]
6615 fn flex_basis_larger_than_content_row() {
6616 let layout = stretch::compute(&stretch::style::Node {
6617 width: stretch::style::Dimension::Points(100.0000),
6618 children: vec![stretch::style::Node {
6619 flex_direction: stretch::style::FlexDirection::Column,
6620 flex_basis: stretch::style::Dimension::Points(50.0000),
6621 children: vec![stretch::style::Node {
6622 width: stretch::style::Dimension::Points(10.0000),
6623 height: stretch::style::Dimension::Points(100.0000),
6624 ..Default::default()
6625 }],
6626 ..Default::default()
6627 }],
6628 ..Default::default()
6629 });
6630
6631 assert_eq!(layout.width, 100.0000);
6632 assert_eq!(layout.height, 100.0000);
6633 assert_eq!(layout.x, 0.0000);
6634 assert_eq!(layout.y, 0.0000);
6635
6636 assert_eq!(layout.children[0].width, 50.0000);
6637 assert_eq!(layout.children[0].height, 100.0000);
6638 assert_eq!(layout.children[0].x, 0.0000);
6639 assert_eq!(layout.children[0].y, 0.0000);
6640
6641 assert_eq!(layout.children[0].children[0].width, 10.0000);
6642 assert_eq!(layout.children[0].children[0].height, 100.0000);
6643 assert_eq!(layout.children[0].children[0].x, 0.0000);
6644 assert_eq!(layout.children[0].children[0].y, 0.0000);
6645 }
6646
6647 #[test]
6648 fn absolute_layout_align_items_and_justify_content_center_and_left_position() {
6649 let layout = stretch::compute(&stretch::style::Node {
6650 align_items: stretch::style::AlignItems::Center,
6651 justify_content: stretch::style::JustifyContent::Center,
6652 width: stretch::style::Dimension::Points(110.0000),
6653 height: stretch::style::Dimension::Points(100.0000),
6654 children: vec![stretch::style::Node {
6655 position: stretch::style::Position::Absolute,
6656 width: stretch::style::Dimension::Points(60.0000),
6657 height: stretch::style::Dimension::Points(40.0000),
6658 start: stretch::style::Dimension::Points(5.0000),
6659 ..Default::default()
6660 }],
6661 ..Default::default()
6662 });
6663
6664 assert_eq!(layout.width, 110.0000);
6665 assert_eq!(layout.height, 100.0000);
6666 assert_eq!(layout.x, 0.0000);
6667 assert_eq!(layout.y, 0.0000);
6668
6669 assert_eq!(layout.children[0].width, 60.0000);
6670 assert_eq!(layout.children[0].height, 40.0000);
6671 assert_eq!(layout.children[0].x, 5.0000);
6672 assert_eq!(layout.children[0].y, 30.0000);
6673 }
6674
6675 #[test]
6676 fn percentage_flex_basis_main_min_width() {
6677 let layout = stretch::compute(&stretch::style::Node {
6678 width: stretch::style::Dimension::Points(200.0000),
6679 height: stretch::style::Dimension::Points(200.0000),
6680 children: vec![
6681 stretch::style::Node {
6682 flex_grow: 1.0000,
6683 flex_basis: stretch::style::Dimension::Percent(0.1500),
6684 min_width: stretch::style::Dimension::Percent(0.6000),
6685 ..Default::default()
6686 },
6687 stretch::style::Node {
6688 flex_grow: 4.0000,
6689 flex_basis: stretch::style::Dimension::Percent(0.1000),
6690 min_width: stretch::style::Dimension::Percent(0.2000),
6691 ..Default::default()
6692 },
6693 ],
6694 ..Default::default()
6695 });
6696
6697 assert_eq!(layout.width, 200.0000);
6698 assert_eq!(layout.height, 200.0000);
6699 assert_eq!(layout.x, 0.0000);
6700 assert_eq!(layout.y, 0.0000);
6701
6702 assert_eq!(layout.children[0].width, 120.0000);
6703 assert_eq!(layout.children[0].height, 200.0000);
6704 assert_eq!(layout.children[0].x, 0.0000);
6705 assert_eq!(layout.children[0].y, 0.0000);
6706
6707 assert_eq!(layout.children[1].width, 80.0000);
6708 assert_eq!(layout.children[1].height, 200.0000);
6709 assert_eq!(layout.children[1].x, 120.0000);
6710 assert_eq!(layout.children[1].y, 0.0000);
6711 }
6712
6713 #[test]
6714 fn margin_auto_bottom() {
6715 let layout = stretch::compute(&stretch::style::Node {
6716 align_items: stretch::style::AlignItems::Center,
6717 width: stretch::style::Dimension::Points(200.0000),
6718 height: stretch::style::Dimension::Points(200.0000),
6719 children: vec![
6720 stretch::style::Node {
6721 width: stretch::style::Dimension::Points(50.0000),
6722 height: stretch::style::Dimension::Points(50.0000),
6723 margin: stretch::style::Edges { bottom: stretch::style::Dimension::Auto, ..Default::default() },
6724 ..Default::default()
6725 },
6726 stretch::style::Node {
6727 width: stretch::style::Dimension::Points(50.0000),
6728 height: stretch::style::Dimension::Points(50.0000),
6729 ..Default::default()
6730 },
6731 ],
6732 ..Default::default()
6733 });
6734
6735 assert_eq!(layout.width, 200.0000);
6736 assert_eq!(layout.height, 200.0000);
6737 assert_eq!(layout.x, 0.0000);
6738 assert_eq!(layout.y, 0.0000);
6739
6740 assert_eq!(layout.children[0].width, 50.0000);
6741 assert_eq!(layout.children[0].height, 50.0000);
6742 assert_eq!(layout.children[0].x, 0.0000);
6743 assert_eq!(layout.children[0].y, 0.0000);
6744
6745 assert_eq!(layout.children[1].width, 50.0000);
6746 assert_eq!(layout.children[1].height, 50.0000);
6747 assert_eq!(layout.children[1].x, 50.0000);
6748 assert_eq!(layout.children[1].y, 75.0000);
6749 }
6750
6751 #[test]
6752 fn flex_grow_shrink_at_most() {
6753 let layout = stretch::compute(&stretch::style::Node {
6754 width: stretch::style::Dimension::Points(100.0000),
6755 height: stretch::style::Dimension::Points(100.0000),
6756 children: vec![stretch::style::Node {
6757 children: vec![stretch::style::Node { flex_grow: 1.0000, flex_shrink: 1.0000, ..Default::default() }],
6758 ..Default::default()
6759 }],
6760 ..Default::default()
6761 });
6762
6763 assert_eq!(layout.width, 100.0000);
6764 assert_eq!(layout.height, 100.0000);
6765 assert_eq!(layout.x, 0.0000);
6766 assert_eq!(layout.y, 0.0000);
6767
6768 assert_eq!(layout.children[0].width, 0.0000);
6769 assert_eq!(layout.children[0].height, 100.0000);
6770 assert_eq!(layout.children[0].x, 0.0000);
6771 assert_eq!(layout.children[0].y, 0.0000);
6772
6773 assert_eq!(layout.children[0].children[0].width, 0.0000);
6774 assert_eq!(layout.children[0].children[0].height, 100.0000);
6775 assert_eq!(layout.children[0].children[0].x, 0.0000);
6776 assert_eq!(layout.children[0].children[0].y, 0.0000);
6777 }
6778
6779 #[test]
6780 fn percentage_padding_should_calculate_based_only_on_width() {
6781 let layout = stretch::compute(&stretch::style::Node {
6782 flex_direction: stretch::style::FlexDirection::Column,
6783 width: stretch::style::Dimension::Points(200.0000),
6784 height: stretch::style::Dimension::Points(100.0000),
6785 children: vec![stretch::style::Node {
6786 flex_direction: stretch::style::FlexDirection::Column,
6787 flex_grow: 1.0000,
6788 padding: stretch::style::Edges {
6789 start: stretch::style::Dimension::Percent(0.1000),
6790 end: stretch::style::Dimension::Percent(0.1000),
6791 top: stretch::style::Dimension::Percent(0.1000),
6792 bottom: stretch::style::Dimension::Percent(0.1000),
6793 ..Default::default()
6794 },
6795 children: vec![stretch::style::Node {
6796 width: stretch::style::Dimension::Points(10.0000),
6797 height: stretch::style::Dimension::Points(10.0000),
6798 ..Default::default()
6799 }],
6800 ..Default::default()
6801 }],
6802 ..Default::default()
6803 });
6804
6805 assert_eq!(layout.width, 200.0000);
6806 assert_eq!(layout.height, 100.0000);
6807 assert_eq!(layout.x, 0.0000);
6808 assert_eq!(layout.y, 0.0000);
6809
6810 assert_eq!(layout.children[0].width, 200.0000);
6811 assert_eq!(layout.children[0].height, 100.0000);
6812 assert_eq!(layout.children[0].x, 0.0000);
6813 assert_eq!(layout.children[0].y, 0.0000);
6814
6815 assert_eq!(layout.children[0].children[0].width, 10.0000);
6816 assert_eq!(layout.children[0].children[0].height, 10.0000);
6817 assert_eq!(layout.children[0].children[0].x, 20.0000);
6818 assert_eq!(layout.children[0].children[0].y, 20.0000);
6819 }
6820
6821 #[test]
6822 fn flex_shrink_to_zero() {
6823 let layout = stretch::compute(&stretch::style::Node {
6824 width: stretch::style::Dimension::Points(75.0000),
6825 children: vec![
6826 stretch::style::Node {
6827 flex_shrink: 0.0000,
6828 width: stretch::style::Dimension::Points(50.0000),
6829 height: stretch::style::Dimension::Points(50.0000),
6830 ..Default::default()
6831 },
6832 stretch::style::Node {
6833 flex_shrink: 1.0000,
6834 width: stretch::style::Dimension::Points(50.0000),
6835 height: stretch::style::Dimension::Points(50.0000),
6836 ..Default::default()
6837 },
6838 stretch::style::Node {
6839 flex_shrink: 0.0000,
6840 width: stretch::style::Dimension::Points(50.0000),
6841 height: stretch::style::Dimension::Points(50.0000),
6842 ..Default::default()
6843 },
6844 ],
6845 ..Default::default()
6846 });
6847
6848 assert_eq!(layout.width, 75.0000);
6849 assert_eq!(layout.height, 50.0000);
6850 assert_eq!(layout.x, 0.0000);
6851 assert_eq!(layout.y, 0.0000);
6852
6853 assert_eq!(layout.children[0].width, 50.0000);
6854 assert_eq!(layout.children[0].height, 50.0000);
6855 assert_eq!(layout.children[0].x, 0.0000);
6856 assert_eq!(layout.children[0].y, 0.0000);
6857
6858 assert_eq!(layout.children[1].width, 0.0000);
6859 assert_eq!(layout.children[1].height, 50.0000);
6860 assert_eq!(layout.children[1].x, 50.0000);
6861 assert_eq!(layout.children[1].y, 0.0000);
6862
6863 assert_eq!(layout.children[2].width, 50.0000);
6864 assert_eq!(layout.children[2].height, 50.0000);
6865 assert_eq!(layout.children[2].x, 50.0000);
6866 assert_eq!(layout.children[2].y, 0.0000);
6867 }
6868
6869 #[test]
6870 fn margin_auto_mutiple_children_row() {
6871 let layout = stretch::compute(&stretch::style::Node {
6872 align_items: stretch::style::AlignItems::Center,
6873 width: stretch::style::Dimension::Points(200.0000),
6874 height: stretch::style::Dimension::Points(200.0000),
6875 children: vec![
6876 stretch::style::Node {
6877 width: stretch::style::Dimension::Points(50.0000),
6878 height: stretch::style::Dimension::Points(50.0000),
6879 margin: stretch::style::Edges { end: stretch::style::Dimension::Auto, ..Default::default() },
6880 ..Default::default()
6881 },
6882 stretch::style::Node {
6883 width: stretch::style::Dimension::Points(50.0000),
6884 height: stretch::style::Dimension::Points(50.0000),
6885 margin: stretch::style::Edges { end: stretch::style::Dimension::Auto, ..Default::default() },
6886 ..Default::default()
6887 },
6888 stretch::style::Node {
6889 width: stretch::style::Dimension::Points(50.0000),
6890 height: stretch::style::Dimension::Points(50.0000),
6891 ..Default::default()
6892 },
6893 ],
6894 ..Default::default()
6895 });
6896
6897 assert_eq!(layout.width, 200.0000);
6898 assert_eq!(layout.height, 200.0000);
6899 assert_eq!(layout.x, 0.0000);
6900 assert_eq!(layout.y, 0.0000);
6901
6902 assert_eq!(layout.children[0].width, 50.0000);
6903 assert_eq!(layout.children[0].height, 50.0000);
6904 assert_eq!(layout.children[0].x, 0.0000);
6905 assert_eq!(layout.children[0].y, 75.0000);
6906
6907 assert_eq!(layout.children[1].width, 50.0000);
6908 assert_eq!(layout.children[1].height, 50.0000);
6909 assert_eq!(layout.children[1].x, 75.0000);
6910 assert_eq!(layout.children[1].y, 75.0000);
6911
6912 assert_eq!(layout.children[2].width, 50.0000);
6913 assert_eq!(layout.children[2].height, 50.0000);
6914 assert_eq!(layout.children[2].x, 150.0000);
6915 assert_eq!(layout.children[2].y, 75.0000);
6916 }
6917
6918 #[test]
6919 fn justify_content_min_width_with_padding_child_width_lower_than_parent() {
6920 let layout = stretch::compute(&stretch::style::Node {
6921 flex_direction: stretch::style::FlexDirection::Column,
6922 width: stretch::style::Dimension::Points(1080.0000),
6923 height: stretch::style::Dimension::Points(1584.0000),
6924 children: vec![stretch::style::Node {
6925 children: vec![stretch::style::Node {
6926 justify_content: stretch::style::JustifyContent::Center,
6927 min_width: stretch::style::Dimension::Points(400.0000),
6928 padding: stretch::style::Edges {
6929 start: stretch::style::Dimension::Points(100.0000),
6930 end: stretch::style::Dimension::Points(100.0000),
6931 ..Default::default()
6932 },
6933 children: vec![stretch::style::Node {
6934 width: stretch::style::Dimension::Points(199.0000),
6935 height: stretch::style::Dimension::Points(100.0000),
6936 ..Default::default()
6937 }],
6938 ..Default::default()
6939 }],
6940 ..Default::default()
6941 }],
6942 ..Default::default()
6943 });
6944
6945 assert_eq!(layout.width, 1080.0000);
6946 assert_eq!(layout.height, 1584.0000);
6947 assert_eq!(layout.x, 0.0000);
6948 assert_eq!(layout.y, 0.0000);
6949
6950 assert_eq!(layout.children[0].width, 1080.0000);
6951 assert_eq!(layout.children[0].height, 100.0000);
6952 assert_eq!(layout.children[0].x, 0.0000);
6953 assert_eq!(layout.children[0].y, 0.0000);
6954
6955 assert_eq!(layout.children[0].children[0].width, 400.0000);
6956 assert_eq!(layout.children[0].children[0].height, 100.0000);
6957 assert_eq!(layout.children[0].children[0].x, 0.0000);
6958 assert_eq!(layout.children[0].children[0].y, 0.0000);
6959
6960 assert_eq!(layout.children[0].children[0].children[0].width, 199.0000);
6961 assert_eq!(layout.children[0].children[0].children[0].height, 100.0000);
6962 assert_eq!(layout.children[0].children[0].children[0].x, 101.0000);
6963 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
6964 }
6965
6966 #[test]
6967 fn size_defined_by_grand_child() {
6968 let layout = stretch::compute(&stretch::style::Node {
6969 children: vec![stretch::style::Node {
6970 children: vec![stretch::style::Node {
6971 width: stretch::style::Dimension::Points(100.0000),
6972 height: stretch::style::Dimension::Points(100.0000),
6973 ..Default::default()
6974 }],
6975 ..Default::default()
6976 }],
6977 ..Default::default()
6978 });
6979
6980 assert_eq!(layout.width, 100.0000);
6981 assert_eq!(layout.height, 100.0000);
6982 assert_eq!(layout.x, 0.0000);
6983 assert_eq!(layout.y, 0.0000);
6984
6985 assert_eq!(layout.children[0].width, 100.0000);
6986 assert_eq!(layout.children[0].height, 100.0000);
6987 assert_eq!(layout.children[0].x, 0.0000);
6988 assert_eq!(layout.children[0].y, 0.0000);
6989
6990 assert_eq!(layout.children[0].children[0].width, 100.0000);
6991 assert_eq!(layout.children[0].children[0].height, 100.0000);
6992 assert_eq!(layout.children[0].children[0].x, 0.0000);
6993 assert_eq!(layout.children[0].children[0].y, 0.0000);
6994 }
6995
6996 #[test]
6997 fn absolute_layout_align_items_and_justify_content_center_and_bottom_position() {
6998 let layout = stretch::compute(&stretch::style::Node {
6999 align_items: stretch::style::AlignItems::Center,
7000 justify_content: stretch::style::JustifyContent::Center,
7001 width: stretch::style::Dimension::Points(110.0000),
7002 height: stretch::style::Dimension::Points(100.0000),
7003 children: vec![stretch::style::Node {
7004 position: stretch::style::Position::Absolute,
7005 width: stretch::style::Dimension::Points(60.0000),
7006 height: stretch::style::Dimension::Points(40.0000),
7007 bottom: stretch::style::Dimension::Points(10.0000),
7008 ..Default::default()
7009 }],
7010 ..Default::default()
7011 });
7012
7013 assert_eq!(layout.width, 110.0000);
7014 assert_eq!(layout.height, 100.0000);
7015 assert_eq!(layout.x, 0.0000);
7016 assert_eq!(layout.y, 0.0000);
7017
7018 assert_eq!(layout.children[0].width, 60.0000);
7019 assert_eq!(layout.children[0].height, 40.0000);
7020 assert_eq!(layout.children[0].x, 25.0000);
7021 assert_eq!(layout.children[0].y, 50.0000);
7022 }
7023
7024 #[test]
7025 fn justify_content_min_max() {
7026 let layout = stretch::compute(&stretch::style::Node {
7027 flex_direction: stretch::style::FlexDirection::Column,
7028 justify_content: stretch::style::JustifyContent::Center,
7029 width: stretch::style::Dimension::Points(100.0000),
7030 min_height: stretch::style::Dimension::Points(100.0000),
7031 max_height: stretch::style::Dimension::Points(200.0000),
7032 children: vec![stretch::style::Node {
7033 width: stretch::style::Dimension::Points(60.0000),
7034 height: stretch::style::Dimension::Points(60.0000),
7035 ..Default::default()
7036 }],
7037 ..Default::default()
7038 });
7039
7040 assert_eq!(layout.width, 100.0000);
7041 assert_eq!(layout.height, 100.0000);
7042 assert_eq!(layout.x, 0.0000);
7043 assert_eq!(layout.y, 0.0000);
7044
7045 assert_eq!(layout.children[0].width, 60.0000);
7046 assert_eq!(layout.children[0].height, 60.0000);
7047 assert_eq!(layout.children[0].x, 0.0000);
7048 assert_eq!(layout.children[0].y, 20.0000);
7049 }
7050
7051 #[test]
7052 fn padding_align_end_child() {
7053 let layout = stretch::compute(&stretch::style::Node {
7054 align_items: stretch::style::AlignItems::FlexEnd,
7055 justify_content: stretch::style::JustifyContent::FlexEnd,
7056 width: stretch::style::Dimension::Points(200.0000),
7057 height: stretch::style::Dimension::Points(200.0000),
7058 children: vec![stretch::style::Node {
7059 width: stretch::style::Dimension::Points(100.0000),
7060 height: stretch::style::Dimension::Points(100.0000),
7061 padding: stretch::style::Edges {
7062 start: stretch::style::Dimension::Points(20.0000),
7063 end: stretch::style::Dimension::Points(20.0000),
7064 top: stretch::style::Dimension::Points(20.0000),
7065 bottom: stretch::style::Dimension::Points(20.0000),
7066 ..Default::default()
7067 },
7068 ..Default::default()
7069 }],
7070 ..Default::default()
7071 });
7072
7073 assert_eq!(layout.width, 200.0000);
7074 assert_eq!(layout.height, 200.0000);
7075 assert_eq!(layout.x, 0.0000);
7076 assert_eq!(layout.y, 0.0000);
7077
7078 assert_eq!(layout.children[0].width, 100.0000);
7079 assert_eq!(layout.children[0].height, 100.0000);
7080 assert_eq!(layout.children[0].x, 100.0000);
7081 assert_eq!(layout.children[0].y, 100.0000);
7082 }
7083
7084 #[test]
7085 fn justify_content_row_space_between() {
7086 let layout = stretch::compute(&stretch::style::Node {
7087 justify_content: stretch::style::JustifyContent::SpaceBetween,
7088 width: stretch::style::Dimension::Points(100.0000),
7089 height: stretch::style::Dimension::Points(100.0000),
7090 children: vec![
7091 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
7092 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
7093 stretch::style::Node { width: stretch::style::Dimension::Points(10.0000), ..Default::default() },
7094 ],
7095 ..Default::default()
7096 });
7097
7098 assert_eq!(layout.width, 100.0000);
7099 assert_eq!(layout.height, 100.0000);
7100 assert_eq!(layout.x, 0.0000);
7101 assert_eq!(layout.y, 0.0000);
7102
7103 assert_eq!(layout.children[0].width, 10.0000);
7104 assert_eq!(layout.children[0].height, 100.0000);
7105 assert_eq!(layout.children[0].x, 0.0000);
7106 assert_eq!(layout.children[0].y, 0.0000);
7107
7108 assert_eq!(layout.children[1].width, 10.0000);
7109 assert_eq!(layout.children[1].height, 100.0000);
7110 assert_eq!(layout.children[1].x, 45.0000);
7111 assert_eq!(layout.children[1].y, 0.0000);
7112
7113 assert_eq!(layout.children[2].width, 10.0000);
7114 assert_eq!(layout.children[2].height, 100.0000);
7115 assert_eq!(layout.children[2].x, 90.0000);
7116 assert_eq!(layout.children[2].y, 0.0000);
7117 }
7118
7119 #[test]
7120 fn align_self_baseline() {
7121 let layout = stretch::compute(&stretch::style::Node {
7122 width: stretch::style::Dimension::Points(100.0000),
7123 height: stretch::style::Dimension::Points(100.0000),
7124 children: vec![
7125 stretch::style::Node {
7126 align_self: stretch::style::AlignSelf::Baseline,
7127 width: stretch::style::Dimension::Points(50.0000),
7128 height: stretch::style::Dimension::Points(50.0000),
7129 ..Default::default()
7130 },
7131 stretch::style::Node {
7132 align_self: stretch::style::AlignSelf::Baseline,
7133 width: stretch::style::Dimension::Points(50.0000),
7134 height: stretch::style::Dimension::Points(20.0000),
7135 children: vec![stretch::style::Node {
7136 width: stretch::style::Dimension::Points(50.0000),
7137 height: stretch::style::Dimension::Points(10.0000),
7138 ..Default::default()
7139 }],
7140 ..Default::default()
7141 },
7142 ],
7143 ..Default::default()
7144 });
7145
7146 assert_eq!(layout.width, 100.0000);
7147 assert_eq!(layout.height, 100.0000);
7148 assert_eq!(layout.x, 0.0000);
7149 assert_eq!(layout.y, 0.0000);
7150
7151 assert_eq!(layout.children[0].width, 50.0000);
7152 assert_eq!(layout.children[0].height, 50.0000);
7153 assert_eq!(layout.children[0].x, 0.0000);
7154 assert_eq!(layout.children[0].y, 0.0000);
7155
7156 assert_eq!(layout.children[1].width, 50.0000);
7157 assert_eq!(layout.children[1].height, 20.0000);
7158 assert_eq!(layout.children[1].x, 50.0000);
7159 assert_eq!(layout.children[1].y, 40.0000);
7160
7161 assert_eq!(layout.children[1].children[0].width, 50.0000);
7162 assert_eq!(layout.children[1].children[0].height, 10.0000);
7163 assert_eq!(layout.children[1].children[0].x, 0.0000);
7164 assert_eq!(layout.children[1].children[0].y, 0.0000);
7165 }
7166
7167 #[test]
7168 fn rounding_fractial_input_1() {
7169 let layout = stretch::compute(&stretch::style::Node {
7170 flex_direction: stretch::style::FlexDirection::Column,
7171 width: stretch::style::Dimension::Points(100.0000),
7172 height: stretch::style::Dimension::Points(113.4000),
7173 children: vec![
7174 stretch::style::Node {
7175 flex_grow: 1.0000,
7176 flex_basis: stretch::style::Dimension::Points(50.0000),
7177 height: stretch::style::Dimension::Points(20.0000),
7178 ..Default::default()
7179 },
7180 stretch::style::Node {
7181 flex_grow: 1.0000,
7182 height: stretch::style::Dimension::Points(10.0000),
7183 ..Default::default()
7184 },
7185 stretch::style::Node {
7186 flex_grow: 1.0000,
7187 height: stretch::style::Dimension::Points(10.0000),
7188 ..Default::default()
7189 },
7190 ],
7191 ..Default::default()
7192 });
7193
7194 assert_eq!(layout.width, 100.0000);
7195 assert_eq!(layout.height, 113.0000);
7196 assert_eq!(layout.x, 0.0000);
7197 assert_eq!(layout.y, 0.0000);
7198
7199 assert_eq!(layout.children[0].width, 100.0000);
7200 assert_eq!(layout.children[0].height, 64.0000);
7201 assert_eq!(layout.children[0].x, 0.0000);
7202 assert_eq!(layout.children[0].y, 0.0000);
7203
7204 assert_eq!(layout.children[1].width, 100.0000);
7205 assert_eq!(layout.children[1].height, 25.0000);
7206 assert_eq!(layout.children[1].x, 0.0000);
7207 assert_eq!(layout.children[1].y, 64.0000);
7208
7209 assert_eq!(layout.children[2].width, 100.0000);
7210 assert_eq!(layout.children[2].height, 24.0000);
7211 assert_eq!(layout.children[2].x, 0.0000);
7212 assert_eq!(layout.children[2].y, 89.0000);
7213 }
7214
7215 #[test]
7216 fn absolute_layout_align_items_center() {
7217 let layout = stretch::compute(&stretch::style::Node {
7218 align_items: stretch::style::AlignItems::Center,
7219 width: stretch::style::Dimension::Points(110.0000),
7220 height: stretch::style::Dimension::Points(100.0000),
7221 children: vec![stretch::style::Node {
7222 position: stretch::style::Position::Absolute,
7223 width: stretch::style::Dimension::Points(60.0000),
7224 height: stretch::style::Dimension::Points(40.0000),
7225 ..Default::default()
7226 }],
7227 ..Default::default()
7228 });
7229
7230 assert_eq!(layout.width, 110.0000);
7231 assert_eq!(layout.height, 100.0000);
7232 assert_eq!(layout.x, 0.0000);
7233 assert_eq!(layout.y, 0.0000);
7234
7235 assert_eq!(layout.children[0].width, 60.0000);
7236 assert_eq!(layout.children[0].height, 40.0000);
7237 assert_eq!(layout.children[0].x, 0.0000);
7238 assert_eq!(layout.children[0].y, 30.0000);
7239 }
7240
7241 #[test]
7242 fn flex_basis_slightly_smaller_then_content_with_flex_grow_large_size() {
7243 let layout = stretch::compute(&stretch::style::Node {
7244 width: stretch::style::Dimension::Points(100.0000),
7245 children: vec![
7246 stretch::style::Node {
7247 flex_direction: stretch::style::FlexDirection::Column,
7248 flex_grow: 1.0000,
7249 flex_basis: stretch::style::Dimension::Points(60.0000),
7250 children: vec![stretch::style::Node {
7251 width: stretch::style::Dimension::Points(70.0000),
7252 height: stretch::style::Dimension::Points(100.0000),
7253 ..Default::default()
7254 }],
7255 ..Default::default()
7256 },
7257 stretch::style::Node {
7258 flex_direction: stretch::style::FlexDirection::Column,
7259 flex_grow: 1.0000,
7260 flex_basis: stretch::style::Dimension::Points(0.0000),
7261 children: vec![stretch::style::Node {
7262 width: stretch::style::Dimension::Points(20.0000),
7263 height: stretch::style::Dimension::Points(100.0000),
7264 ..Default::default()
7265 }],
7266 ..Default::default()
7267 },
7268 ],
7269 ..Default::default()
7270 });
7271
7272 assert_eq!(layout.width, 100.0000);
7273 assert_eq!(layout.height, 100.0000);
7274 assert_eq!(layout.x, 0.0000);
7275 assert_eq!(layout.y, 0.0000);
7276
7277 assert_eq!(layout.children[0].width, 80.0000);
7278 assert_eq!(layout.children[0].height, 100.0000);
7279 assert_eq!(layout.children[0].x, 0.0000);
7280 assert_eq!(layout.children[0].y, 0.0000);
7281
7282 assert_eq!(layout.children[0].children[0].width, 70.0000);
7283 assert_eq!(layout.children[0].children[0].height, 100.0000);
7284 assert_eq!(layout.children[0].children[0].x, 0.0000);
7285 assert_eq!(layout.children[0].children[0].y, 0.0000);
7286
7287 assert_eq!(layout.children[1].width, 20.0000);
7288 assert_eq!(layout.children[1].height, 100.0000);
7289 assert_eq!(layout.children[1].x, 80.0000);
7290 assert_eq!(layout.children[1].y, 0.0000);
7291
7292 assert_eq!(layout.children[1].children[0].width, 20.0000);
7293 assert_eq!(layout.children[1].children[0].height, 100.0000);
7294 assert_eq!(layout.children[1].children[0].x, 0.0000);
7295 assert_eq!(layout.children[1].children[0].y, 0.0000);
7296 }
7297
7298 #[test]
7299 fn percentage_flex_basis_cross_min_width() {
7300 let layout = stretch::compute(&stretch::style::Node {
7301 flex_direction: stretch::style::FlexDirection::Column,
7302 width: stretch::style::Dimension::Points(200.0000),
7303 height: stretch::style::Dimension::Points(200.0000),
7304 children: vec![
7305 stretch::style::Node {
7306 flex_grow: 1.0000,
7307 flex_basis: stretch::style::Dimension::Percent(0.1000),
7308 min_width: stretch::style::Dimension::Percent(0.6000),
7309 ..Default::default()
7310 },
7311 stretch::style::Node {
7312 flex_grow: 4.0000,
7313 flex_basis: stretch::style::Dimension::Percent(0.1500),
7314 min_width: stretch::style::Dimension::Percent(0.2000),
7315 ..Default::default()
7316 },
7317 ],
7318 ..Default::default()
7319 });
7320
7321 assert_eq!(layout.width, 200.0000);
7322 assert_eq!(layout.height, 200.0000);
7323 assert_eq!(layout.x, 0.0000);
7324 assert_eq!(layout.y, 0.0000);
7325
7326 assert_eq!(layout.children[0].width, 200.0000);
7327 assert_eq!(layout.children[0].height, 50.0000);
7328 assert_eq!(layout.children[0].x, 0.0000);
7329 assert_eq!(layout.children[0].y, 0.0000);
7330
7331 assert_eq!(layout.children[1].width, 200.0000);
7332 assert_eq!(layout.children[1].height, 150.0000);
7333 assert_eq!(layout.children[1].x, 0.0000);
7334 assert_eq!(layout.children[1].y, 50.0000);
7335 }
7336
7337 #[test]
7338 fn margin_auto_left_and_right_column_and_center() {
7339 let layout = stretch::compute(&stretch::style::Node {
7340 align_items: stretch::style::AlignItems::Center,
7341 width: stretch::style::Dimension::Points(200.0000),
7342 height: stretch::style::Dimension::Points(200.0000),
7343 children: vec![
7344 stretch::style::Node {
7345 width: stretch::style::Dimension::Points(50.0000),
7346 height: stretch::style::Dimension::Points(50.0000),
7347 margin: stretch::style::Edges {
7348 start: stretch::style::Dimension::Auto,
7349 end: stretch::style::Dimension::Auto,
7350 ..Default::default()
7351 },
7352 ..Default::default()
7353 },
7354 stretch::style::Node {
7355 width: stretch::style::Dimension::Points(50.0000),
7356 height: stretch::style::Dimension::Points(50.0000),
7357 ..Default::default()
7358 },
7359 ],
7360 ..Default::default()
7361 });
7362
7363 assert_eq!(layout.width, 200.0000);
7364 assert_eq!(layout.height, 200.0000);
7365 assert_eq!(layout.x, 0.0000);
7366 assert_eq!(layout.y, 0.0000);
7367
7368 assert_eq!(layout.children[0].width, 50.0000);
7369 assert_eq!(layout.children[0].height, 50.0000);
7370 assert_eq!(layout.children[0].x, 50.0000);
7371 assert_eq!(layout.children[0].y, 75.0000);
7372
7373 assert_eq!(layout.children[1].width, 50.0000);
7374 assert_eq!(layout.children[1].height, 50.0000);
7375 assert_eq!(layout.children[1].x, 150.0000);
7376 assert_eq!(layout.children[1].y, 75.0000);
7377 }
7378
7379 #[test]
7380 fn flex_grow_less_than_factor_one() {
7381 let layout = stretch::compute(&stretch::style::Node {
7382 width: stretch::style::Dimension::Points(500.0000),
7383 height: stretch::style::Dimension::Points(200.0000),
7384 children: vec![
7385 stretch::style::Node {
7386 flex_grow: 0.2000,
7387 flex_shrink: 0.0000,
7388 flex_basis: stretch::style::Dimension::Points(40.0000),
7389 ..Default::default()
7390 },
7391 stretch::style::Node { flex_grow: 0.2000, flex_shrink: 0.0000, ..Default::default() },
7392 stretch::style::Node { flex_grow: 0.4000, flex_shrink: 0.0000, ..Default::default() },
7393 ],
7394 ..Default::default()
7395 });
7396
7397 assert_eq!(layout.width, 500.0000);
7398 assert_eq!(layout.height, 200.0000);
7399 assert_eq!(layout.x, 0.0000);
7400 assert_eq!(layout.y, 0.0000);
7401
7402 assert_eq!(layout.children[0].width, 132.0000);
7403 assert_eq!(layout.children[0].height, 200.0000);
7404 assert_eq!(layout.children[0].x, 0.0000);
7405 assert_eq!(layout.children[0].y, 0.0000);
7406
7407 assert_eq!(layout.children[1].width, 92.0000);
7408 assert_eq!(layout.children[1].height, 200.0000);
7409 assert_eq!(layout.children[1].x, 132.0000);
7410 assert_eq!(layout.children[1].y, 0.0000);
7411
7412 assert_eq!(layout.children[2].width, 184.0000);
7413 assert_eq!(layout.children[2].height, 200.0000);
7414 assert_eq!(layout.children[2].x, 224.0000);
7415 assert_eq!(layout.children[2].y, 0.0000);
7416 }
7417
7418 #[test]
7419 fn flex_grow_within_constrained_min_max_column() {
7420 let layout = stretch::compute(&stretch::style::Node {
7421 min_height: stretch::style::Dimension::Points(100.0000),
7422 children: vec![
7423 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7424 stretch::style::Node { height: stretch::style::Dimension::Points(50.0000), ..Default::default() },
7425 ],
7426 ..Default::default()
7427 });
7428
7429 assert_eq!(layout.width, 0.0000);
7430 assert_eq!(layout.height, 100.0000);
7431 assert_eq!(layout.x, 0.0000);
7432 assert_eq!(layout.y, 0.0000);
7433
7434 assert_eq!(layout.children[0].width, 0.0000);
7435 assert_eq!(layout.children[0].height, 100.0000);
7436 assert_eq!(layout.children[0].x, 0.0000);
7437 assert_eq!(layout.children[0].y, 0.0000);
7438
7439 assert_eq!(layout.children[1].width, 0.0000);
7440 assert_eq!(layout.children[1].height, 50.0000);
7441 assert_eq!(layout.children[1].x, 0.0000);
7442 assert_eq!(layout.children[1].y, 0.0000);
7443 }
7444
7445 #[test]
7446 fn percentage_flex_basis_cross_max_height() {
7447 let layout = stretch::compute(&stretch::style::Node {
7448 flex_direction: stretch::style::FlexDirection::Column,
7449 width: stretch::style::Dimension::Points(200.0000),
7450 height: stretch::style::Dimension::Points(200.0000),
7451 children: vec![
7452 stretch::style::Node {
7453 flex_grow: 1.0000,
7454 flex_basis: stretch::style::Dimension::Percent(0.1000),
7455 max_height: stretch::style::Dimension::Percent(0.6000),
7456 ..Default::default()
7457 },
7458 stretch::style::Node {
7459 flex_grow: 4.0000,
7460 flex_basis: stretch::style::Dimension::Percent(0.1000),
7461 max_height: stretch::style::Dimension::Percent(0.2000),
7462 ..Default::default()
7463 },
7464 ],
7465 ..Default::default()
7466 });
7467
7468 assert_eq!(layout.width, 200.0000);
7469 assert_eq!(layout.height, 200.0000);
7470 assert_eq!(layout.x, 0.0000);
7471 assert_eq!(layout.y, 0.0000);
7472
7473 assert_eq!(layout.children[0].width, 200.0000);
7474 assert_eq!(layout.children[0].height, 120.0000);
7475 assert_eq!(layout.children[0].x, 0.0000);
7476 assert_eq!(layout.children[0].y, 0.0000);
7477
7478 assert_eq!(layout.children[1].width, 200.0000);
7479 assert_eq!(layout.children[1].height, 40.0000);
7480 assert_eq!(layout.children[1].x, 0.0000);
7481 assert_eq!(layout.children[1].y, 120.0000);
7482 }
7483
7484 #[test]
7485 fn justify_content_column_flex_end() {
7486 let layout = stretch::compute(&stretch::style::Node {
7487 flex_direction: stretch::style::FlexDirection::Column,
7488 justify_content: stretch::style::JustifyContent::FlexEnd,
7489 width: stretch::style::Dimension::Points(100.0000),
7490 height: stretch::style::Dimension::Points(100.0000),
7491 children: vec![
7492 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
7493 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
7494 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
7495 ],
7496 ..Default::default()
7497 });
7498
7499 assert_eq!(layout.width, 100.0000);
7500 assert_eq!(layout.height, 100.0000);
7501 assert_eq!(layout.x, 0.0000);
7502 assert_eq!(layout.y, 0.0000);
7503
7504 assert_eq!(layout.children[0].width, 100.0000);
7505 assert_eq!(layout.children[0].height, 10.0000);
7506 assert_eq!(layout.children[0].x, 0.0000);
7507 assert_eq!(layout.children[0].y, 70.0000);
7508
7509 assert_eq!(layout.children[1].width, 100.0000);
7510 assert_eq!(layout.children[1].height, 10.0000);
7511 assert_eq!(layout.children[1].x, 0.0000);
7512 assert_eq!(layout.children[1].y, 80.0000);
7513
7514 assert_eq!(layout.children[2].width, 100.0000);
7515 assert_eq!(layout.children[2].height, 10.0000);
7516 assert_eq!(layout.children[2].x, 0.0000);
7517 assert_eq!(layout.children[2].y, 90.0000);
7518 }
7519
7520 #[test]
7521 fn rounding_flex_basis_flex_grow_row_width_of_100() {
7522 let layout = stretch::compute(&stretch::style::Node {
7523 width: stretch::style::Dimension::Points(100.0000),
7524 height: stretch::style::Dimension::Points(100.0000),
7525 children: vec![
7526 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7527 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7528 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7529 ],
7530 ..Default::default()
7531 });
7532
7533 assert_eq!(layout.width, 100.0000);
7534 assert_eq!(layout.height, 100.0000);
7535 assert_eq!(layout.x, 0.0000);
7536 assert_eq!(layout.y, 0.0000);
7537
7538 assert_eq!(layout.children[0].width, 33.0000);
7539 assert_eq!(layout.children[0].height, 100.0000);
7540 assert_eq!(layout.children[0].x, 0.0000);
7541 assert_eq!(layout.children[0].y, 0.0000);
7542
7543 assert_eq!(layout.children[1].width, 34.0000);
7544 assert_eq!(layout.children[1].height, 100.0000);
7545 assert_eq!(layout.children[1].x, 33.0000);
7546 assert_eq!(layout.children[1].y, 0.0000);
7547
7548 assert_eq!(layout.children[2].width, 33.0000);
7549 assert_eq!(layout.children[2].height, 100.0000);
7550 assert_eq!(layout.children[2].x, 67.0000);
7551 assert_eq!(layout.children[2].y, 0.0000);
7552 }
7553
7554 #[test]
7555 fn wrap_reverse_row_align_content_flex_start() {
7556 let layout = stretch::compute(&stretch::style::Node {
7557 flex_wrap: stretch::style::FlexWrap::WrapReverse,
7558 align_content: stretch::style::AlignContent::FlexStart,
7559 width: stretch::style::Dimension::Points(100.0000),
7560 children: vec![
7561 stretch::style::Node {
7562 width: stretch::style::Dimension::Points(30.0000),
7563 height: stretch::style::Dimension::Points(10.0000),
7564 ..Default::default()
7565 },
7566 stretch::style::Node {
7567 width: stretch::style::Dimension::Points(30.0000),
7568 height: stretch::style::Dimension::Points(20.0000),
7569 ..Default::default()
7570 },
7571 stretch::style::Node {
7572 width: stretch::style::Dimension::Points(30.0000),
7573 height: stretch::style::Dimension::Points(30.0000),
7574 ..Default::default()
7575 },
7576 stretch::style::Node {
7577 width: stretch::style::Dimension::Points(30.0000),
7578 height: stretch::style::Dimension::Points(40.0000),
7579 ..Default::default()
7580 },
7581 stretch::style::Node {
7582 width: stretch::style::Dimension::Points(30.0000),
7583 height: stretch::style::Dimension::Points(50.0000),
7584 ..Default::default()
7585 },
7586 ],
7587 ..Default::default()
7588 });
7589
7590 assert_eq!(layout.width, 100.0000);
7591 assert_eq!(layout.height, 80.0000);
7592 assert_eq!(layout.x, 0.0000);
7593 assert_eq!(layout.y, 0.0000);
7594
7595 assert_eq!(layout.children[0].width, 30.0000);
7596 assert_eq!(layout.children[0].height, 10.0000);
7597 assert_eq!(layout.children[0].x, 0.0000);
7598 assert_eq!(layout.children[0].y, 70.0000);
7599
7600 assert_eq!(layout.children[1].width, 30.0000);
7601 assert_eq!(layout.children[1].height, 20.0000);
7602 assert_eq!(layout.children[1].x, 30.0000);
7603 assert_eq!(layout.children[1].y, 60.0000);
7604
7605 assert_eq!(layout.children[2].width, 30.0000);
7606 assert_eq!(layout.children[2].height, 30.0000);
7607 assert_eq!(layout.children[2].x, 60.0000);
7608 assert_eq!(layout.children[2].y, 50.0000);
7609
7610 assert_eq!(layout.children[3].width, 30.0000);
7611 assert_eq!(layout.children[3].height, 40.0000);
7612 assert_eq!(layout.children[3].x, 0.0000);
7613 assert_eq!(layout.children[3].y, 10.0000);
7614
7615 assert_eq!(layout.children[4].width, 30.0000);
7616 assert_eq!(layout.children[4].height, 50.0000);
7617 assert_eq!(layout.children[4].x, 30.0000);
7618 assert_eq!(layout.children[4].y, 0.0000);
7619 }
7620
7621 #[test]
7622 fn flex_shrink_flex_grow_child_flex_shrink_other_child() {
7623 let layout = stretch::compute(&stretch::style::Node {
7624 width: stretch::style::Dimension::Points(500.0000),
7625 height: stretch::style::Dimension::Points(500.0000),
7626 children: vec![
7627 stretch::style::Node {
7628 flex_grow: 0.0000,
7629 flex_shrink: 1.0000,
7630 width: stretch::style::Dimension::Points(500.0000),
7631 height: stretch::style::Dimension::Points(100.0000),
7632 ..Default::default()
7633 },
7634 stretch::style::Node {
7635 flex_grow: 1.0000,
7636 flex_shrink: 1.0000,
7637 width: stretch::style::Dimension::Points(500.0000),
7638 height: stretch::style::Dimension::Points(100.0000),
7639 ..Default::default()
7640 },
7641 ],
7642 ..Default::default()
7643 });
7644
7645 assert_eq!(layout.width, 500.0000);
7646 assert_eq!(layout.height, 500.0000);
7647 assert_eq!(layout.x, 0.0000);
7648 assert_eq!(layout.y, 0.0000);
7649
7650 assert_eq!(layout.children[0].width, 250.0000);
7651 assert_eq!(layout.children[0].height, 100.0000);
7652 assert_eq!(layout.children[0].x, 0.0000);
7653 assert_eq!(layout.children[0].y, 0.0000);
7654
7655 assert_eq!(layout.children[1].width, 250.0000);
7656 assert_eq!(layout.children[1].height, 100.0000);
7657 assert_eq!(layout.children[1].x, 250.0000);
7658 assert_eq!(layout.children[1].y, 0.0000);
7659 }
7660
7661 #[test]
7662 fn flex_basis_unconstraint_row() {
7663 let layout = stretch::compute(&stretch::style::Node {
7664 children: vec![stretch::style::Node {
7665 flex_basis: stretch::style::Dimension::Points(50.0000),
7666 height: stretch::style::Dimension::Points(100.0000),
7667 ..Default::default()
7668 }],
7669 ..Default::default()
7670 });
7671
7672 assert_eq!(layout.width, 0.0000);
7673 assert_eq!(layout.height, 100.0000);
7674 assert_eq!(layout.x, 0.0000);
7675 assert_eq!(layout.y, 0.0000);
7676
7677 assert_eq!(layout.children[0].width, 0.0000);
7678 assert_eq!(layout.children[0].height, 100.0000);
7679 assert_eq!(layout.children[0].x, 0.0000);
7680 assert_eq!(layout.children[0].y, 0.0000);
7681 }
7682
7683 #[test]
7684 fn align_items_flex_end() {
7685 let layout = stretch::compute(&stretch::style::Node {
7686 align_items: stretch::style::AlignItems::FlexEnd,
7687 width: stretch::style::Dimension::Points(100.0000),
7688 height: stretch::style::Dimension::Points(100.0000),
7689 children: vec![stretch::style::Node {
7690 width: stretch::style::Dimension::Points(10.0000),
7691 height: stretch::style::Dimension::Points(10.0000),
7692 ..Default::default()
7693 }],
7694 ..Default::default()
7695 });
7696
7697 assert_eq!(layout.width, 100.0000);
7698 assert_eq!(layout.height, 100.0000);
7699 assert_eq!(layout.x, 0.0000);
7700 assert_eq!(layout.y, 0.0000);
7701
7702 assert_eq!(layout.children[0].width, 10.0000);
7703 assert_eq!(layout.children[0].height, 10.0000);
7704 assert_eq!(layout.children[0].x, 0.0000);
7705 assert_eq!(layout.children[0].y, 90.0000);
7706 }
7707
7708 #[test]
7709 fn absolute_layout_width_height_start_top() {
7710 let layout = stretch::compute(&stretch::style::Node {
7711 width: stretch::style::Dimension::Points(100.0000),
7712 height: stretch::style::Dimension::Points(100.0000),
7713 children: vec![stretch::style::Node {
7714 position: stretch::style::Position::Absolute,
7715 width: stretch::style::Dimension::Points(10.0000),
7716 height: stretch::style::Dimension::Points(10.0000),
7717 start: stretch::style::Dimension::Points(10.0000),
7718 top: stretch::style::Dimension::Points(10.0000),
7719 ..Default::default()
7720 }],
7721 ..Default::default()
7722 });
7723
7724 assert_eq!(layout.width, 100.0000);
7725 assert_eq!(layout.height, 100.0000);
7726 assert_eq!(layout.x, 0.0000);
7727 assert_eq!(layout.y, 0.0000);
7728
7729 assert_eq!(layout.children[0].width, 10.0000);
7730 assert_eq!(layout.children[0].height, 10.0000);
7731 assert_eq!(layout.children[0].x, 10.0000);
7732 assert_eq!(layout.children[0].y, 10.0000);
7733 }
7734
7735 #[test]
7736 fn rounding_flex_basis_flex_shrink_row() {
7737 let layout = stretch::compute(&stretch::style::Node {
7738 width: stretch::style::Dimension::Points(101.0000),
7739 height: stretch::style::Dimension::Points(100.0000),
7740 children: vec![
7741 stretch::style::Node {
7742 flex_shrink: 1.0000,
7743 flex_basis: stretch::style::Dimension::Points(100.0000),
7744 ..Default::default()
7745 },
7746 stretch::style::Node { flex_basis: stretch::style::Dimension::Points(25.0000), ..Default::default() },
7747 stretch::style::Node { flex_basis: stretch::style::Dimension::Points(25.0000), ..Default::default() },
7748 ],
7749 ..Default::default()
7750 });
7751
7752 assert_eq!(layout.width, 101.0000);
7753 assert_eq!(layout.height, 100.0000);
7754 assert_eq!(layout.x, 0.0000);
7755 assert_eq!(layout.y, 0.0000);
7756
7757 assert_eq!(layout.children[0].width, 67.0000);
7758 assert_eq!(layout.children[0].height, 100.0000);
7759 assert_eq!(layout.children[0].x, 0.0000);
7760 assert_eq!(layout.children[0].y, 0.0000);
7761
7762 assert_eq!(layout.children[1].width, 17.0000);
7763 assert_eq!(layout.children[1].height, 100.0000);
7764 assert_eq!(layout.children[1].x, 67.0000);
7765 assert_eq!(layout.children[1].y, 0.0000);
7766
7767 assert_eq!(layout.children[2].width, 17.0000);
7768 assert_eq!(layout.children[2].height, 100.0000);
7769 assert_eq!(layout.children[2].x, 84.0000);
7770 assert_eq!(layout.children[2].y, 0.0000);
7771 }
7772
7773 #[test]
7774 fn border_center_child() {
7775 let layout = stretch::compute(&stretch::style::Node {
7776 align_items: stretch::style::AlignItems::Center,
7777 justify_content: stretch::style::JustifyContent::Center,
7778 width: stretch::style::Dimension::Points(100.0000),
7779 height: stretch::style::Dimension::Points(100.0000),
7780 border: stretch::style::Edges {
7781 top: stretch::style::Dimension::Points(10.0000),
7782 bottom: stretch::style::Dimension::Points(20.0000),
7783 ..Default::default()
7784 },
7785 children: vec![stretch::style::Node {
7786 width: stretch::style::Dimension::Points(10.0000),
7787 height: stretch::style::Dimension::Points(10.0000),
7788 ..Default::default()
7789 }],
7790 ..Default::default()
7791 });
7792
7793 assert_eq!(layout.width, 100.0000);
7794 assert_eq!(layout.height, 100.0000);
7795 assert_eq!(layout.x, 0.0000);
7796 assert_eq!(layout.y, 0.0000);
7797
7798 assert_eq!(layout.children[0].width, 10.0000);
7799 assert_eq!(layout.children[0].height, 10.0000);
7800 assert_eq!(layout.children[0].x, 45.0000);
7801 assert_eq!(layout.children[0].y, 40.0000);
7802 }
7803
7804 #[test]
7805 fn align_items_flex_start() {
7806 let layout = stretch::compute(&stretch::style::Node {
7807 align_items: stretch::style::AlignItems::FlexStart,
7808 width: stretch::style::Dimension::Points(100.0000),
7809 height: stretch::style::Dimension::Points(100.0000),
7810 children: vec![stretch::style::Node {
7811 width: stretch::style::Dimension::Points(10.0000),
7812 height: stretch::style::Dimension::Points(10.0000),
7813 ..Default::default()
7814 }],
7815 ..Default::default()
7816 });
7817
7818 assert_eq!(layout.width, 100.0000);
7819 assert_eq!(layout.height, 100.0000);
7820 assert_eq!(layout.x, 0.0000);
7821 assert_eq!(layout.y, 0.0000);
7822
7823 assert_eq!(layout.children[0].width, 10.0000);
7824 assert_eq!(layout.children[0].height, 10.0000);
7825 assert_eq!(layout.children[0].x, 0.0000);
7826 assert_eq!(layout.children[0].y, 0.0000);
7827 }
7828
7829 #[test]
7830 fn border_no_child() {
7831 let layout = stretch::compute(&stretch::style::Node {
7832 border: stretch::style::Edges {
7833 start: stretch::style::Dimension::Points(10.0000),
7834 end: stretch::style::Dimension::Points(10.0000),
7835 top: stretch::style::Dimension::Points(10.0000),
7836 bottom: stretch::style::Dimension::Points(10.0000),
7837 ..Default::default()
7838 },
7839 ..Default::default()
7840 });
7841
7842 assert_eq!(layout.width, 20.0000);
7843 assert_eq!(layout.height, 20.0000);
7844 assert_eq!(layout.x, 0.0000);
7845 assert_eq!(layout.y, 0.0000);
7846 }
7847
7848 #[test]
7849 fn rounding_flex_basis_flex_grow_row_prime_number_width() {
7850 let layout = stretch::compute(&stretch::style::Node {
7851 width: stretch::style::Dimension::Points(113.0000),
7852 height: stretch::style::Dimension::Points(100.0000),
7853 children: vec![
7854 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7855 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7856 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7857 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7858 stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7859 ],
7860 ..Default::default()
7861 });
7862
7863 assert_eq!(layout.width, 113.0000);
7864 assert_eq!(layout.height, 100.0000);
7865 assert_eq!(layout.x, 0.0000);
7866 assert_eq!(layout.y, 0.0000);
7867
7868 assert_eq!(layout.children[0].width, 23.0000);
7869 assert_eq!(layout.children[0].height, 100.0000);
7870 assert_eq!(layout.children[0].x, 0.0000);
7871 assert_eq!(layout.children[0].y, 0.0000);
7872
7873 assert_eq!(layout.children[1].width, 22.0000);
7874 assert_eq!(layout.children[1].height, 100.0000);
7875 assert_eq!(layout.children[1].x, 23.0000);
7876 assert_eq!(layout.children[1].y, 0.0000);
7877
7878 assert_eq!(layout.children[2].width, 23.0000);
7879 assert_eq!(layout.children[2].height, 100.0000);
7880 assert_eq!(layout.children[2].x, 45.0000);
7881 assert_eq!(layout.children[2].y, 0.0000);
7882
7883 assert_eq!(layout.children[3].width, 22.0000);
7884 assert_eq!(layout.children[3].height, 100.0000);
7885 assert_eq!(layout.children[3].x, 68.0000);
7886 assert_eq!(layout.children[3].y, 0.0000);
7887
7888 assert_eq!(layout.children[4].width, 23.0000);
7889 assert_eq!(layout.children[4].height, 100.0000);
7890 assert_eq!(layout.children[4].x, 90.0000);
7891 assert_eq!(layout.children[4].y, 0.0000);
7892 }
7893
7894 #[test]
7895 fn align_items_center_with_child_top() {
7896 let layout = stretch::compute(&stretch::style::Node {
7897 align_items: stretch::style::AlignItems::Center,
7898 width: stretch::style::Dimension::Points(100.0000),
7899 height: stretch::style::Dimension::Points(100.0000),
7900 children: vec![stretch::style::Node {
7901 width: stretch::style::Dimension::Points(10.0000),
7902 height: stretch::style::Dimension::Points(10.0000),
7903 top: stretch::style::Dimension::Points(10.0000),
7904 ..Default::default()
7905 }],
7906 ..Default::default()
7907 });
7908
7909 assert_eq!(layout.width, 100.0000);
7910 assert_eq!(layout.height, 100.0000);
7911 assert_eq!(layout.x, 0.0000);
7912 assert_eq!(layout.y, 0.0000);
7913
7914 assert_eq!(layout.children[0].width, 10.0000);
7915 assert_eq!(layout.children[0].height, 10.0000);
7916 assert_eq!(layout.children[0].x, 0.0000);
7917 assert_eq!(layout.children[0].y, 55.0000);
7918 }
7919
7920 #[test]
7921 fn width_smaller_then_content_with_flex_grow_large_size() {
7922 let layout = stretch::compute(&stretch::style::Node {
7923 width: stretch::style::Dimension::Points(100.0000),
7924 children: vec![
7925 stretch::style::Node {
7926 flex_direction: stretch::style::FlexDirection::Column,
7927 flex_grow: 1.0000,
7928 width: stretch::style::Dimension::Points(0.0000),
7929 children: vec![stretch::style::Node {
7930 width: stretch::style::Dimension::Points(70.0000),
7931 height: stretch::style::Dimension::Points(100.0000),
7932 ..Default::default()
7933 }],
7934 ..Default::default()
7935 },
7936 stretch::style::Node {
7937 flex_direction: stretch::style::FlexDirection::Column,
7938 flex_grow: 1.0000,
7939 width: stretch::style::Dimension::Points(0.0000),
7940 children: vec![stretch::style::Node {
7941 width: stretch::style::Dimension::Points(20.0000),
7942 height: stretch::style::Dimension::Points(100.0000),
7943 ..Default::default()
7944 }],
7945 ..Default::default()
7946 },
7947 ],
7948 ..Default::default()
7949 });
7950
7951 assert_eq!(layout.width, 100.0000);
7952 assert_eq!(layout.height, 100.0000);
7953 assert_eq!(layout.x, 0.0000);
7954 assert_eq!(layout.y, 0.0000);
7955
7956 assert_eq!(layout.children[0].width, 50.0000);
7957 assert_eq!(layout.children[0].height, 100.0000);
7958 assert_eq!(layout.children[0].x, 0.0000);
7959 assert_eq!(layout.children[0].y, 0.0000);
7960
7961 assert_eq!(layout.children[0].children[0].width, 70.0000);
7962 assert_eq!(layout.children[0].children[0].height, 100.0000);
7963 assert_eq!(layout.children[0].children[0].x, 0.0000);
7964 assert_eq!(layout.children[0].children[0].y, 0.0000);
7965
7966 assert_eq!(layout.children[1].width, 50.0000);
7967 assert_eq!(layout.children[1].height, 100.0000);
7968 assert_eq!(layout.children[1].x, 50.0000);
7969 assert_eq!(layout.children[1].y, 0.0000);
7970
7971 assert_eq!(layout.children[1].children[0].width, 20.0000);
7972 assert_eq!(layout.children[1].children[0].height, 100.0000);
7973 assert_eq!(layout.children[1].children[0].x, 0.0000);
7974 assert_eq!(layout.children[1].children[0].y, 0.0000);
7975 }
7976
7977 #[test]
7978 fn flex_basis_smaller_than_content_column() {
7979 let layout = stretch::compute(&stretch::style::Node {
7980 flex_direction: stretch::style::FlexDirection::Column,
7981 height: stretch::style::Dimension::Points(100.0000),
7982 children: vec![stretch::style::Node {
7983 flex_direction: stretch::style::FlexDirection::Column,
7984 flex_basis: stretch::style::Dimension::Points(50.0000),
7985 children: vec![stretch::style::Node {
7986 width: stretch::style::Dimension::Points(100.0000),
7987 height: stretch::style::Dimension::Points(100.0000),
7988 ..Default::default()
7989 }],
7990 ..Default::default()
7991 }],
7992 ..Default::default()
7993 });
7994
7995 assert_eq!(layout.width, 100.0000);
7996 assert_eq!(layout.height, 100.0000);
7997 assert_eq!(layout.x, 0.0000);
7998 assert_eq!(layout.y, 0.0000);
7999
8000 assert_eq!(layout.children[0].width, 100.0000);
8001 assert_eq!(layout.children[0].height, 50.0000);
8002 assert_eq!(layout.children[0].x, 0.0000);
8003 assert_eq!(layout.children[0].y, 0.0000);
8004
8005 assert_eq!(layout.children[0].children[0].width, 100.0000);
8006 assert_eq!(layout.children[0].children[0].height, 50.0000);
8007 assert_eq!(layout.children[0].children[0].x, 0.0000);
8008 assert_eq!(layout.children[0].children[0].y, 0.0000);
8009 }
8010
8011 #[test]
8012 fn percentage_width_height_undefined_parent_size() {
8013 let layout = stretch::compute(&stretch::style::Node {
8014 flex_direction: stretch::style::FlexDirection::Column,
8015 children: vec![stretch::style::Node {
8016 width: stretch::style::Dimension::Percent(0.5000),
8017 height: stretch::style::Dimension::Percent(0.5000),
8018 ..Default::default()
8019 }],
8020 ..Default::default()
8021 });
8022
8023 assert_eq!(layout.width, 0.0000);
8024 assert_eq!(layout.height, 0.0000);
8025 assert_eq!(layout.x, 0.0000);
8026 assert_eq!(layout.y, 0.0000);
8027
8028 assert_eq!(layout.children[0].width, 0.0000);
8029 assert_eq!(layout.children[0].height, 0.0000);
8030 assert_eq!(layout.children[0].x, 0.0000);
8031 assert_eq!(layout.children[0].y, 0.0000);
8032 }
8033
8034 #[test]
8035 fn flex_grow_within_max_width() {
8036 let layout = stretch::compute(&stretch::style::Node {
8037 flex_direction: stretch::style::FlexDirection::Column,
8038 width: stretch::style::Dimension::Points(200.0000),
8039 height: stretch::style::Dimension::Points(100.0000),
8040 children: vec![stretch::style::Node {
8041 max_width: stretch::style::Dimension::Points(100.0000),
8042 children: vec![stretch::style::Node {
8043 flex_grow: 1.0000,
8044 height: stretch::style::Dimension::Points(20.0000),
8045 ..Default::default()
8046 }],
8047 ..Default::default()
8048 }],
8049 ..Default::default()
8050 });
8051
8052 assert_eq!(layout.width, 200.0000);
8053 assert_eq!(layout.height, 100.0000);
8054 assert_eq!(layout.x, 0.0000);
8055 assert_eq!(layout.y, 0.0000);
8056
8057 assert_eq!(layout.children[0].width, 100.0000);
8058 assert_eq!(layout.children[0].height, 20.0000);
8059 assert_eq!(layout.children[0].x, 0.0000);
8060 assert_eq!(layout.children[0].y, 0.0000);
8061
8062 assert_eq!(layout.children[0].children[0].width, 100.0000);
8063 assert_eq!(layout.children[0].children[0].height, 20.0000);
8064 assert_eq!(layout.children[0].children[0].x, 0.0000);
8065 assert_eq!(layout.children[0].children[0].y, 0.0000);
8066 }
8067
8068 #[test]
8069 fn flex_grow_height_maximized() {
8070 let layout = stretch::compute(&stretch::style::Node {
8071 flex_direction: stretch::style::FlexDirection::Column,
8072 width: stretch::style::Dimension::Points(100.0000),
8073 height: stretch::style::Dimension::Points(500.0000),
8074 children: vec![stretch::style::Node {
8075 flex_direction: stretch::style::FlexDirection::Column,
8076 flex_grow: 1.0000,
8077 min_height: stretch::style::Dimension::Points(100.0000),
8078 max_height: stretch::style::Dimension::Points(500.0000),
8079 children: vec![
8080 stretch::style::Node {
8081 flex_grow: 1.0000,
8082 flex_basis: stretch::style::Dimension::Points(200.0000),
8083 ..Default::default()
8084 },
8085 stretch::style::Node { height: stretch::style::Dimension::Points(100.0000), ..Default::default() },
8086 ],
8087 ..Default::default()
8088 }],
8089 ..Default::default()
8090 });
8091
8092 assert_eq!(layout.width, 100.0000);
8093 assert_eq!(layout.height, 500.0000);
8094 assert_eq!(layout.x, 0.0000);
8095 assert_eq!(layout.y, 0.0000);
8096
8097 assert_eq!(layout.children[0].width, 100.0000);
8098 assert_eq!(layout.children[0].height, 500.0000);
8099 assert_eq!(layout.children[0].x, 0.0000);
8100 assert_eq!(layout.children[0].y, 0.0000);
8101
8102 assert_eq!(layout.children[0].children[0].width, 100.0000);
8103 assert_eq!(layout.children[0].children[0].height, 400.0000);
8104 assert_eq!(layout.children[0].children[0].x, 0.0000);
8105 assert_eq!(layout.children[0].children[0].y, 0.0000);
8106
8107 assert_eq!(layout.children[0].children[1].width, 100.0000);
8108 assert_eq!(layout.children[0].children[1].height, 100.0000);
8109 assert_eq!(layout.children[0].children[1].x, 0.0000);
8110 assert_eq!(layout.children[0].children[1].y, 400.0000);
8111 }
8112
8113 #[test]
8114 fn max_height_overrides_height() {
8115 let layout = stretch::compute(&stretch::style::Node {
8116 children: vec![stretch::style::Node {
8117 height: stretch::style::Dimension::Points(200.0000),
8118 max_height: stretch::style::Dimension::Points(100.0000),
8119 ..Default::default()
8120 }],
8121 ..Default::default()
8122 });
8123
8124 assert_eq!(layout.width, 0.0000);
8125 assert_eq!(layout.height, 100.0000);
8126 assert_eq!(layout.x, 0.0000);
8127 assert_eq!(layout.y, 0.0000);
8128
8129 assert_eq!(layout.children[0].width, 0.0000);
8130 assert_eq!(layout.children[0].height, 100.0000);
8131 assert_eq!(layout.children[0].x, 0.0000);
8132 assert_eq!(layout.children[0].y, 0.0000);
8133 }
8134
8135 #[test]
8136 fn justify_content_min_width_with_padding_child_width_greater_than_parent() {
8137 let layout = stretch::compute(&stretch::style::Node {
8138 flex_direction: stretch::style::FlexDirection::Column,
8139 width: stretch::style::Dimension::Points(1000.0000),
8140 height: stretch::style::Dimension::Points(1584.0000),
8141 children: vec![stretch::style::Node {
8142 children: vec![stretch::style::Node {
8143 justify_content: stretch::style::JustifyContent::Center,
8144 min_width: stretch::style::Dimension::Points(400.0000),
8145 padding: stretch::style::Edges {
8146 start: stretch::style::Dimension::Points(100.0000),
8147 end: stretch::style::Dimension::Points(100.0000),
8148 ..Default::default()
8149 },
8150 children: vec![stretch::style::Node {
8151 width: stretch::style::Dimension::Points(300.0000),
8152 height: stretch::style::Dimension::Points(100.0000),
8153 ..Default::default()
8154 }],
8155 ..Default::default()
8156 }],
8157 ..Default::default()
8158 }],
8159 ..Default::default()
8160 });
8161
8162 assert_eq!(layout.width, 1000.0000);
8163 assert_eq!(layout.height, 1584.0000);
8164 assert_eq!(layout.x, 0.0000);
8165 assert_eq!(layout.y, 0.0000);
8166
8167 assert_eq!(layout.children[0].width, 1000.0000);
8168 assert_eq!(layout.children[0].height, 100.0000);
8169 assert_eq!(layout.children[0].x, 0.0000);
8170 assert_eq!(layout.children[0].y, 0.0000);
8171
8172 assert_eq!(layout.children[0].children[0].width, 500.0000);
8173 assert_eq!(layout.children[0].children[0].height, 100.0000);
8174 assert_eq!(layout.children[0].children[0].x, 0.0000);
8175 assert_eq!(layout.children[0].children[0].y, 0.0000);
8176
8177 assert_eq!(layout.children[0].children[0].children[0].width, 300.0000);
8178 assert_eq!(layout.children[0].children[0].children[0].height, 100.0000);
8179 assert_eq!(layout.children[0].children[0].children[0].x, 100.0000);
8180 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
8181 }
8182
8183 #[test]
8184 fn flex_grow_flex_basis_percent_min_max() {
8185 let layout = stretch::compute(&stretch::style::Node {
8186 width: stretch::style::Dimension::Points(120.0000),
8187 children: vec![
8188 stretch::style::Node {
8189 flex_grow: 1.0000,
8190 flex_shrink: 0.0000,
8191 flex_basis: stretch::style::Dimension::Points(0.0000),
8192 min_width: stretch::style::Dimension::Points(60.0000),
8193 height: stretch::style::Dimension::Points(20.0000),
8194 ..Default::default()
8195 },
8196 stretch::style::Node {
8197 flex_grow: 1.0000,
8198 flex_shrink: 0.0000,
8199 flex_basis: stretch::style::Dimension::Percent(0.5000),
8200 width: stretch::style::Dimension::Points(20.0000),
8201 max_width: stretch::style::Dimension::Points(20.0000),
8202 height: stretch::style::Dimension::Points(20.0000),
8203 ..Default::default()
8204 },
8205 ],
8206 ..Default::default()
8207 });
8208
8209 assert_eq!(layout.width, 120.0000);
8210 assert_eq!(layout.height, 20.0000);
8211 assert_eq!(layout.x, 0.0000);
8212 assert_eq!(layout.y, 0.0000);
8213
8214 assert_eq!(layout.children[0].width, 100.0000);
8215 assert_eq!(layout.children[0].height, 20.0000);
8216 assert_eq!(layout.children[0].x, 0.0000);
8217 assert_eq!(layout.children[0].y, 0.0000);
8218
8219 assert_eq!(layout.children[1].width, 20.0000);
8220 assert_eq!(layout.children[1].height, 20.0000);
8221 assert_eq!(layout.children[1].x, 100.0000);
8222 assert_eq!(layout.children[1].y, 0.0000);
8223 }
8224
8225 #[test]
8226 fn percent_absolute_position() {
8227 let layout = stretch::compute(&stretch::style::Node {
8228 flex_direction: stretch::style::FlexDirection::Column,
8229 width: stretch::style::Dimension::Points(60.0000),
8230 height: stretch::style::Dimension::Points(50.0000),
8231 children: vec![stretch::style::Node {
8232 position: stretch::style::Position::Absolute,
8233 width: stretch::style::Dimension::Percent(1.0000),
8234 height: stretch::style::Dimension::Points(50.0000),
8235 start: stretch::style::Dimension::Percent(0.5000),
8236 children: vec![
8237 stretch::style::Node { width: stretch::style::Dimension::Percent(1.0000), ..Default::default() },
8238 stretch::style::Node { width: stretch::style::Dimension::Percent(1.0000), ..Default::default() },
8239 ],
8240 ..Default::default()
8241 }],
8242 ..Default::default()
8243 });
8244
8245 assert_eq!(layout.width, 60.0000);
8246 assert_eq!(layout.height, 50.0000);
8247 assert_eq!(layout.x, 0.0000);
8248 assert_eq!(layout.y, 0.0000);
8249
8250 assert_eq!(layout.children[0].width, 60.0000);
8251 assert_eq!(layout.children[0].height, 50.0000);
8252 assert_eq!(layout.children[0].x, 30.0000);
8253 assert_eq!(layout.children[0].y, 0.0000);
8254
8255 assert_eq!(layout.children[0].children[0].width, 30.0000);
8256 assert_eq!(layout.children[0].children[0].height, 50.0000);
8257 assert_eq!(layout.children[0].children[0].x, 0.0000);
8258 assert_eq!(layout.children[0].children[0].y, 0.0000);
8259
8260 assert_eq!(layout.children[0].children[1].width, 30.0000);
8261 assert_eq!(layout.children[0].children[1].height, 50.0000);
8262 assert_eq!(layout.children[0].children[1].x, 30.0000);
8263 assert_eq!(layout.children[0].children[1].y, 0.0000);
8264 }
8265
8266 #[test]
8267 fn flex_root_ignored() {
8268 let layout = stretch::compute(&stretch::style::Node {
8269 flex_direction: stretch::style::FlexDirection::Column,
8270 width: stretch::style::Dimension::Points(100.0000),
8271 min_height: stretch::style::Dimension::Points(100.0000),
8272 max_height: stretch::style::Dimension::Points(500.0000),
8273 children: vec![
8274 stretch::style::Node {
8275 flex_grow: 1.0000,
8276 flex_basis: stretch::style::Dimension::Points(200.0000),
8277 ..Default::default()
8278 },
8279 stretch::style::Node { height: stretch::style::Dimension::Points(100.0000), ..Default::default() },
8280 ],
8281 ..Default::default()
8282 });
8283
8284 assert_eq!(layout.width, 100.0000);
8285 assert_eq!(layout.height, 300.0000);
8286 assert_eq!(layout.x, 0.0000);
8287 assert_eq!(layout.y, 0.0000);
8288
8289 assert_eq!(layout.children[0].width, 100.0000);
8290 assert_eq!(layout.children[0].height, 200.0000);
8291 assert_eq!(layout.children[0].x, 0.0000);
8292 assert_eq!(layout.children[0].y, 0.0000);
8293
8294 assert_eq!(layout.children[1].width, 100.0000);
8295 assert_eq!(layout.children[1].height, 100.0000);
8296 assert_eq!(layout.children[1].x, 0.0000);
8297 assert_eq!(layout.children[1].y, 200.0000);
8298 }
8299
8300 #[test]
8301 fn justify_content_column_space_between() {
8302 let layout = stretch::compute(&stretch::style::Node {
8303 flex_direction: stretch::style::FlexDirection::Column,
8304 justify_content: stretch::style::JustifyContent::SpaceBetween,
8305 width: stretch::style::Dimension::Points(100.0000),
8306 height: stretch::style::Dimension::Points(100.0000),
8307 children: vec![
8308 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
8309 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
8310 stretch::style::Node { height: stretch::style::Dimension::Points(10.0000), ..Default::default() },
8311 ],
8312 ..Default::default()
8313 });
8314
8315 assert_eq!(layout.width, 100.0000);
8316 assert_eq!(layout.height, 100.0000);
8317 assert_eq!(layout.x, 0.0000);
8318 assert_eq!(layout.y, 0.0000);
8319
8320 assert_eq!(layout.children[0].width, 100.0000);
8321 assert_eq!(layout.children[0].height, 10.0000);
8322 assert_eq!(layout.children[0].x, 0.0000);
8323 assert_eq!(layout.children[0].y, 0.0000);
8324
8325 assert_eq!(layout.children[1].width, 100.0000);
8326 assert_eq!(layout.children[1].height, 10.0000);
8327 assert_eq!(layout.children[1].x, 0.0000);
8328 assert_eq!(layout.children[1].y, 45.0000);
8329
8330 assert_eq!(layout.children[2].width, 100.0000);
8331 assert_eq!(layout.children[2].height, 10.0000);
8332 assert_eq!(layout.children[2].x, 0.0000);
8333 assert_eq!(layout.children[2].y, 90.0000);
8334 }
8335
8336 #[test]
8337 fn flex_grow_within_constrained_max_width() {
8338 let layout = stretch::compute(&stretch::style::Node {
8339 flex_direction: stretch::style::FlexDirection::Column,
8340 width: stretch::style::Dimension::Points(200.0000),
8341 height: stretch::style::Dimension::Points(100.0000),
8342 children: vec![stretch::style::Node {
8343 max_width: stretch::style::Dimension::Points(300.0000),
8344 children: vec![stretch::style::Node {
8345 flex_grow: 1.0000,
8346 height: stretch::style::Dimension::Points(20.0000),
8347 ..Default::default()
8348 }],
8349 ..Default::default()
8350 }],
8351 ..Default::default()
8352 });
8353
8354 assert_eq!(layout.width, 200.0000);
8355 assert_eq!(layout.height, 100.0000);
8356 assert_eq!(layout.x, 0.0000);
8357 assert_eq!(layout.y, 0.0000);
8358
8359 assert_eq!(layout.children[0].width, 200.0000);
8360 assert_eq!(layout.children[0].height, 20.0000);
8361 assert_eq!(layout.children[0].x, 0.0000);
8362 assert_eq!(layout.children[0].y, 0.0000);
8363
8364 assert_eq!(layout.children[0].children[0].width, 200.0000);
8365 assert_eq!(layout.children[0].children[0].height, 20.0000);
8366 assert_eq!(layout.children[0].children[0].x, 0.0000);
8367 assert_eq!(layout.children[0].children[0].y, 0.0000);
8368 }
8369
8370 #[test]
8371 fn flex_basis_smaller_than_content_row() {
8372 let layout = stretch::compute(&stretch::style::Node {
8373 width: stretch::style::Dimension::Points(100.0000),
8374 children: vec![stretch::style::Node {
8375 flex_direction: stretch::style::FlexDirection::Column,
8376 flex_basis: stretch::style::Dimension::Points(50.0000),
8377 children: vec![stretch::style::Node {
8378 width: stretch::style::Dimension::Points(100.0000),
8379 height: stretch::style::Dimension::Points(100.0000),
8380 ..Default::default()
8381 }],
8382 ..Default::default()
8383 }],
8384 ..Default::default()
8385 });
8386
8387 assert_eq!(layout.width, 100.0000);
8388 assert_eq!(layout.height, 100.0000);
8389 assert_eq!(layout.x, 0.0000);
8390 assert_eq!(layout.y, 0.0000);
8391
8392 assert_eq!(layout.children[0].width, 100.0000);
8393 assert_eq!(layout.children[0].height, 100.0000);
8394 assert_eq!(layout.children[0].x, 0.0000);
8395 assert_eq!(layout.children[0].y, 0.0000);
8396
8397 assert_eq!(layout.children[0].children[0].width, 100.0000);
8398 assert_eq!(layout.children[0].children[0].height, 100.0000);
8399 assert_eq!(layout.children[0].children[0].x, 0.0000);
8400 assert_eq!(layout.children[0].children[0].y, 0.0000);
8401 }
8402
8403 #[test]
8404 fn max_width_overrides_width() {
8405 let layout = stretch::compute(&stretch::style::Node {
8406 children: vec![stretch::style::Node {
8407 width: stretch::style::Dimension::Points(200.0000),
8408 max_width: stretch::style::Dimension::Points(100.0000),
8409 ..Default::default()
8410 }],
8411 ..Default::default()
8412 });
8413
8414 assert_eq!(layout.width, 100.0000);
8415 assert_eq!(layout.height, 0.0000);
8416 assert_eq!(layout.x, 0.0000);
8417 assert_eq!(layout.y, 0.0000);
8418
8419 assert_eq!(layout.children[0].width, 100.0000);
8420 assert_eq!(layout.children[0].height, 0.0000);
8421 assert_eq!(layout.children[0].x, 0.0000);
8422 assert_eq!(layout.children[0].y, 0.0000);
8423 }
8424
8425 #[test]
8426 fn percentage_position_bottom_right() {
8427 let layout = stretch::compute(&stretch::style::Node {
8428 width: stretch::style::Dimension::Points(500.0000),
8429 height: stretch::style::Dimension::Points(500.0000),
8430 children: vec![stretch::style::Node {
8431 width: stretch::style::Dimension::Percent(0.5500),
8432 height: stretch::style::Dimension::Percent(0.1500),
8433 end: stretch::style::Dimension::Percent(0.2000),
8434 bottom: stretch::style::Dimension::Percent(0.1000),
8435 ..Default::default()
8436 }],
8437 ..Default::default()
8438 });
8439
8440 assert_eq!(layout.width, 500.0000);
8441 assert_eq!(layout.height, 500.0000);
8442 assert_eq!(layout.x, 0.0000);
8443 assert_eq!(layout.y, 0.0000);
8444
8445 assert_eq!(layout.children[0].width, 275.0000);
8446 assert_eq!(layout.children[0].height, 75.0000);
8447 assert_eq!(layout.children[0].x, -100.0000);
8448 assert_eq!(layout.children[0].y, -50.0000);
8449 }
8450
8451 #[test]
8452 fn margin_auto_top_stretching_child() {
8453 let layout = stretch::compute(&stretch::style::Node {
8454 align_items: stretch::style::AlignItems::Center,
8455 width: stretch::style::Dimension::Points(200.0000),
8456 height: stretch::style::Dimension::Points(200.0000),
8457 children: vec![
8458 stretch::style::Node {
8459 flex_grow: 1.0000,
8460 flex_shrink: 1.0000,
8461 flex_basis: stretch::style::Dimension::Percent(0.0000),
8462 margin: stretch::style::Edges { top: stretch::style::Dimension::Auto, ..Default::default() },
8463 ..Default::default()
8464 },
8465 stretch::style::Node {
8466 width: stretch::style::Dimension::Points(50.0000),
8467 height: stretch::style::Dimension::Points(50.0000),
8468 ..Default::default()
8469 },
8470 ],
8471 ..Default::default()
8472 });
8473
8474 assert_eq!(layout.width, 200.0000);
8475 assert_eq!(layout.height, 200.0000);
8476 assert_eq!(layout.x, 0.0000);
8477 assert_eq!(layout.y, 0.0000);
8478
8479 assert_eq!(layout.children[0].width, 150.0000);
8480 assert_eq!(layout.children[0].height, 0.0000);
8481 assert_eq!(layout.children[0].x, 0.0000);
8482 assert_eq!(layout.children[0].y, 200.0000);
8483
8484 assert_eq!(layout.children[1].width, 50.0000);
8485 assert_eq!(layout.children[1].height, 50.0000);
8486 assert_eq!(layout.children[1].x, 150.0000);
8487 assert_eq!(layout.children[1].y, 75.0000);
8488 }
8489
8490 #[test]
8491 fn align_flex_start_with_shrinking_children() {
8492 let layout = stretch::compute(&stretch::style::Node {
8493 width: stretch::style::Dimension::Points(500.0000),
8494 height: stretch::style::Dimension::Points(500.0000),
8495 children: vec![stretch::style::Node {
8496 align_items: stretch::style::AlignItems::FlexStart,
8497 children: vec![stretch::style::Node {
8498 flex_grow: 1.0000,
8499 flex_shrink: 1.0000,
8500 children: vec![stretch::style::Node {
8501 flex_grow: 1.0000,
8502 flex_shrink: 1.0000,
8503 ..Default::default()
8504 }],
8505 ..Default::default()
8506 }],
8507 ..Default::default()
8508 }],
8509 ..Default::default()
8510 });
8511
8512 assert_eq!(layout.width, 500.0000);
8513 assert_eq!(layout.height, 500.0000);
8514 assert_eq!(layout.x, 0.0000);
8515 assert_eq!(layout.y, 0.0000);
8516
8517 assert_eq!(layout.children[0].width, 0.0000);
8518 assert_eq!(layout.children[0].height, 500.0000);
8519 assert_eq!(layout.children[0].x, 0.0000);
8520 assert_eq!(layout.children[0].y, 0.0000);
8521
8522 assert_eq!(layout.children[0].children[0].width, 0.0000);
8523 assert_eq!(layout.children[0].children[0].height, 0.0000);
8524 assert_eq!(layout.children[0].children[0].x, 0.0000);
8525 assert_eq!(layout.children[0].children[0].y, 0.0000);
8526
8527 assert_eq!(layout.children[0].children[0].children[0].width, 0.0000);
8528 assert_eq!(layout.children[0].children[0].children[0].height, 0.0000);
8529 assert_eq!(layout.children[0].children[0].children[0].x, 0.0000);
8530 assert_eq!(layout.children[0].children[0].children[0].y, 0.0000);
8531 }
8532
8533 #[test]
8534 fn justify_content_column_min_height_and_margin_bottom() {
8535 let layout = stretch::compute(&stretch::style::Node {
8536 flex_direction: stretch::style::FlexDirection::Column,
8537 justify_content: stretch::style::JustifyContent::Center,
8538 min_height: stretch::style::Dimension::Points(50.0000),
8539 children: vec![stretch::style::Node {
8540 width: stretch::style::Dimension::Points(20.0000),
8541 height: stretch::style::Dimension::Points(20.0000),
8542 margin: stretch::style::Edges {
8543 bottom: stretch::style::Dimension::Points(10.0000),
8544 ..Default::default()
8545 },
8546 ..Default::default()
8547 }],
8548 ..Default::default()
8549 });
8550
8551 assert_eq!(layout.width, 20.0000);
8552 assert_eq!(layout.height, 50.0000);
8553 assert_eq!(layout.x, 0.0000);
8554 assert_eq!(layout.y, 0.0000);
8555
8556 assert_eq!(layout.children[0].width, 20.0000);
8557 assert_eq!(layout.children[0].height, 20.0000);
8558 assert_eq!(layout.children[0].x, 0.0000);
8559 assert_eq!(layout.children[0].y, 10.0000);
8560 }
8561
8562}