tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1064HTML 999Markdown 12TOML 83137 Definitions

⎇ d67e82255da07928c7e415ea7364529d204bbaf9 tests/generated/wrap_nodes_with_content_sizing_margin_cross.rs Rust · 101 lines · 4.1 KB History Who touched what raw

Fix formatting d67e82255 · elbaro ·

1#[test]
2fn wrap_nodes_with_content_sizing_margin_cross() {
3    let mut stretch = stretch2::Stretch::new();
4    let node000 = stretch
5        .new_node(
6            stretch2::style::Style {
7                size: stretch2::geometry::Size {
8                    width: stretch2::style::Dimension::Points(40f32),
9                    height: stretch2::style::Dimension::Points(40f32),
10                    ..Default::default()
11                },
12                ..Default::default()
13            },
14            &[],
15        )
16        .unwrap();
17    let node00 = stretch
18        .new_node(
19            stretch2::style::Style { flex_direction: stretch2::style::FlexDirection::Column, ..Default::default() },
20            &[node000],
21        )
22        .unwrap();
23    let node010 = stretch
24        .new_node(
25            stretch2::style::Style {
26                size: stretch2::geometry::Size {
27                    width: stretch2::style::Dimension::Points(40f32),
28                    height: stretch2::style::Dimension::Points(40f32),
29                    ..Default::default()
30                },
31                ..Default::default()
32            },
33            &[],
34        )
35        .unwrap();
36    let node01 = stretch
37        .new_node(
38            stretch2::style::Style {
39                flex_direction: stretch2::style::FlexDirection::Column,
40                margin: stretch2::geometry::Rect {
41                    top: stretch2::style::Dimension::Points(10f32),
42                    ..Default::default()
43                },
44                ..Default::default()
45            },
46            &[node010],
47        )
48        .unwrap();
49    let node0 = stretch
50        .new_node(
51            stretch2::style::Style {
52                flex_wrap: stretch2::style::FlexWrap::Wrap,
53                size: stretch2::geometry::Size {
54                    width: stretch2::style::Dimension::Points(70f32),
55                    ..Default::default()
56                },
57                ..Default::default()
58            },
59            &[node00, node01],
60        )
61        .unwrap();
62    let node = stretch
63        .new_node(
64            stretch2::style::Style {
65                flex_direction: stretch2::style::FlexDirection::Column,
66                size: stretch2::geometry::Size {
67                    width: stretch2::style::Dimension::Points(500f32),
68                    height: stretch2::style::Dimension::Points(500f32),
69                    ..Default::default()
70                },
71                ..Default::default()
72            },
73            &[node0],
74        )
75        .unwrap();
76    stretch.compute_layout(node, stretch2::geometry::Size::undefined()).unwrap();
77    assert_eq!(stretch.layout(node).unwrap().size.width, 500f32);
78    assert_eq!(stretch.layout(node).unwrap().size.height, 500f32);
79    assert_eq!(stretch.layout(node).unwrap().location.x, 0f32);
80    assert_eq!(stretch.layout(node).unwrap().location.y, 0f32);
81    assert_eq!(stretch.layout(node0).unwrap().size.width, 70f32);
82    assert_eq!(stretch.layout(node0).unwrap().size.height, 90f32);
83    assert_eq!(stretch.layout(node0).unwrap().location.x, 0f32);
84    assert_eq!(stretch.layout(node0).unwrap().location.y, 0f32);
85    assert_eq!(stretch.layout(node00).unwrap().size.width, 40f32);
86    assert_eq!(stretch.layout(node00).unwrap().size.height, 40f32);
87    assert_eq!(stretch.layout(node00).unwrap().location.x, 0f32);
88    assert_eq!(stretch.layout(node00).unwrap().location.y, 0f32);
89    assert_eq!(stretch.layout(node000).unwrap().size.width, 40f32);
90    assert_eq!(stretch.layout(node000).unwrap().size.height, 40f32);
91    assert_eq!(stretch.layout(node000).unwrap().location.x, 0f32);
92    assert_eq!(stretch.layout(node000).unwrap().location.y, 0f32);
93    assert_eq!(stretch.layout(node01).unwrap().size.width, 40f32);
94    assert_eq!(stretch.layout(node01).unwrap().size.height, 40f32);
95    assert_eq!(stretch.layout(node01).unwrap().location.x, 0f32);
96    assert_eq!(stretch.layout(node01).unwrap().location.y, 50f32);
97    assert_eq!(stretch.layout(node010).unwrap().size.width, 40f32);
98    assert_eq!(stretch.layout(node010).unwrap().size.height, 40f32);
99    assert_eq!(stretch.layout(node010).unwrap().location.x, 0f32);
100    assert_eq!(stretch.layout(node010).unwrap().location.y, 0f32);
101}