gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/wrap_nodes_with_content_sizing_margin_cross.rs Rust · 444 líneas · 17.6 KB Historia Quién tocó qué crudo

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

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