Rename PositionType and Position in accordance to specs (#295)
1#[test]
2fn rounding_total_fractial_nested() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node00 = taffy
8 .new_leaf(taffy::style::Style {
9 flex_grow: 1f32,
10 flex_basis: taffy::style::Dimension::Points(0.3f32),
11 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(9.9f32) },
12 inset: taffy::geometry::Rect {
13 left: auto(),
14 right: auto(),
15 top: auto(),
16 bottom: taffy::style::LengthPercentageAuto::Points(13.3f32),
17 },
18 ..Default::default()
19 })
20 .unwrap();
21 let node01 = taffy
22 .new_leaf(taffy::style::Style {
23 flex_grow: 4f32,
24 flex_basis: taffy::style::Dimension::Points(0.3f32),
25 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(1.1f32) },
26 inset: taffy::geometry::Rect {
27 left: auto(),
28 right: auto(),
29 top: taffy::style::LengthPercentageAuto::Points(13.3f32),
30 bottom: auto(),
31 },
32 ..Default::default()
33 })
34 .unwrap();
35 let node0 = taffy
36 .new_with_children(
37 taffy::style::Style {
38 flex_direction: taffy::style::FlexDirection::Column,
39 flex_grow: 0.7f32,
40 flex_basis: taffy::style::Dimension::Points(50.3f32),
41 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20.3f32) },
42 ..Default::default()
43 },
44 &[node00, node01],
45 )
46 .unwrap();
47 let node1 = taffy
48 .new_leaf(taffy::style::Style {
49 flex_grow: 1.6f32,
50 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(10f32) },
51 ..Default::default()
52 })
53 .unwrap();
54 let node2 = taffy
55 .new_leaf(taffy::style::Style {
56 flex_grow: 1.1f32,
57 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(10.7f32) },
58 ..Default::default()
59 })
60 .unwrap();
61 let node = taffy
62 .new_with_children(
63 taffy::style::Style {
64 flex_direction: taffy::style::FlexDirection::Column,
65 size: taffy::geometry::Size {
66 width: taffy::style::Dimension::Points(87.4f32),
67 height: taffy::style::Dimension::Points(113.4f32),
68 },
69 ..Default::default()
70 },
71 &[node0, node1, node2],
72 )
73 .unwrap();
74 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
75 println!("\nComputed tree:");
76 taffy::debug::print_tree(&taffy, node);
77 println!();
78 let Layout { size, location, .. } = taffy.layout(node).unwrap();
79 assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 87f32, size.width);
80 assert_eq!(size.height, 113f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 113f32, size.height);
81 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
82 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
83 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
84 assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 87f32, size.width);
85 assert_eq!(size.height, 59f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 59f32, size.height);
86 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
87 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
88 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
89 assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 87f32, size.width);
90 assert_eq!(size.height, 12f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 12f32, size.height);
91 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
92 assert_eq!(location.y, -13f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), -13f32, location.y);
93 let Layout { size, location, .. } = taffy.layout(node01).unwrap();
94 assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 87f32, size.width);
95 assert_eq!(size.height, 47f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 47f32, size.height);
96 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.x);
97 assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 25f32, location.y);
98 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
99 assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 87f32, size.width);
100 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 30f32, size.height);
101 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
102 assert_eq!(location.y, 59f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 59f32, location.y);
103 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
104 assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 87f32, size.width);
105 assert_eq!(size.height, 24f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 24f32, size.height);
106 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.x);
107 assert_eq!(location.y, 89f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 89f32, location.y);
108}