gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 252HTML 238TOML 3CSS 1626 Definiciones

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/align_content_space_between_wrapped.rs Rust · 502 líneas · 20.0 KB Historia Quién tocó qué crudo

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn align_content_space_between_wrapped__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(50f32),
11                height: taffy::style::Dimension::Length(10f32),
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(50f32),
20                height: taffy::style::Dimension::Length(10f32),
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(50f32),
29                height: taffy::style::Dimension::Length(10f32),
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(50f32),
38                height: taffy::style::Dimension::Length(10f32),
39            },
40            ..Default::default()
41        })
42        .unwrap();
43    let node4 = taffy
44        .new_leaf(taffy::style::Style {
45            size: taffy::geometry::Size {
46                width: taffy::style::Dimension::Length(50f32),
47                height: taffy::style::Dimension::Length(10f32),
48            },
49            ..Default::default()
50        })
51        .unwrap();
52    let node5 = taffy
53        .new_leaf(taffy::style::Style {
54            size: taffy::geometry::Size {
55                width: taffy::style::Dimension::Length(50f32),
56                height: taffy::style::Dimension::Length(10f32),
57            },
58            ..Default::default()
59        })
60        .unwrap();
61    let node = taffy
62        .new_with_children(
63            taffy::style::Style {
64                flex_wrap: taffy::style::FlexWrap::Wrap,
65                align_content: Some(taffy::style::AlignContent::SpaceBetween),
66                size: taffy::geometry::Size {
67                    width: taffy::style::Dimension::Length(100f32),
68                    height: taffy::style::Dimension::Length(100f32),
69                },
70                ..Default::default()
71            },
72            &[node0, node1, node2, node3, node4, node5],
73        )
74        .unwrap();
75    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
76    println!("\nComputed tree:");
77    taffy.print_tree(node);
78    println!();
79    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
80    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
81    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
82    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
83    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
84    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
85    #[cfg(feature = "content_size")]
86    assert_eq!(
87        layout.scroll_width(),
88        0f32,
89        "scroll_width of node {:?}. Expected {}. Actual {}",
90        node,
91        0f32,
92        layout.scroll_width()
93    );
94    #[cfg(feature = "content_size")]
95    assert_eq!(
96        layout.scroll_height(),
97        0f32,
98        "scroll_height of node {:?}. Expected {}. Actual {}",
99        node,
100        0f32,
101        layout.scroll_height()
102    );
103    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
104    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
105    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
106    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
107    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
108    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
109    #[cfg(feature = "content_size")]
110    assert_eq!(
111        layout.scroll_width(),
112        0f32,
113        "scroll_width of node {:?}. Expected {}. Actual {}",
114        node0,
115        0f32,
116        layout.scroll_width()
117    );
118    #[cfg(feature = "content_size")]
119    assert_eq!(
120        layout.scroll_height(),
121        0f32,
122        "scroll_height of node {:?}. Expected {}. Actual {}",
123        node0,
124        0f32,
125        layout.scroll_height()
126    );
127    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
128    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
129    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
130    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
131    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
132    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
133    #[cfg(feature = "content_size")]
134    assert_eq!(
135        layout.scroll_width(),
136        0f32,
137        "scroll_width of node {:?}. Expected {}. Actual {}",
138        node1,
139        0f32,
140        layout.scroll_width()
141    );
142    #[cfg(feature = "content_size")]
143    assert_eq!(
144        layout.scroll_height(),
145        0f32,
146        "scroll_height of node {:?}. Expected {}. Actual {}",
147        node1,
148        0f32,
149        layout.scroll_height()
150    );
151    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
152    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
153    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
154    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
155    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
156    assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node2, 45f32, location.y);
157    #[cfg(feature = "content_size")]
158    assert_eq!(
159        layout.scroll_width(),
160        0f32,
161        "scroll_width of node {:?}. Expected {}. Actual {}",
162        node2,
163        0f32,
164        layout.scroll_width()
165    );
166    #[cfg(feature = "content_size")]
167    assert_eq!(
168        layout.scroll_height(),
169        0f32,
170        "scroll_height of node {:?}. Expected {}. Actual {}",
171        node2,
172        0f32,
173        layout.scroll_height()
174    );
175    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
176    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
177    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
178    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
179    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
180    assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node3, 45f32, location.y);
181    #[cfg(feature = "content_size")]
182    assert_eq!(
183        layout.scroll_width(),
184        0f32,
185        "scroll_width of node {:?}. Expected {}. Actual {}",
186        node3,
187        0f32,
188        layout.scroll_width()
189    );
190    #[cfg(feature = "content_size")]
191    assert_eq!(
192        layout.scroll_height(),
193        0f32,
194        "scroll_height of node {:?}. Expected {}. Actual {}",
195        node3,
196        0f32,
197        layout.scroll_height()
198    );
199    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
200    let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
201    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
202    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node4, 10f32, size.height);
203    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
204    assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node4, 90f32, location.y);
205    #[cfg(feature = "content_size")]
206    assert_eq!(
207        layout.scroll_width(),
208        0f32,
209        "scroll_width of node {:?}. Expected {}. Actual {}",
210        node4,
211        0f32,
212        layout.scroll_width()
213    );
214    #[cfg(feature = "content_size")]
215    assert_eq!(
216        layout.scroll_height(),
217        0f32,
218        "scroll_height of node {:?}. Expected {}. Actual {}",
219        node4,
220        0f32,
221        layout.scroll_height()
222    );
223    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
224    let layout @ Layout { size, location, .. } = taffy.layout(node5).unwrap();
225    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node5, 50f32, size.width);
226    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node5, 10f32, size.height);
227    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node5, 50f32, location.x);
228    assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node5, 90f32, location.y);
229    #[cfg(feature = "content_size")]
230    assert_eq!(
231        layout.scroll_width(),
232        0f32,
233        "scroll_width of node {:?}. Expected {}. Actual {}",
234        node5,
235        0f32,
236        layout.scroll_width()
237    );
238    #[cfg(feature = "content_size")]
239    assert_eq!(
240        layout.scroll_height(),
241        0f32,
242        "scroll_height of node {:?}. Expected {}. Actual {}",
243        node5,
244        0f32,
245        layout.scroll_height()
246    );
247}
248
249#[test]
250#[allow(non_snake_case)]
251fn align_content_space_between_wrapped__content_box() {
252    #[allow(unused_imports)]
253    use taffy::{prelude::*, tree::Layout, TaffyTree};
254    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
255    let node0 = taffy
256        .new_leaf(taffy::style::Style {
257            box_sizing: taffy::style::BoxSizing::ContentBox,
258            size: taffy::geometry::Size {
259                width: taffy::style::Dimension::Length(50f32),
260                height: taffy::style::Dimension::Length(10f32),
261            },
262            ..Default::default()
263        })
264        .unwrap();
265    let node1 = taffy
266        .new_leaf(taffy::style::Style {
267            box_sizing: taffy::style::BoxSizing::ContentBox,
268            size: taffy::geometry::Size {
269                width: taffy::style::Dimension::Length(50f32),
270                height: taffy::style::Dimension::Length(10f32),
271            },
272            ..Default::default()
273        })
274        .unwrap();
275    let node2 = taffy
276        .new_leaf(taffy::style::Style {
277            box_sizing: taffy::style::BoxSizing::ContentBox,
278            size: taffy::geometry::Size {
279                width: taffy::style::Dimension::Length(50f32),
280                height: taffy::style::Dimension::Length(10f32),
281            },
282            ..Default::default()
283        })
284        .unwrap();
285    let node3 = taffy
286        .new_leaf(taffy::style::Style {
287            box_sizing: taffy::style::BoxSizing::ContentBox,
288            size: taffy::geometry::Size {
289                width: taffy::style::Dimension::Length(50f32),
290                height: taffy::style::Dimension::Length(10f32),
291            },
292            ..Default::default()
293        })
294        .unwrap();
295    let node4 = taffy
296        .new_leaf(taffy::style::Style {
297            box_sizing: taffy::style::BoxSizing::ContentBox,
298            size: taffy::geometry::Size {
299                width: taffy::style::Dimension::Length(50f32),
300                height: taffy::style::Dimension::Length(10f32),
301            },
302            ..Default::default()
303        })
304        .unwrap();
305    let node5 = taffy
306        .new_leaf(taffy::style::Style {
307            box_sizing: taffy::style::BoxSizing::ContentBox,
308            size: taffy::geometry::Size {
309                width: taffy::style::Dimension::Length(50f32),
310                height: taffy::style::Dimension::Length(10f32),
311            },
312            ..Default::default()
313        })
314        .unwrap();
315    let node = taffy
316        .new_with_children(
317            taffy::style::Style {
318                box_sizing: taffy::style::BoxSizing::ContentBox,
319                flex_wrap: taffy::style::FlexWrap::Wrap,
320                align_content: Some(taffy::style::AlignContent::SpaceBetween),
321                size: taffy::geometry::Size {
322                    width: taffy::style::Dimension::Length(100f32),
323                    height: taffy::style::Dimension::Length(100f32),
324                },
325                ..Default::default()
326            },
327            &[node0, node1, node2, node3, node4, node5],
328        )
329        .unwrap();
330    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
331    println!("\nComputed tree:");
332    taffy.print_tree(node);
333    println!();
334    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
335    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
336    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
337    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
338    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
339    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
340    #[cfg(feature = "content_size")]
341    assert_eq!(
342        layout.scroll_width(),
343        0f32,
344        "scroll_width of node {:?}. Expected {}. Actual {}",
345        node,
346        0f32,
347        layout.scroll_width()
348    );
349    #[cfg(feature = "content_size")]
350    assert_eq!(
351        layout.scroll_height(),
352        0f32,
353        "scroll_height of node {:?}. Expected {}. Actual {}",
354        node,
355        0f32,
356        layout.scroll_height()
357    );
358    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
359    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
360    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
361    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
362    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
363    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
364    #[cfg(feature = "content_size")]
365    assert_eq!(
366        layout.scroll_width(),
367        0f32,
368        "scroll_width of node {:?}. Expected {}. Actual {}",
369        node0,
370        0f32,
371        layout.scroll_width()
372    );
373    #[cfg(feature = "content_size")]
374    assert_eq!(
375        layout.scroll_height(),
376        0f32,
377        "scroll_height of node {:?}. Expected {}. Actual {}",
378        node0,
379        0f32,
380        layout.scroll_height()
381    );
382    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
383    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
384    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
385    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
386    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
387    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
388    #[cfg(feature = "content_size")]
389    assert_eq!(
390        layout.scroll_width(),
391        0f32,
392        "scroll_width of node {:?}. Expected {}. Actual {}",
393        node1,
394        0f32,
395        layout.scroll_width()
396    );
397    #[cfg(feature = "content_size")]
398    assert_eq!(
399        layout.scroll_height(),
400        0f32,
401        "scroll_height of node {:?}. Expected {}. Actual {}",
402        node1,
403        0f32,
404        layout.scroll_height()
405    );
406    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
407    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
408    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
409    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
410    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
411    assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node2, 45f32, location.y);
412    #[cfg(feature = "content_size")]
413    assert_eq!(
414        layout.scroll_width(),
415        0f32,
416        "scroll_width of node {:?}. Expected {}. Actual {}",
417        node2,
418        0f32,
419        layout.scroll_width()
420    );
421    #[cfg(feature = "content_size")]
422    assert_eq!(
423        layout.scroll_height(),
424        0f32,
425        "scroll_height of node {:?}. Expected {}. Actual {}",
426        node2,
427        0f32,
428        layout.scroll_height()
429    );
430    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
431    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
432    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
433    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
434    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
435    assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node3, 45f32, location.y);
436    #[cfg(feature = "content_size")]
437    assert_eq!(
438        layout.scroll_width(),
439        0f32,
440        "scroll_width of node {:?}. Expected {}. Actual {}",
441        node3,
442        0f32,
443        layout.scroll_width()
444    );
445    #[cfg(feature = "content_size")]
446    assert_eq!(
447        layout.scroll_height(),
448        0f32,
449        "scroll_height of node {:?}. Expected {}. Actual {}",
450        node3,
451        0f32,
452        layout.scroll_height()
453    );
454    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
455    let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
456    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
457    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node4, 10f32, size.height);
458    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
459    assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node4, 90f32, location.y);
460    #[cfg(feature = "content_size")]
461    assert_eq!(
462        layout.scroll_width(),
463        0f32,
464        "scroll_width of node {:?}. Expected {}. Actual {}",
465        node4,
466        0f32,
467        layout.scroll_width()
468    );
469    #[cfg(feature = "content_size")]
470    assert_eq!(
471        layout.scroll_height(),
472        0f32,
473        "scroll_height of node {:?}. Expected {}. Actual {}",
474        node4,
475        0f32,
476        layout.scroll_height()
477    );
478    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
479    let layout @ Layout { size, location, .. } = taffy.layout(node5).unwrap();
480    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node5, 50f32, size.width);
481    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node5, 10f32, size.height);
482    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node5, 50f32, location.x);
483    assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node5, 90f32, location.y);
484    #[cfg(feature = "content_size")]
485    assert_eq!(
486        layout.scroll_width(),
487        0f32,
488        "scroll_width of node {:?}. Expected {}. Actual {}",
489        node5,
490        0f32,
491        layout.scroll_width()
492    );
493    #[cfg(feature = "content_size")]
494    assert_eq!(
495        layout.scroll_height(),
496        0f32,
497        "scroll_height of node {:?}. Expected {}. Actual {}",
498        node5,
499        0f32,
500        layout.scroll_height()
501    );
502}