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