Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn block_margin_auto_top__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::from_length(50f32),
11 height: taffy::style::Dimension::from_length(50f32),
12 },
13 margin: taffy::geometry::Rect {
14 left: zero(),
15 right: zero(),
16 top: taffy::style::LengthPercentageAuto::AUTO,
17 bottom: zero(),
18 },
19 ..Default::default()
20 })
21 .unwrap();
22 let node1 = taffy
23 .new_leaf(taffy::style::Style {
24 size: taffy::geometry::Size {
25 width: taffy::style::Dimension::from_length(50f32),
26 height: taffy::style::Dimension::from_length(50f32),
27 },
28 ..Default::default()
29 })
30 .unwrap();
31 let node = taffy
32 .new_with_children(
33 taffy::style::Style {
34 display: taffy::style::Display::Block,
35 align_items: Some(taffy::style::AlignItems::Center),
36 size: taffy::geometry::Size {
37 width: taffy::style::Dimension::from_length(200f32),
38 height: taffy::style::Dimension::from_length(200f32),
39 },
40 ..Default::default()
41 },
42 &[node0, node1],
43 )
44 .unwrap();
45 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
46 println!("\nComputed tree:");
47 taffy.print_tree(node);
48 println!();
49 let layout = taffy.layout(node).unwrap();
50 let Layout { size, location, .. } = layout;
51 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
52 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
53 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
54 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
55 let layout = taffy.layout(node0).unwrap();
56 let Layout { size, location, .. } = layout;
57 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
58 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
59 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
60 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
61 let layout = taffy.layout(node1).unwrap();
62 let Layout { size, location, .. } = layout;
63 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
64 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
65 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
66 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
67}
68
69#[test]
70#[allow(non_snake_case)]
71fn block_margin_auto_top__content_box() {
72 #[allow(unused_imports)]
73 use taffy::{prelude::*, Layout};
74 let mut taffy = crate::new_test_tree();
75 let node0 = taffy
76 .new_leaf(taffy::style::Style {
77 box_sizing: taffy::style::BoxSizing::ContentBox,
78 size: taffy::geometry::Size {
79 width: taffy::style::Dimension::from_length(50f32),
80 height: taffy::style::Dimension::from_length(50f32),
81 },
82 margin: taffy::geometry::Rect {
83 left: zero(),
84 right: zero(),
85 top: taffy::style::LengthPercentageAuto::AUTO,
86 bottom: zero(),
87 },
88 ..Default::default()
89 })
90 .unwrap();
91 let node1 = taffy
92 .new_leaf(taffy::style::Style {
93 box_sizing: taffy::style::BoxSizing::ContentBox,
94 size: taffy::geometry::Size {
95 width: taffy::style::Dimension::from_length(50f32),
96 height: taffy::style::Dimension::from_length(50f32),
97 },
98 ..Default::default()
99 })
100 .unwrap();
101 let node = taffy
102 .new_with_children(
103 taffy::style::Style {
104 display: taffy::style::Display::Block,
105 box_sizing: taffy::style::BoxSizing::ContentBox,
106 align_items: Some(taffy::style::AlignItems::Center),
107 size: taffy::geometry::Size {
108 width: taffy::style::Dimension::from_length(200f32),
109 height: taffy::style::Dimension::from_length(200f32),
110 },
111 ..Default::default()
112 },
113 &[node0, node1],
114 )
115 .unwrap();
116 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
117 println!("\nComputed tree:");
118 taffy.print_tree(node);
119 println!();
120 let layout = taffy.layout(node).unwrap();
121 let Layout { size, location, .. } = layout;
122 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
123 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
124 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
125 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
126 let layout = taffy.layout(node0).unwrap();
127 let Layout { size, location, .. } = layout;
128 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
129 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
130 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
131 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
132 let layout = taffy.layout(node1).unwrap();
133 let Layout { size, location, .. } = layout;
134 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
135 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
136 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
137 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
138}