Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn flex_grow_0_min_size__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_with_context(
9 taffy::style::Style {
10 flex_grow: 0f32,
11 flex_shrink: 0f32,
12 flex_basis: taffy::style::Dimension::from_percent(0f32),
13 ..Default::default()
14 },
15 crate::TestNodeContext::ahem_text("one", crate::WritingMode::Horizontal),
16 )
17 .unwrap();
18 let node1 = taffy
19 .new_leaf_with_context(
20 taffy::style::Style {
21 flex_grow: 0f32,
22 flex_shrink: 0f32,
23 flex_basis: taffy::style::Dimension::from_percent(0f32),
24 ..Default::default()
25 },
26 crate::TestNodeContext::ahem_text("two", crate::WritingMode::Horizontal),
27 )
28 .unwrap();
29 let node2 = taffy
30 .new_leaf_with_context(
31 taffy::style::Style {
32 flex_grow: 0f32,
33 flex_shrink: 0f32,
34 flex_basis: taffy::style::Dimension::from_percent(0f32),
35 ..Default::default()
36 },
37 crate::TestNodeContext::ahem_text("three", crate::WritingMode::Horizontal),
38 )
39 .unwrap();
40 let node3 = taffy
41 .new_leaf_with_context(
42 taffy::style::Style {
43 flex_grow: 0f32,
44 flex_shrink: 0f32,
45 flex_basis: taffy::style::Dimension::from_percent(0f32),
46 ..Default::default()
47 },
48 crate::TestNodeContext::ahem_text("four", crate::WritingMode::Horizontal),
49 )
50 .unwrap();
51 let node = taffy
52 .new_with_children(
53 taffy::style::Style {
54 display: taffy::style::Display::Flex,
55 size: taffy::geometry::Size {
56 width: taffy::style::Dimension::from_length(400f32),
57 height: taffy::style::Dimension::from_length(100f32),
58 },
59 border: taffy::geometry::Rect {
60 left: length(1f32),
61 right: length(1f32),
62 top: length(1f32),
63 bottom: length(1f32),
64 },
65 ..Default::default()
66 },
67 &[node0, node1, node2, node3],
68 )
69 .unwrap();
70 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
71 println!("\nComputed tree:");
72 taffy.print_tree(node);
73 println!();
74 let layout = taffy.layout(node).unwrap();
75 let Layout { size, location, .. } = layout;
76 assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node, 400f32, size.width);
77 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
78 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
79 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
80 let layout = taffy.layout(node0).unwrap();
81 let Layout { size, location, .. } = layout;
82 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width);
83 assert_eq!(size.height, 98f32, "height of node {:?}. Expected {}. Actual {}", node0, 98f32, size.height);
84 assert_eq!(location.x, 1f32, "x of node {:?}. Expected {}. Actual {}", node0, 1f32, location.x);
85 assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node0, 1f32, location.y);
86 let layout = taffy.layout(node1).unwrap();
87 let Layout { size, location, .. } = layout;
88 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width);
89 assert_eq!(size.height, 98f32, "height of node {:?}. Expected {}. Actual {}", node1, 98f32, size.height);
90 assert_eq!(location.x, 31f32, "x of node {:?}. Expected {}. Actual {}", node1, 31f32, location.x);
91 assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node1, 1f32, location.y);
92 let layout = taffy.layout(node2).unwrap();
93 let Layout { size, location, .. } = layout;
94 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
95 assert_eq!(size.height, 98f32, "height of node {:?}. Expected {}. Actual {}", node2, 98f32, size.height);
96 assert_eq!(location.x, 61f32, "x of node {:?}. Expected {}. Actual {}", node2, 61f32, location.x);
97 assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node2, 1f32, location.y);
98 let layout = taffy.layout(node3).unwrap();
99 let Layout { size, location, .. } = layout;
100 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
101 assert_eq!(size.height, 98f32, "height of node {:?}. Expected {}. Actual {}", node3, 98f32, size.height);
102 assert_eq!(location.x, 111f32, "x of node {:?}. Expected {}. Actual {}", node3, 111f32, location.x);
103 assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node3, 1f32, location.y);
104}
105
106#[test]
107#[allow(non_snake_case)]
108fn flex_grow_0_min_size__content_box() {
109 #[allow(unused_imports)]
110 use taffy::{prelude::*, Layout};
111 let mut taffy = crate::new_test_tree();
112 let node0 = taffy
113 .new_leaf_with_context(
114 taffy::style::Style {
115 box_sizing: taffy::style::BoxSizing::ContentBox,
116 flex_grow: 0f32,
117 flex_shrink: 0f32,
118 flex_basis: taffy::style::Dimension::from_percent(0f32),
119 ..Default::default()
120 },
121 crate::TestNodeContext::ahem_text("one", crate::WritingMode::Horizontal),
122 )
123 .unwrap();
124 let node1 = taffy
125 .new_leaf_with_context(
126 taffy::style::Style {
127 box_sizing: taffy::style::BoxSizing::ContentBox,
128 flex_grow: 0f32,
129 flex_shrink: 0f32,
130 flex_basis: taffy::style::Dimension::from_percent(0f32),
131 ..Default::default()
132 },
133 crate::TestNodeContext::ahem_text("two", crate::WritingMode::Horizontal),
134 )
135 .unwrap();
136 let node2 = taffy
137 .new_leaf_with_context(
138 taffy::style::Style {
139 box_sizing: taffy::style::BoxSizing::ContentBox,
140 flex_grow: 0f32,
141 flex_shrink: 0f32,
142 flex_basis: taffy::style::Dimension::from_percent(0f32),
143 ..Default::default()
144 },
145 crate::TestNodeContext::ahem_text("three", crate::WritingMode::Horizontal),
146 )
147 .unwrap();
148 let node3 = taffy
149 .new_leaf_with_context(
150 taffy::style::Style {
151 box_sizing: taffy::style::BoxSizing::ContentBox,
152 flex_grow: 0f32,
153 flex_shrink: 0f32,
154 flex_basis: taffy::style::Dimension::from_percent(0f32),
155 ..Default::default()
156 },
157 crate::TestNodeContext::ahem_text("four", crate::WritingMode::Horizontal),
158 )
159 .unwrap();
160 let node = taffy
161 .new_with_children(
162 taffy::style::Style {
163 display: taffy::style::Display::Flex,
164 box_sizing: taffy::style::BoxSizing::ContentBox,
165 size: taffy::geometry::Size {
166 width: taffy::style::Dimension::from_length(400f32),
167 height: taffy::style::Dimension::from_length(100f32),
168 },
169 border: taffy::geometry::Rect {
170 left: length(1f32),
171 right: length(1f32),
172 top: length(1f32),
173 bottom: length(1f32),
174 },
175 ..Default::default()
176 },
177 &[node0, node1, node2, node3],
178 )
179 .unwrap();
180 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
181 println!("\nComputed tree:");
182 taffy.print_tree(node);
183 println!();
184 let layout = taffy.layout(node).unwrap();
185 let Layout { size, location, .. } = layout;
186 assert_eq!(size.width, 402f32, "width of node {:?}. Expected {}. Actual {}", node, 402f32, size.width);
187 assert_eq!(size.height, 102f32, "height of node {:?}. Expected {}. Actual {}", node, 102f32, size.height);
188 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
189 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
190 let layout = taffy.layout(node0).unwrap();
191 let Layout { size, location, .. } = layout;
192 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width);
193 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
194 assert_eq!(location.x, 1f32, "x of node {:?}. Expected {}. Actual {}", node0, 1f32, location.x);
195 assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node0, 1f32, location.y);
196 let layout = taffy.layout(node1).unwrap();
197 let Layout { size, location, .. } = layout;
198 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width);
199 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
200 assert_eq!(location.x, 31f32, "x of node {:?}. Expected {}. Actual {}", node1, 31f32, location.x);
201 assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node1, 1f32, location.y);
202 let layout = taffy.layout(node2).unwrap();
203 let Layout { size, location, .. } = layout;
204 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
205 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
206 assert_eq!(location.x, 61f32, "x of node {:?}. Expected {}. Actual {}", node2, 61f32, location.x);
207 assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node2, 1f32, location.y);
208 let layout = taffy.layout(node3).unwrap();
209 let Layout { size, location, .. } = layout;
210 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
211 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node3, 100f32, size.height);
212 assert_eq!(location.x, 111f32, "x of node {:?}. Expected {}. Actual {}", node3, 111f32, location.x);
213 assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node3, 1f32, location.y);
214}