Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn grid_align_self_sized_all__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 align_self: Some(taffy::style::AlignSelf::Start),
10 size: taffy::geometry::Size {
11 width: taffy::style::Dimension::from_length(20f32),
12 height: taffy::style::Dimension::from_length(20f32),
13 },
14 ..Default::default()
15 })
16 .unwrap();
17 let node1 = taffy
18 .new_leaf(taffy::style::Style {
19 align_self: Some(taffy::style::AlignSelf::Start),
20 size: taffy::geometry::Size {
21 width: taffy::style::Dimension::from_length(60f32),
22 height: taffy::style::Dimension::from_length(60f32),
23 },
24 ..Default::default()
25 })
26 .unwrap();
27 let node2 = taffy
28 .new_leaf(taffy::style::Style {
29 align_self: Some(taffy::style::AlignSelf::End),
30 size: taffy::geometry::Size {
31 width: taffy::style::Dimension::from_length(20f32),
32 height: taffy::style::Dimension::from_length(20f32),
33 },
34 ..Default::default()
35 })
36 .unwrap();
37 let node3 = taffy
38 .new_leaf(taffy::style::Style {
39 align_self: Some(taffy::style::AlignSelf::End),
40 size: taffy::geometry::Size {
41 width: taffy::style::Dimension::from_length(60f32),
42 height: taffy::style::Dimension::from_length(60f32),
43 },
44 ..Default::default()
45 })
46 .unwrap();
47 let node4 = taffy
48 .new_leaf(taffy::style::Style {
49 align_self: Some(taffy::style::AlignSelf::Center),
50 size: taffy::geometry::Size {
51 width: taffy::style::Dimension::from_length(20f32),
52 height: taffy::style::Dimension::from_length(20f32),
53 },
54 ..Default::default()
55 })
56 .unwrap();
57 let node5 = taffy
58 .new_leaf(taffy::style::Style {
59 align_self: Some(taffy::style::AlignSelf::Center),
60 size: taffy::geometry::Size {
61 width: taffy::style::Dimension::from_length(60f32),
62 height: taffy::style::Dimension::from_length(60f32),
63 },
64 ..Default::default()
65 })
66 .unwrap();
67 let node6 = taffy
68 .new_leaf(taffy::style::Style {
69 align_self: Some(taffy::style::AlignSelf::Stretch),
70 size: taffy::geometry::Size {
71 width: taffy::style::Dimension::from_length(20f32),
72 height: taffy::style::Dimension::from_length(20f32),
73 },
74 ..Default::default()
75 })
76 .unwrap();
77 let node7 = taffy
78 .new_leaf(taffy::style::Style {
79 align_self: Some(taffy::style::AlignSelf::Stretch),
80 size: taffy::geometry::Size {
81 width: taffy::style::Dimension::from_length(60f32),
82 height: taffy::style::Dimension::from_length(60f32),
83 },
84 ..Default::default()
85 })
86 .unwrap();
87 let node = taffy
88 .new_with_children(
89 taffy::style::Style {
90 display: taffy::style::Display::Grid,
91 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
92 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
93 size: taffy::geometry::Size {
94 width: taffy::style::Dimension::from_length(120f32),
95 height: taffy::style::Dimension::from_length(120f32),
96 },
97 ..Default::default()
98 },
99 &[node0, node1, node2, node3, node4, node5, node6, node7],
100 )
101 .unwrap();
102 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
103 println!("\nComputed tree:");
104 taffy.print_tree(node);
105 println!();
106 let layout = taffy.layout(node).unwrap();
107 let Layout { size, location, .. } = layout;
108 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
109 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
110 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
111 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
112 let layout = taffy.layout(node0).unwrap();
113 let Layout { size, location, .. } = layout;
114 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
115 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
116 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
117 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
118 let layout = taffy.layout(node1).unwrap();
119 let Layout { size, location, .. } = layout;
120 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1, 60f32, size.width);
121 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node1, 60f32, size.height);
122 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
123 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
124 let layout = taffy.layout(node2).unwrap();
125 let Layout { size, location, .. } = layout;
126 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
127 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
128 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node2, 80f32, location.x);
129 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2, 20f32, location.y);
130 let layout = taffy.layout(node3).unwrap();
131 let Layout { size, location, .. } = layout;
132 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node3, 60f32, size.width);
133 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node3, 60f32, size.height);
134 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
135 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node3, 20f32, location.y);
136 let layout = taffy.layout(node4).unwrap();
137 let Layout { size, location, .. } = layout;
138 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
139 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4, 20f32, size.height);
140 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node4, 40f32, location.x);
141 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node4, 50f32, location.y);
142 let layout = taffy.layout(node5).unwrap();
143 let Layout { size, location, .. } = layout;
144 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node5, 60f32, size.width);
145 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node5, 60f32, size.height);
146 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node5, 80f32, location.x);
147 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node5, 30f32, location.y);
148 let layout = taffy.layout(node6).unwrap();
149 let Layout { size, location, .. } = layout;
150 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6, 20f32, size.width);
151 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6, 20f32, size.height);
152 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
153 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, location.y);
154 let layout = taffy.layout(node7).unwrap();
155 let Layout { size, location, .. } = layout;
156 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node7, 60f32, size.width);
157 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node7, 60f32, size.height);
158 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7, 40f32, location.x);
159 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, location.y);
160}
161
162#[test]
163#[allow(non_snake_case)]
164fn grid_align_self_sized_all__content_box() {
165 #[allow(unused_imports)]
166 use taffy::{prelude::*, Layout};
167 let mut taffy = crate::new_test_tree();
168 let node0 = taffy
169 .new_leaf(taffy::style::Style {
170 box_sizing: taffy::style::BoxSizing::ContentBox,
171 align_self: Some(taffy::style::AlignSelf::Start),
172 size: taffy::geometry::Size {
173 width: taffy::style::Dimension::from_length(20f32),
174 height: taffy::style::Dimension::from_length(20f32),
175 },
176 ..Default::default()
177 })
178 .unwrap();
179 let node1 = taffy
180 .new_leaf(taffy::style::Style {
181 box_sizing: taffy::style::BoxSizing::ContentBox,
182 align_self: Some(taffy::style::AlignSelf::Start),
183 size: taffy::geometry::Size {
184 width: taffy::style::Dimension::from_length(60f32),
185 height: taffy::style::Dimension::from_length(60f32),
186 },
187 ..Default::default()
188 })
189 .unwrap();
190 let node2 = taffy
191 .new_leaf(taffy::style::Style {
192 box_sizing: taffy::style::BoxSizing::ContentBox,
193 align_self: Some(taffy::style::AlignSelf::End),
194 size: taffy::geometry::Size {
195 width: taffy::style::Dimension::from_length(20f32),
196 height: taffy::style::Dimension::from_length(20f32),
197 },
198 ..Default::default()
199 })
200 .unwrap();
201 let node3 = taffy
202 .new_leaf(taffy::style::Style {
203 box_sizing: taffy::style::BoxSizing::ContentBox,
204 align_self: Some(taffy::style::AlignSelf::End),
205 size: taffy::geometry::Size {
206 width: taffy::style::Dimension::from_length(60f32),
207 height: taffy::style::Dimension::from_length(60f32),
208 },
209 ..Default::default()
210 })
211 .unwrap();
212 let node4 = taffy
213 .new_leaf(taffy::style::Style {
214 box_sizing: taffy::style::BoxSizing::ContentBox,
215 align_self: Some(taffy::style::AlignSelf::Center),
216 size: taffy::geometry::Size {
217 width: taffy::style::Dimension::from_length(20f32),
218 height: taffy::style::Dimension::from_length(20f32),
219 },
220 ..Default::default()
221 })
222 .unwrap();
223 let node5 = taffy
224 .new_leaf(taffy::style::Style {
225 box_sizing: taffy::style::BoxSizing::ContentBox,
226 align_self: Some(taffy::style::AlignSelf::Center),
227 size: taffy::geometry::Size {
228 width: taffy::style::Dimension::from_length(60f32),
229 height: taffy::style::Dimension::from_length(60f32),
230 },
231 ..Default::default()
232 })
233 .unwrap();
234 let node6 = taffy
235 .new_leaf(taffy::style::Style {
236 box_sizing: taffy::style::BoxSizing::ContentBox,
237 align_self: Some(taffy::style::AlignSelf::Stretch),
238 size: taffy::geometry::Size {
239 width: taffy::style::Dimension::from_length(20f32),
240 height: taffy::style::Dimension::from_length(20f32),
241 },
242 ..Default::default()
243 })
244 .unwrap();
245 let node7 = taffy
246 .new_leaf(taffy::style::Style {
247 box_sizing: taffy::style::BoxSizing::ContentBox,
248 align_self: Some(taffy::style::AlignSelf::Stretch),
249 size: taffy::geometry::Size {
250 width: taffy::style::Dimension::from_length(60f32),
251 height: taffy::style::Dimension::from_length(60f32),
252 },
253 ..Default::default()
254 })
255 .unwrap();
256 let node = taffy
257 .new_with_children(
258 taffy::style::Style {
259 display: taffy::style::Display::Grid,
260 box_sizing: taffy::style::BoxSizing::ContentBox,
261 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
262 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
263 size: taffy::geometry::Size {
264 width: taffy::style::Dimension::from_length(120f32),
265 height: taffy::style::Dimension::from_length(120f32),
266 },
267 ..Default::default()
268 },
269 &[node0, node1, node2, node3, node4, node5, node6, node7],
270 )
271 .unwrap();
272 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
273 println!("\nComputed tree:");
274 taffy.print_tree(node);
275 println!();
276 let layout = taffy.layout(node).unwrap();
277 let Layout { size, location, .. } = layout;
278 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
279 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
280 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
281 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
282 let layout = taffy.layout(node0).unwrap();
283 let Layout { size, location, .. } = layout;
284 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
285 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
286 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
287 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
288 let layout = taffy.layout(node1).unwrap();
289 let Layout { size, location, .. } = layout;
290 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1, 60f32, size.width);
291 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node1, 60f32, size.height);
292 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
293 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
294 let layout = taffy.layout(node2).unwrap();
295 let Layout { size, location, .. } = layout;
296 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
297 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
298 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node2, 80f32, location.x);
299 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2, 20f32, location.y);
300 let layout = taffy.layout(node3).unwrap();
301 let Layout { size, location, .. } = layout;
302 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node3, 60f32, size.width);
303 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node3, 60f32, size.height);
304 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
305 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node3, 20f32, location.y);
306 let layout = taffy.layout(node4).unwrap();
307 let Layout { size, location, .. } = layout;
308 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
309 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4, 20f32, size.height);
310 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node4, 40f32, location.x);
311 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node4, 50f32, location.y);
312 let layout = taffy.layout(node5).unwrap();
313 let Layout { size, location, .. } = layout;
314 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node5, 60f32, size.width);
315 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node5, 60f32, size.height);
316 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node5, 80f32, location.x);
317 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node5, 30f32, location.y);
318 let layout = taffy.layout(node6).unwrap();
319 let Layout { size, location, .. } = layout;
320 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6, 20f32, size.width);
321 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6, 20f32, size.height);
322 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
323 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, location.y);
324 let layout = taffy.layout(node7).unwrap();
325 let Layout { size, location, .. } = layout;
326 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node7, 60f32, size.width);
327 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node7, 60f32, size.height);
328 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7, 40f32, location.x);
329 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, location.y);
330}