Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn gridflex_kitchen_sink() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node000 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(20f32), height: auto() },
9 ..Default::default()
10 })
11 .unwrap();
12 let node00100 = taffy
13 .new_leaf(taffy::style::Style {
14 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(20f32), height: auto() },
15 ..Default::default()
16 })
17 .unwrap();
18 let node00101 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
19 let node00102 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
20 let node00103 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
21 let node0010 = taffy
22 .new_with_children(
23 taffy::style::Style {
24 display: taffy::style::Display::Grid,
25 grid_template_rows: vec![percent(0.3f32), percent(0.1f32)],
26 grid_template_columns: vec![auto(), percent(0.1f32)],
27 ..Default::default()
28 },
29 &[node00100, node00101, node00102, node00103],
30 )
31 .unwrap();
32 let node001 = taffy
33 .new_with_children(
34 taffy::style::Style {
35 flex_grow: 1f32,
36 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
37 ..Default::default()
38 },
39 &[node0010],
40 )
41 .unwrap();
42 let node00 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node000, node001]).unwrap();
43 let node01 = taffy
44 .new_leaf_with_context(
45 taffy::style::Style { ..Default::default() },
46 crate::TextMeasure {
47 text_content: "HH",
48 writing_mode: crate::WritingMode::Horizontal,
49 _aspect_ratio: None,
50 },
51 )
52 .unwrap();
53 let node02 = taffy
54 .new_leaf_with_context(
55 taffy::style::Style { ..Default::default() },
56 crate::TextMeasure {
57 text_content: "HH",
58 writing_mode: crate::WritingMode::Horizontal,
59 _aspect_ratio: None,
60 },
61 )
62 .unwrap();
63 let node03 = taffy
64 .new_leaf_with_context(
65 taffy::style::Style { ..Default::default() },
66 crate::TextMeasure {
67 text_content: "HH",
68 writing_mode: crate::WritingMode::Horizontal,
69 _aspect_ratio: None,
70 },
71 )
72 .unwrap();
73 let node0 = taffy
74 .new_with_children(
75 taffy::style::Style {
76 display: taffy::style::Display::Grid,
77 grid_template_rows: vec![fr(1f32), fr(1f32)],
78 grid_template_columns: vec![fr(1f32), fr(1f32)],
79 ..Default::default()
80 },
81 &[node00, node01, node02, node03],
82 )
83 .unwrap();
84 let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
85 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
86 println!("\nComputed tree:");
87 taffy.print_tree(node);
88 println!();
89 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
90 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
91 assert_eq!(size.width, 140f32, "width of node {:?}. Expected {}. Actual {}", node, 140f32, size.width);
92 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
93 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
94 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
95 #[cfg(feature = "content_size")]
96 assert_eq!(
97 layout.scroll_width(),
98 0f32,
99 "scroll_width of node {:?}. Expected {}. Actual {}",
100 node,
101 0f32,
102 layout.scroll_width()
103 );
104 #[cfg(feature = "content_size")]
105 assert_eq!(
106 layout.scroll_height(),
107 0f32,
108 "scroll_height of node {:?}. Expected {}. Actual {}",
109 node,
110 0f32,
111 layout.scroll_height()
112 );
113 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
114 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
115 assert_eq!(size.width, 140f32, "width of node {:?}. Expected {}. Actual {}", node0, 140f32, size.width);
116 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
117 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
118 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
119 #[cfg(feature = "content_size")]
120 assert_eq!(
121 layout.scroll_width(),
122 0f32,
123 "scroll_width of node {:?}. Expected {}. Actual {}",
124 node0,
125 0f32,
126 layout.scroll_width()
127 );
128 #[cfg(feature = "content_size")]
129 assert_eq!(
130 layout.scroll_height(),
131 0f32,
132 "scroll_height of node {:?}. Expected {}. Actual {}",
133 node0,
134 0f32,
135 layout.scroll_height()
136 );
137 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
138 let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
139 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node00, 70f32, size.width);
140 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
141 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
142 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
143 #[cfg(feature = "content_size")]
144 assert_eq!(
145 layout.scroll_width(),
146 0f32,
147 "scroll_width of node {:?}. Expected {}. Actual {}",
148 node00,
149 0f32,
150 layout.scroll_width()
151 );
152 #[cfg(feature = "content_size")]
153 assert_eq!(
154 layout.scroll_height(),
155 0f32,
156 "scroll_height of node {:?}. Expected {}. Actual {}",
157 node00,
158 0f32,
159 layout.scroll_height()
160 );
161 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
162 let layout @ Layout { size, location, .. } = taffy.layout(node000).unwrap();
163 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node000, 20f32, size.width);
164 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
165 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
166 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
167 #[cfg(feature = "content_size")]
168 assert_eq!(
169 layout.scroll_width(),
170 0f32,
171 "scroll_width of node {:?}. Expected {}. Actual {}",
172 node000,
173 0f32,
174 layout.scroll_width()
175 );
176 #[cfg(feature = "content_size")]
177 assert_eq!(
178 layout.scroll_height(),
179 0f32,
180 "scroll_height of node {:?}. Expected {}. Actual {}",
181 node000,
182 0f32,
183 layout.scroll_height()
184 );
185 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
186 let layout @ Layout { size, location, .. } = taffy.layout(node001).unwrap();
187 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node001, 50f32, size.width);
188 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node001, 10f32, size.height);
189 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node001, 20f32, location.x);
190 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node001, 0f32, location.y);
191 #[cfg(feature = "content_size")]
192 assert_eq!(
193 layout.scroll_width(),
194 0f32,
195 "scroll_width of node {:?}. Expected {}. Actual {}",
196 node001,
197 0f32,
198 layout.scroll_width()
199 );
200 #[cfg(feature = "content_size")]
201 assert_eq!(
202 layout.scroll_height(),
203 0f32,
204 "scroll_height of node {:?}. Expected {}. Actual {}",
205 node001,
206 0f32,
207 layout.scroll_height()
208 );
209 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
210 let layout @ Layout { size, location, .. } = taffy.layout(node0010).unwrap();
211 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0010, 20f32, size.width);
212 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0010, 10f32, size.height);
213 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0010, 0f32, location.x);
214 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0010, 0f32, location.y);
215 #[cfg(feature = "content_size")]
216 assert_eq!(
217 layout.scroll_width(),
218 2f32,
219 "scroll_width of node {:?}. Expected {}. Actual {}",
220 node0010,
221 2f32,
222 layout.scroll_width()
223 );
224 #[cfg(feature = "content_size")]
225 assert_eq!(
226 layout.scroll_height(),
227 0f32,
228 "scroll_height of node {:?}. Expected {}. Actual {}",
229 node0010,
230 0f32,
231 layout.scroll_height()
232 );
233 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
234 let layout @ Layout { size, location, .. } = taffy.layout(node00100).unwrap();
235 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00100, 20f32, size.width);
236 assert_eq!(size.height, 3f32, "height of node {:?}. Expected {}. Actual {}", node00100, 3f32, size.height);
237 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00100, 0f32, location.x);
238 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00100, 0f32, location.y);
239 #[cfg(feature = "content_size")]
240 assert_eq!(
241 layout.scroll_width(),
242 0f32,
243 "scroll_width of node {:?}. Expected {}. Actual {}",
244 node00100,
245 0f32,
246 layout.scroll_width()
247 );
248 #[cfg(feature = "content_size")]
249 assert_eq!(
250 layout.scroll_height(),
251 0f32,
252 "scroll_height of node {:?}. Expected {}. Actual {}",
253 node00100,
254 0f32,
255 layout.scroll_height()
256 );
257 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
258 let layout @ Layout { size, location, .. } = taffy.layout(node00101).unwrap();
259 assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node00101, 2f32, size.width);
260 assert_eq!(size.height, 3f32, "height of node {:?}. Expected {}. Actual {}", node00101, 3f32, size.height);
261 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00101, 20f32, location.x);
262 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00101, 0f32, location.y);
263 #[cfg(feature = "content_size")]
264 assert_eq!(
265 layout.scroll_width(),
266 0f32,
267 "scroll_width of node {:?}. Expected {}. Actual {}",
268 node00101,
269 0f32,
270 layout.scroll_width()
271 );
272 #[cfg(feature = "content_size")]
273 assert_eq!(
274 layout.scroll_height(),
275 0f32,
276 "scroll_height of node {:?}. Expected {}. Actual {}",
277 node00101,
278 0f32,
279 layout.scroll_height()
280 );
281 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
282 let layout @ Layout { size, location, .. } = taffy.layout(node00102).unwrap();
283 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00102, 20f32, size.width);
284 assert_eq!(size.height, 1f32, "height of node {:?}. Expected {}. Actual {}", node00102, 1f32, size.height);
285 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00102, 0f32, location.x);
286 assert_eq!(location.y, 3f32, "y of node {:?}. Expected {}. Actual {}", node00102, 3f32, location.y);
287 #[cfg(feature = "content_size")]
288 assert_eq!(
289 layout.scroll_width(),
290 0f32,
291 "scroll_width of node {:?}. Expected {}. Actual {}",
292 node00102,
293 0f32,
294 layout.scroll_width()
295 );
296 #[cfg(feature = "content_size")]
297 assert_eq!(
298 layout.scroll_height(),
299 0f32,
300 "scroll_height of node {:?}. Expected {}. Actual {}",
301 node00102,
302 0f32,
303 layout.scroll_height()
304 );
305 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
306 let layout @ Layout { size, location, .. } = taffy.layout(node00103).unwrap();
307 assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node00103, 2f32, size.width);
308 assert_eq!(size.height, 1f32, "height of node {:?}. Expected {}. Actual {}", node00103, 1f32, size.height);
309 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00103, 20f32, location.x);
310 assert_eq!(location.y, 3f32, "y of node {:?}. Expected {}. Actual {}", node00103, 3f32, location.y);
311 #[cfg(feature = "content_size")]
312 assert_eq!(
313 layout.scroll_width(),
314 0f32,
315 "scroll_width of node {:?}. Expected {}. Actual {}",
316 node00103,
317 0f32,
318 layout.scroll_width()
319 );
320 #[cfg(feature = "content_size")]
321 assert_eq!(
322 layout.scroll_height(),
323 0f32,
324 "scroll_height of node {:?}. Expected {}. Actual {}",
325 node00103,
326 0f32,
327 layout.scroll_height()
328 );
329 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
330 let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
331 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node01, 70f32, size.width);
332 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01, 10f32, size.height);
333 assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node01, 70f32, location.x);
334 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
335 #[cfg(feature = "content_size")]
336 assert_eq!(
337 layout.scroll_width(),
338 0f32,
339 "scroll_width of node {:?}. Expected {}. Actual {}",
340 node01,
341 0f32,
342 layout.scroll_width()
343 );
344 #[cfg(feature = "content_size")]
345 assert_eq!(
346 layout.scroll_height(),
347 0f32,
348 "scroll_height of node {:?}. Expected {}. Actual {}",
349 node01,
350 0f32,
351 layout.scroll_height()
352 );
353 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
354 let layout @ Layout { size, location, .. } = taffy.layout(node02).unwrap();
355 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node02, 70f32, size.width);
356 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02, 10f32, size.height);
357 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
358 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02, 10f32, location.y);
359 #[cfg(feature = "content_size")]
360 assert_eq!(
361 layout.scroll_width(),
362 0f32,
363 "scroll_width of node {:?}. Expected {}. Actual {}",
364 node02,
365 0f32,
366 layout.scroll_width()
367 );
368 #[cfg(feature = "content_size")]
369 assert_eq!(
370 layout.scroll_height(),
371 0f32,
372 "scroll_height of node {:?}. Expected {}. Actual {}",
373 node02,
374 0f32,
375 layout.scroll_height()
376 );
377 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
378 let layout @ Layout { size, location, .. } = taffy.layout(node03).unwrap();
379 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node03, 70f32, size.width);
380 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03, 10f32, size.height);
381 assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node03, 70f32, location.x);
382 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03, 10f32, location.y);
383 #[cfg(feature = "content_size")]
384 assert_eq!(
385 layout.scroll_width(),
386 0f32,
387 "scroll_width of node {:?}. Expected {}. Actual {}",
388 node03,
389 0f32,
390 layout.scroll_width()
391 );
392 #[cfg(feature = "content_size")]
393 assert_eq!(
394 layout.scroll_height(),
395 0f32,
396 "scroll_height of node {:?}. Expected {}. Actual {}",
397 node03,
398 0f32,
399 layout.scroll_height()
400 );
401}