gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 87Markdown 12TOML 91924 Definitions

⎇ 0.3.x tests/generated/gap_column_gap_row_gap_wrapping.rs Rust · 156 lines · 8.7 KB History Who touched what raw

Import yoga tests (#320) e05b9093d · Nico Burns ·

1#[test]
2fn gap_column_gap_row_gap_wrapping() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Points(20f32),
11                height: taffy::style::Dimension::Points(20f32),
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::Points(20f32),
20                height: taffy::style::Dimension::Points(20f32),
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::Points(20f32),
29                height: taffy::style::Dimension::Points(20f32),
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::Points(20f32),
38                height: taffy::style::Dimension::Points(20f32),
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::Points(20f32),
47                height: taffy::style::Dimension::Points(20f32),
48            },
49            ..Default::default()
50        })
51        .unwrap();
52    let node5 = taffy
53        .new_leaf(taffy::style::Style {
54            size: taffy::geometry::Size {
55                width: taffy::style::Dimension::Points(20f32),
56                height: taffy::style::Dimension::Points(20f32),
57            },
58            ..Default::default()
59        })
60        .unwrap();
61    let node6 = taffy
62        .new_leaf(taffy::style::Style {
63            size: taffy::geometry::Size {
64                width: taffy::style::Dimension::Points(20f32),
65                height: taffy::style::Dimension::Points(20f32),
66            },
67            ..Default::default()
68        })
69        .unwrap();
70    let node7 = taffy
71        .new_leaf(taffy::style::Style {
72            size: taffy::geometry::Size {
73                width: taffy::style::Dimension::Points(20f32),
74                height: taffy::style::Dimension::Points(20f32),
75            },
76            ..Default::default()
77        })
78        .unwrap();
79    let node8 = taffy
80        .new_leaf(taffy::style::Style {
81            size: taffy::geometry::Size {
82                width: taffy::style::Dimension::Points(20f32),
83                height: taffy::style::Dimension::Points(20f32),
84            },
85            ..Default::default()
86        })
87        .unwrap();
88    let node = taffy
89        .new_with_children(
90            taffy::style::Style {
91                flex_wrap: taffy::style::FlexWrap::Wrap,
92                gap: taffy::geometry::Size {
93                    width: taffy::style::LengthPercentage::Points(10f32),
94                    height: taffy::style::LengthPercentage::Points(20f32),
95                },
96                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(80f32), height: auto() },
97                ..Default::default()
98            },
99            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
100        )
101        .unwrap();
102    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
103    println!("\nComputed tree:");
104    taffy::debug::print_tree(&taffy, node);
105    println!();
106    let Layout { size, location, .. } = taffy.layout(node).unwrap();
107    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 80f32, size.width);
108    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
109    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
110    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
111    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
112    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
113    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
114    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
115    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
116    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
117    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.width);
118    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
119    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 30f32, location.x);
120    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
121    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
122    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.width);
123    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.height);
124    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 60f32, location.x);
125    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
126    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
127    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 20f32, size.width);
128    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 20f32, size.height);
129    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 0f32, location.x);
130    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 40f32, location.y);
131    let Layout { size, location, .. } = taffy.layout(node4).unwrap();
132    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4.data(), 20f32, size.width);
133    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4.data(), 20f32, size.height);
134    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4.data(), 30f32, location.x);
135    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4.data(), 40f32, location.y);
136    let Layout { size, location, .. } = taffy.layout(node5).unwrap();
137    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5.data(), 20f32, size.width);
138    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node5.data(), 20f32, size.height);
139    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node5.data(), 60f32, location.x);
140    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5.data(), 40f32, location.y);
141    let Layout { size, location, .. } = taffy.layout(node6).unwrap();
142    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6.data(), 20f32, size.width);
143    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6.data(), 20f32, size.height);
144    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6.data(), 0f32, location.x);
145    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6.data(), 80f32, location.y);
146    let Layout { size, location, .. } = taffy.layout(node7).unwrap();
147    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node7.data(), 20f32, size.width);
148    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node7.data(), 20f32, size.height);
149    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node7.data(), 30f32, location.x);
150    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7.data(), 80f32, location.y);
151    let Layout { size, location, .. } = taffy.layout(node8).unwrap();
152    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node8.data(), 20f32, size.width);
153    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node8.data(), 20f32, size.height);
154    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node8.data(), 60f32, location.x);
155    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node8.data(), 80f32, location.y);
156}