tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Definiciones

⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227 tests/generated/flex/align_content_stretch_row.rs Rust · 405 líneas · 16.5 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_stretch_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 { width: taffy::style::Dimension::Length(50f32), height: auto() },
10            ..Default::default()
11        })
12        .unwrap();
13    let node1 = taffy
14        .new_leaf(taffy::style::Style {
15            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
16            ..Default::default()
17        })
18        .unwrap();
19    let node2 = taffy
20        .new_leaf(taffy::style::Style {
21            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
22            ..Default::default()
23        })
24        .unwrap();
25    let node3 = taffy
26        .new_leaf(taffy::style::Style {
27            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
28            ..Default::default()
29        })
30        .unwrap();
31    let node4 = taffy
32        .new_leaf(taffy::style::Style {
33            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
34            ..Default::default()
35        })
36        .unwrap();
37    let node = taffy
38        .new_with_children(
39            taffy::style::Style {
40                flex_wrap: taffy::style::FlexWrap::Wrap,
41                align_content: Some(taffy::style::AlignContent::Stretch),
42                size: taffy::geometry::Size {
43                    width: taffy::style::Dimension::Length(150f32),
44                    height: taffy::style::Dimension::Length(100f32),
45                },
46                ..Default::default()
47            },
48            &[node0, node1, node2, node3, node4],
49        )
50        .unwrap();
51    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
52    println!("\nComputed tree:");
53    taffy.print_tree(node);
54    println!();
55    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
56    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
57    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
58    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
61    #[cfg(feature = "content_size")]
62    assert_eq!(
63        layout.scroll_width(),
64        0f32,
65        "scroll_width of node {:?}. Expected {}. Actual {}",
66        node,
67        0f32,
68        layout.scroll_width()
69    );
70    #[cfg(feature = "content_size")]
71    assert_eq!(
72        layout.scroll_height(),
73        0f32,
74        "scroll_height of node {:?}. Expected {}. Actual {}",
75        node,
76        0f32,
77        layout.scroll_height()
78    );
79    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
80    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
81    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
82    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
83    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
84    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 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        node0,
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        node0,
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(node1).unwrap();
105    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
106    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
107    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
108    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 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        node1,
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        node1,
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(node2).unwrap();
129    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
130    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
131    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node2, 100f32, location.x);
132    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 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        node2,
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        node2,
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(node3).unwrap();
153    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
154    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3, 50f32, size.height);
155    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
156    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node3, 50f32, location.y);
157    #[cfg(feature = "content_size")]
158    assert_eq!(
159        layout.scroll_width(),
160        0f32,
161        "scroll_width of node {:?}. Expected {}. Actual {}",
162        node3,
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        node3,
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(node4).unwrap();
177    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
178    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node4, 50f32, size.height);
179    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node4, 50f32, location.x);
180    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node4, 50f32, location.y);
181    #[cfg(feature = "content_size")]
182    assert_eq!(
183        layout.scroll_width(),
184        0f32,
185        "scroll_width of node {:?}. Expected {}. Actual {}",
186        node4,
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        node4,
196        0f32,
197        layout.scroll_height()
198    );
199}
200
201#[test]
202#[allow(non_snake_case)]
203fn align_content_stretch_row__content_box() {
204    #[allow(unused_imports)]
205    use taffy::{prelude::*, tree::Layout, TaffyTree};
206    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
207    let node0 = taffy
208        .new_leaf(taffy::style::Style {
209            box_sizing: taffy::style::BoxSizing::ContentBox,
210            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
211            ..Default::default()
212        })
213        .unwrap();
214    let node1 = taffy
215        .new_leaf(taffy::style::Style {
216            box_sizing: taffy::style::BoxSizing::ContentBox,
217            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
218            ..Default::default()
219        })
220        .unwrap();
221    let node2 = taffy
222        .new_leaf(taffy::style::Style {
223            box_sizing: taffy::style::BoxSizing::ContentBox,
224            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
225            ..Default::default()
226        })
227        .unwrap();
228    let node3 = taffy
229        .new_leaf(taffy::style::Style {
230            box_sizing: taffy::style::BoxSizing::ContentBox,
231            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
232            ..Default::default()
233        })
234        .unwrap();
235    let node4 = taffy
236        .new_leaf(taffy::style::Style {
237            box_sizing: taffy::style::BoxSizing::ContentBox,
238            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
239            ..Default::default()
240        })
241        .unwrap();
242    let node = taffy
243        .new_with_children(
244            taffy::style::Style {
245                box_sizing: taffy::style::BoxSizing::ContentBox,
246                flex_wrap: taffy::style::FlexWrap::Wrap,
247                align_content: Some(taffy::style::AlignContent::Stretch),
248                size: taffy::geometry::Size {
249                    width: taffy::style::Dimension::Length(150f32),
250                    height: taffy::style::Dimension::Length(100f32),
251                },
252                ..Default::default()
253            },
254            &[node0, node1, node2, node3, node4],
255        )
256        .unwrap();
257    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
258    println!("\nComputed tree:");
259    taffy.print_tree(node);
260    println!();
261    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
262    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
263    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
264    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
265    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
266    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
267    #[cfg(feature = "content_size")]
268    assert_eq!(
269        layout.scroll_width(),
270        0f32,
271        "scroll_width of node {:?}. Expected {}. Actual {}",
272        node,
273        0f32,
274        layout.scroll_width()
275    );
276    #[cfg(feature = "content_size")]
277    assert_eq!(
278        layout.scroll_height(),
279        0f32,
280        "scroll_height of node {:?}. Expected {}. Actual {}",
281        node,
282        0f32,
283        layout.scroll_height()
284    );
285    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
286    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
287    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
288    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
289    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
290    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
291    #[cfg(feature = "content_size")]
292    assert_eq!(
293        layout.scroll_width(),
294        0f32,
295        "scroll_width of node {:?}. Expected {}. Actual {}",
296        node0,
297        0f32,
298        layout.scroll_width()
299    );
300    #[cfg(feature = "content_size")]
301    assert_eq!(
302        layout.scroll_height(),
303        0f32,
304        "scroll_height of node {:?}. Expected {}. Actual {}",
305        node0,
306        0f32,
307        layout.scroll_height()
308    );
309    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
310    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
311    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
312    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
313    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
314    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
315    #[cfg(feature = "content_size")]
316    assert_eq!(
317        layout.scroll_width(),
318        0f32,
319        "scroll_width of node {:?}. Expected {}. Actual {}",
320        node1,
321        0f32,
322        layout.scroll_width()
323    );
324    #[cfg(feature = "content_size")]
325    assert_eq!(
326        layout.scroll_height(),
327        0f32,
328        "scroll_height of node {:?}. Expected {}. Actual {}",
329        node1,
330        0f32,
331        layout.scroll_height()
332    );
333    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
334    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
335    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
336    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
337    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node2, 100f32, location.x);
338    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
339    #[cfg(feature = "content_size")]
340    assert_eq!(
341        layout.scroll_width(),
342        0f32,
343        "scroll_width of node {:?}. Expected {}. Actual {}",
344        node2,
345        0f32,
346        layout.scroll_width()
347    );
348    #[cfg(feature = "content_size")]
349    assert_eq!(
350        layout.scroll_height(),
351        0f32,
352        "scroll_height of node {:?}. Expected {}. Actual {}",
353        node2,
354        0f32,
355        layout.scroll_height()
356    );
357    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
358    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
359    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
360    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3, 50f32, size.height);
361    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
362    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node3, 50f32, location.y);
363    #[cfg(feature = "content_size")]
364    assert_eq!(
365        layout.scroll_width(),
366        0f32,
367        "scroll_width of node {:?}. Expected {}. Actual {}",
368        node3,
369        0f32,
370        layout.scroll_width()
371    );
372    #[cfg(feature = "content_size")]
373    assert_eq!(
374        layout.scroll_height(),
375        0f32,
376        "scroll_height of node {:?}. Expected {}. Actual {}",
377        node3,
378        0f32,
379        layout.scroll_height()
380    );
381    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
382    let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
383    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
384    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node4, 50f32, size.height);
385    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node4, 50f32, location.x);
386    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node4, 50f32, location.y);
387    #[cfg(feature = "content_size")]
388    assert_eq!(
389        layout.scroll_width(),
390        0f32,
391        "scroll_width of node {:?}. Expected {}. Actual {}",
392        node4,
393        0f32,
394        layout.scroll_width()
395    );
396    #[cfg(feature = "content_size")]
397    assert_eq!(
398        layout.scroll_height(),
399        0f32,
400        "scroll_height of node {:?}. Expected {}. Actual {}",
401        node4,
402        0f32,
403        layout.scroll_height()
404    );
405}