1#[test]
2fn wrap_row() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Points(31f32),
11 height: taffy::style::Dimension::Points(30f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node1 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::Points(32f32),
20 height: taffy::style::Dimension::Points(30f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node2 = taffy
26 .new_leaf(taffy::style::Style {
27 size: taffy::geometry::Size {
28 width: taffy::style::Dimension::Points(33f32),
29 height: taffy::style::Dimension::Points(30f32),
30 },
31 ..Default::default()
32 })
33 .unwrap();
34 let node3 = taffy
35 .new_leaf(taffy::style::Style {
36 size: taffy::geometry::Size {
37 width: taffy::style::Dimension::Points(34f32),
38 height: taffy::style::Dimension::Points(30f32),
39 },
40 ..Default::default()
41 })
42 .unwrap();
43 let node = taffy
44 .new_with_children(
45 taffy::style::Style {
46 flex_wrap: taffy::style::FlexWrap::Wrap,
47 size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: auto() },
48 ..Default::default()
49 },
50 &[node0, node1, node2, node3],
51 )
52 .unwrap();
53 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
54 println!("\nComputed tree:");
55 taffy::debug::print_tree(&taffy, node);
56 println!();
57 let Layout { size, location, .. } = taffy.layout(node).unwrap();
58 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
59 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 60f32, size.height);
60 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
61 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
62 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
63 assert_eq!(size.width, 31f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 31f32, size.width);
64 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, size.height);
65 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
66 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
67 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
68 assert_eq!(size.width, 32f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 32f32, size.width);
69 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 30f32, size.height);
70 assert_eq!(location.x, 31f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 31f32, location.x);
71 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
72 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
73 assert_eq!(size.width, 33f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 33f32, size.width);
74 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 30f32, size.height);
75 assert_eq!(location.x, 63f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 63f32, location.x);
76 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
77 let Layout { size, location, .. } = taffy.layout(node3).unwrap();
78 assert_eq!(size.width, 34f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 34f32, size.width);
79 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, size.height);
80 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 0f32, location.x);
81 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, location.y);
82}