tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1077HTML 1008Markdown 12TOML 83209 Sutichaykuna

⎇ b746ac4f346dde8a2b6f85d3a428c02a2342f099 tests/generated/flex/align_content_stretch_row_wrap.rs Rust · 234 siq'ikuna · 9.3 KB Ñawpa willay Pi imata llamkarqan ch'uya

Fix flex line cross-size determination (#690) b746ac4f3 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn align_content_stretch_row_wrap__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            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Length(50f32),
11                height: taffy::style::Dimension::Length(150f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node0 = taffy
17        .new_with_children(
18            taffy::style::Style {
19                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
20                ..Default::default()
21            },
22            &[node00],
23        )
24        .unwrap();
25    let node = taffy
26        .new_with_children(
27            taffy::style::Style {
28                flex_wrap: taffy::style::FlexWrap::Wrap,
29                align_content: Some(taffy::style::AlignContent::Stretch),
30                size: taffy::geometry::Size {
31                    width: taffy::style::Dimension::Length(150f32),
32                    height: taffy::style::Dimension::Length(100f32),
33                },
34                ..Default::default()
35            },
36            &[node0],
37        )
38        .unwrap();
39    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
40    println!("\nComputed tree:");
41    taffy.print_tree(node);
42    println!();
43    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
44    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
45    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
46    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
47    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
48    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
49    #[cfg(feature = "content_size")]
50    assert_eq!(
51        layout.scroll_width(),
52        0f32,
53        "scroll_width of node {:?}. Expected {}. Actual {}",
54        node,
55        0f32,
56        layout.scroll_width()
57    );
58    #[cfg(feature = "content_size")]
59    assert_eq!(
60        layout.scroll_height(),
61        50f32,
62        "scroll_height of node {:?}. Expected {}. Actual {}",
63        node,
64        50f32,
65        layout.scroll_height()
66    );
67    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
68    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
69    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
70    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node0, 150f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
73    #[cfg(feature = "content_size")]
74    assert_eq!(
75        layout.scroll_width(),
76        0f32,
77        "scroll_width of node {:?}. Expected {}. Actual {}",
78        node0,
79        0f32,
80        layout.scroll_width()
81    );
82    #[cfg(feature = "content_size")]
83    assert_eq!(
84        layout.scroll_height(),
85        0f32,
86        "scroll_height of node {:?}. Expected {}. Actual {}",
87        node0,
88        0f32,
89        layout.scroll_height()
90    );
91    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
92    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
93    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
94    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node00, 150f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
97    #[cfg(feature = "content_size")]
98    assert_eq!(
99        layout.scroll_width(),
100        0f32,
101        "scroll_width of node {:?}. Expected {}. Actual {}",
102        node00,
103        0f32,
104        layout.scroll_width()
105    );
106    #[cfg(feature = "content_size")]
107    assert_eq!(
108        layout.scroll_height(),
109        0f32,
110        "scroll_height of node {:?}. Expected {}. Actual {}",
111        node00,
112        0f32,
113        layout.scroll_height()
114    );
115}
116
117#[test]
118#[allow(non_snake_case)]
119fn align_content_stretch_row_wrap__content_box() {
120    #[allow(unused_imports)]
121    use taffy::{prelude::*, tree::Layout, TaffyTree};
122    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
123    let node00 = taffy
124        .new_leaf(taffy::style::Style {
125            box_sizing: taffy::style::BoxSizing::ContentBox,
126            size: taffy::geometry::Size {
127                width: taffy::style::Dimension::Length(50f32),
128                height: taffy::style::Dimension::Length(150f32),
129            },
130            ..Default::default()
131        })
132        .unwrap();
133    let node0 = taffy
134        .new_with_children(
135            taffy::style::Style {
136                box_sizing: taffy::style::BoxSizing::ContentBox,
137                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
138                ..Default::default()
139            },
140            &[node00],
141        )
142        .unwrap();
143    let node = taffy
144        .new_with_children(
145            taffy::style::Style {
146                box_sizing: taffy::style::BoxSizing::ContentBox,
147                flex_wrap: taffy::style::FlexWrap::Wrap,
148                align_content: Some(taffy::style::AlignContent::Stretch),
149                size: taffy::geometry::Size {
150                    width: taffy::style::Dimension::Length(150f32),
151                    height: taffy::style::Dimension::Length(100f32),
152                },
153                ..Default::default()
154            },
155            &[node0],
156        )
157        .unwrap();
158    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
159    println!("\nComputed tree:");
160    taffy.print_tree(node);
161    println!();
162    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
163    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
164    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
165    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
166    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
167    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
168    #[cfg(feature = "content_size")]
169    assert_eq!(
170        layout.scroll_width(),
171        0f32,
172        "scroll_width of node {:?}. Expected {}. Actual {}",
173        node,
174        0f32,
175        layout.scroll_width()
176    );
177    #[cfg(feature = "content_size")]
178    assert_eq!(
179        layout.scroll_height(),
180        50f32,
181        "scroll_height of node {:?}. Expected {}. Actual {}",
182        node,
183        50f32,
184        layout.scroll_height()
185    );
186    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
187    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
188    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
189    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node0, 150f32, size.height);
190    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
191    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
192    #[cfg(feature = "content_size")]
193    assert_eq!(
194        layout.scroll_width(),
195        0f32,
196        "scroll_width of node {:?}. Expected {}. Actual {}",
197        node0,
198        0f32,
199        layout.scroll_width()
200    );
201    #[cfg(feature = "content_size")]
202    assert_eq!(
203        layout.scroll_height(),
204        0f32,
205        "scroll_height of node {:?}. Expected {}. Actual {}",
206        node0,
207        0f32,
208        layout.scroll_height()
209    );
210    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
211    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
212    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
213    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node00, 150f32, size.height);
214    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
215    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
216    #[cfg(feature = "content_size")]
217    assert_eq!(
218        layout.scroll_width(),
219        0f32,
220        "scroll_width of node {:?}. Expected {}. Actual {}",
221        node00,
222        0f32,
223        layout.scroll_width()
224    );
225    #[cfg(feature = "content_size")]
226    assert_eq!(
227        layout.scroll_height(),
228        0f32,
229        "scroll_height of node {:?}. Expected {}. Actual {}",
230        node00,
231        0f32,
232        layout.scroll_height()
233    );
234}