Rename PositionType and Position in accordance to specs (#295)
1#[test]
2fn absolute_layout_child_order() {
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(60f32),
11 height: taffy::style::Dimension::Points(40f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node1 = taffy
17 .new_leaf(taffy::style::Style {
18 position: taffy::style::Position::Absolute,
19 size: taffy::geometry::Size {
20 width: taffy::style::Dimension::Points(60f32),
21 height: taffy::style::Dimension::Points(40f32),
22 },
23 ..Default::default()
24 })
25 .unwrap();
26 let node2 = taffy
27 .new_leaf(taffy::style::Style {
28 size: taffy::geometry::Size {
29 width: taffy::style::Dimension::Points(60f32),
30 height: taffy::style::Dimension::Points(40f32),
31 },
32 ..Default::default()
33 })
34 .unwrap();
35 let node = taffy
36 .new_with_children(
37 taffy::style::Style {
38 align_items: Some(taffy::style::AlignItems::Center),
39 justify_content: Some(taffy::style::JustifyContent::Center),
40 size: taffy::geometry::Size {
41 width: taffy::style::Dimension::Points(110f32),
42 height: taffy::style::Dimension::Points(100f32),
43 },
44 ..Default::default()
45 },
46 &[node0, node1, node2],
47 )
48 .unwrap();
49 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
50 println!("\nComputed tree:");
51 taffy::debug::print_tree(&taffy, node);
52 println!();
53 let Layout { size, location, .. } = taffy.layout(node).unwrap();
54 assert_eq!(size.width, 110f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 110f32, size.width);
55 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
56 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
57 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
58 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
59 assert_eq!(size.width, 55f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 55f32, size.width);
60 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height);
61 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
62 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, location.y);
63 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
64 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, size.width);
65 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.height);
66 assert_eq!(location.x, 25f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 25f32, location.x);
67 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 30f32, location.y);
68 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
69 assert_eq!(size.width, 55f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 55f32, size.width);
70 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 40f32, size.height);
71 assert_eq!(location.x, 55f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 55f32, location.x);
72 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 30f32, location.y);
73}