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