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