⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227
tests/generated/flex/wrap_row.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn wrap_row__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, tree::Layout, TaffyTree};
6 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(31f32),
11 height: taffy::style::Dimension::Length(30f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node1 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::Length(32f32),
20 height: taffy::style::Dimension::Length(30f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node2 = taffy
26 .new_leaf(taffy::style::Style {
27 size: taffy::geometry::Size {
28 width: taffy::style::Dimension::Length(33f32),
29 height: taffy::style::Dimension::Length(30f32),
30 },
31 ..Default::default()
32 })
33 .unwrap();
34 let node3 = taffy
35 .new_leaf(taffy::style::Style {
36 size: taffy::geometry::Size {
37 width: taffy::style::Dimension::Length(34f32),
38 height: taffy::style::Dimension::Length(30f32),
39 },
40 ..Default::default()
41 })
42 .unwrap();
43 let node = taffy
44 .new_with_children(
45 taffy::style::Style {
46 flex_wrap: taffy::style::FlexWrap::Wrap,
47 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
48 ..Default::default()
49 },
50 &[node0, node1, node2, node3],
51 )
52 .unwrap();
53 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
54 println!("\nComputed tree:");
55 taffy.print_tree(node);
56 println!();
57 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
58 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
59 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
60 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node, 60f32, size.height);
61 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
62 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
63 #[cfg(feature = "content_size")]
64 assert_eq!(
65 layout.scroll_width(),
66 0f32,
67 "scroll_width of node {:?}. Expected {}. Actual {}",
68 node,
69 0f32,
70 layout.scroll_width()
71 );
72 #[cfg(feature = "content_size")]
73 assert_eq!(
74 layout.scroll_height(),
75 0f32,
76 "scroll_height of node {:?}. Expected {}. Actual {}",
77 node,
78 0f32,
79 layout.scroll_height()
80 );
81 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
82 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
83 assert_eq!(size.width, 31f32, "width of node {:?}. Expected {}. Actual {}", node0, 31f32, size.width);
84 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0, 30f32, size.height);
85 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
86 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
87 #[cfg(feature = "content_size")]
88 assert_eq!(
89 layout.scroll_width(),
90 0f32,
91 "scroll_width of node {:?}. Expected {}. Actual {}",
92 node0,
93 0f32,
94 layout.scroll_width()
95 );
96 #[cfg(feature = "content_size")]
97 assert_eq!(
98 layout.scroll_height(),
99 0f32,
100 "scroll_height of node {:?}. Expected {}. Actual {}",
101 node0,
102 0f32,
103 layout.scroll_height()
104 );
105 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
106 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
107 assert_eq!(size.width, 32f32, "width of node {:?}. Expected {}. Actual {}", node1, 32f32, size.width);
108 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
109 assert_eq!(location.x, 31f32, "x of node {:?}. Expected {}. Actual {}", node1, 31f32, location.x);
110 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
111 #[cfg(feature = "content_size")]
112 assert_eq!(
113 layout.scroll_width(),
114 0f32,
115 "scroll_width of node {:?}. Expected {}. Actual {}",
116 node1,
117 0f32,
118 layout.scroll_width()
119 );
120 #[cfg(feature = "content_size")]
121 assert_eq!(
122 layout.scroll_height(),
123 0f32,
124 "scroll_height of node {:?}. Expected {}. Actual {}",
125 node1,
126 0f32,
127 layout.scroll_height()
128 );
129 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
130 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
131 assert_eq!(size.width, 33f32, "width of node {:?}. Expected {}. Actual {}", node2, 33f32, size.width);
132 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
133 assert_eq!(location.x, 63f32, "x of node {:?}. Expected {}. Actual {}", node2, 63f32, location.x);
134 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 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 node2,
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 node2,
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(node3).unwrap();
155 assert_eq!(size.width, 34f32, "width of node {:?}. Expected {}. Actual {}", node3, 34f32, size.width);
156 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node3, 30f32, size.height);
157 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
158 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3, 30f32, location.y);
159 #[cfg(feature = "content_size")]
160 assert_eq!(
161 layout.scroll_width(),
162 0f32,
163 "scroll_width of node {:?}. Expected {}. Actual {}",
164 node3,
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 node3,
174 0f32,
175 layout.scroll_height()
176 );
177}
178
179#[test]
180#[allow(non_snake_case)]
181fn wrap_row__content_box() {
182 #[allow(unused_imports)]
183 use taffy::{prelude::*, tree::Layout, TaffyTree};
184 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
185 let node0 = taffy
186 .new_leaf(taffy::style::Style {
187 box_sizing: taffy::style::BoxSizing::ContentBox,
188 size: taffy::geometry::Size {
189 width: taffy::style::Dimension::Length(31f32),
190 height: taffy::style::Dimension::Length(30f32),
191 },
192 ..Default::default()
193 })
194 .unwrap();
195 let node1 = taffy
196 .new_leaf(taffy::style::Style {
197 box_sizing: taffy::style::BoxSizing::ContentBox,
198 size: taffy::geometry::Size {
199 width: taffy::style::Dimension::Length(32f32),
200 height: taffy::style::Dimension::Length(30f32),
201 },
202 ..Default::default()
203 })
204 .unwrap();
205 let node2 = taffy
206 .new_leaf(taffy::style::Style {
207 box_sizing: taffy::style::BoxSizing::ContentBox,
208 size: taffy::geometry::Size {
209 width: taffy::style::Dimension::Length(33f32),
210 height: taffy::style::Dimension::Length(30f32),
211 },
212 ..Default::default()
213 })
214 .unwrap();
215 let node3 = taffy
216 .new_leaf(taffy::style::Style {
217 box_sizing: taffy::style::BoxSizing::ContentBox,
218 size: taffy::geometry::Size {
219 width: taffy::style::Dimension::Length(34f32),
220 height: taffy::style::Dimension::Length(30f32),
221 },
222 ..Default::default()
223 })
224 .unwrap();
225 let node = taffy
226 .new_with_children(
227 taffy::style::Style {
228 box_sizing: taffy::style::BoxSizing::ContentBox,
229 flex_wrap: taffy::style::FlexWrap::Wrap,
230 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
231 ..Default::default()
232 },
233 &[node0, node1, node2, node3],
234 )
235 .unwrap();
236 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
237 println!("\nComputed tree:");
238 taffy.print_tree(node);
239 println!();
240 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
241 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
242 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
243 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node, 60f32, size.height);
244 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
245 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
246 #[cfg(feature = "content_size")]
247 assert_eq!(
248 layout.scroll_width(),
249 0f32,
250 "scroll_width of node {:?}. Expected {}. Actual {}",
251 node,
252 0f32,
253 layout.scroll_width()
254 );
255 #[cfg(feature = "content_size")]
256 assert_eq!(
257 layout.scroll_height(),
258 0f32,
259 "scroll_height of node {:?}. Expected {}. Actual {}",
260 node,
261 0f32,
262 layout.scroll_height()
263 );
264 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
265 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
266 assert_eq!(size.width, 31f32, "width of node {:?}. Expected {}. Actual {}", node0, 31f32, size.width);
267 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0, 30f32, size.height);
268 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
269 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
270 #[cfg(feature = "content_size")]
271 assert_eq!(
272 layout.scroll_width(),
273 0f32,
274 "scroll_width of node {:?}. Expected {}. Actual {}",
275 node0,
276 0f32,
277 layout.scroll_width()
278 );
279 #[cfg(feature = "content_size")]
280 assert_eq!(
281 layout.scroll_height(),
282 0f32,
283 "scroll_height of node {:?}. Expected {}. Actual {}",
284 node0,
285 0f32,
286 layout.scroll_height()
287 );
288 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
289 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
290 assert_eq!(size.width, 32f32, "width of node {:?}. Expected {}. Actual {}", node1, 32f32, size.width);
291 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
292 assert_eq!(location.x, 31f32, "x of node {:?}. Expected {}. Actual {}", node1, 31f32, location.x);
293 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
294 #[cfg(feature = "content_size")]
295 assert_eq!(
296 layout.scroll_width(),
297 0f32,
298 "scroll_width of node {:?}. Expected {}. Actual {}",
299 node1,
300 0f32,
301 layout.scroll_width()
302 );
303 #[cfg(feature = "content_size")]
304 assert_eq!(
305 layout.scroll_height(),
306 0f32,
307 "scroll_height of node {:?}. Expected {}. Actual {}",
308 node1,
309 0f32,
310 layout.scroll_height()
311 );
312 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
313 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
314 assert_eq!(size.width, 33f32, "width of node {:?}. Expected {}. Actual {}", node2, 33f32, size.width);
315 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
316 assert_eq!(location.x, 63f32, "x of node {:?}. Expected {}. Actual {}", node2, 63f32, location.x);
317 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
318 #[cfg(feature = "content_size")]
319 assert_eq!(
320 layout.scroll_width(),
321 0f32,
322 "scroll_width of node {:?}. Expected {}. Actual {}",
323 node2,
324 0f32,
325 layout.scroll_width()
326 );
327 #[cfg(feature = "content_size")]
328 assert_eq!(
329 layout.scroll_height(),
330 0f32,
331 "scroll_height of node {:?}. Expected {}. Actual {}",
332 node2,
333 0f32,
334 layout.scroll_height()
335 );
336 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
337 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
338 assert_eq!(size.width, 34f32, "width of node {:?}. Expected {}. Actual {}", node3, 34f32, size.width);
339 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node3, 30f32, size.height);
340 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
341 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3, 30f32, location.y);
342 #[cfg(feature = "content_size")]
343 assert_eq!(
344 layout.scroll_width(),
345 0f32,
346 "scroll_width of node {:?}. Expected {}. Actual {}",
347 node3,
348 0f32,
349 layout.scroll_width()
350 );
351 #[cfg(feature = "content_size")]
352 assert_eq!(
353 layout.scroll_height(),
354 0f32,
355 "scroll_height of node {:?}. Expected {}. Actual {}",
356 node3,
357 0f32,
358 layout.scroll_height()
359 );
360}