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