tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

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