tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5334Rust 85Markdown 12TOML 91813 Sutichaykuna

⎇ b746ac4f346dde8a2b6f85d3a428c02a2342f099 tests/generated/flex/justify_content_overflow_min_max.rs Rust · 303 siq'ikuna · 12.2 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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