tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 498HTML 254C 19JavaScript 81349 Definitions

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/grid/grid_percent_items_nested_with_padding_margin.rs Rust · 249 lines · 12.0 KB History Who touched what raw

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn grid_percent_items_nested_with_padding_margin__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node000 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(0.45f32), height: auto() },
10            margin: taffy::geometry::Rect {
11                left: percent(0.05f32),
12                right: percent(0.05f32),
13                top: percent(0.05f32),
14                bottom: percent(0.05f32),
15            },
16            padding: taffy::geometry::Rect {
17                left: length(3f32),
18                right: length(3f32),
19                top: length(3f32),
20                bottom: length(3f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node00 = taffy
26        .new_with_children(
27            taffy::style::Style {
28                display: taffy::style::Display::Grid,
29                size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(0.5f32), height: auto() },
30                margin: taffy::geometry::Rect {
31                    left: length(5f32),
32                    right: length(5f32),
33                    top: length(5f32),
34                    bottom: length(5f32),
35                },
36                padding: taffy::geometry::Rect {
37                    left: percent(0.03f32),
38                    right: percent(0.03f32),
39                    top: percent(0.03f32),
40                    bottom: percent(0.03f32),
41                },
42                ..Default::default()
43            },
44            &[node000],
45        )
46        .unwrap();
47    let node0 = taffy
48        .new_with_children(
49            taffy::style::Style {
50                display: taffy::style::Display::Grid,
51                min_size: taffy::geometry::Size {
52                    width: taffy::style::Dimension::from_percent(0.6f32),
53                    height: auto(),
54                },
55                margin: taffy::geometry::Rect {
56                    left: length(5f32),
57                    right: length(5f32),
58                    top: length(5f32),
59                    bottom: length(5f32),
60                },
61                padding: taffy::geometry::Rect {
62                    left: length(3f32),
63                    right: length(3f32),
64                    top: length(3f32),
65                    bottom: length(3f32),
66                },
67                ..Default::default()
68            },
69            &[node00],
70        )
71        .unwrap();
72    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
73    let node = taffy
74        .new_with_children(
75            taffy::style::Style {
76                display: taffy::style::Display::Grid,
77                grid_template_rows: vec![fr(1f32), fr(4f32)],
78                size: taffy::geometry::Size {
79                    width: taffy::style::Dimension::from_length(200f32),
80                    height: taffy::style::Dimension::from_length(200f32),
81                },
82                ..Default::default()
83            },
84            &[node0, node1],
85        )
86        .unwrap();
87    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
88    println!("\nComputed tree:");
89    taffy.print_tree(node);
90    println!();
91    let layout = taffy.layout(node).unwrap();
92    let Layout { size, location, .. } = layout;
93    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
94    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
97    let layout = taffy.layout(node0).unwrap();
98    let Layout { size, location, .. } = layout;
99    assert_eq!(size.width, 190f32, "width of node {:?}. Expected {}. Actual {}", node0, 190f32, size.width);
100    assert_eq!(size.height, 41f32, "height of node {:?}. Expected {}. Actual {}", node0, 41f32, size.height);
101    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
102    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
103    let layout = taffy.layout(node00).unwrap();
104    let Layout { size, location, .. } = layout;
105    assert_eq!(size.width, 92f32, "width of node {:?}. Expected {}. Actual {}", node00, 92f32, size.width);
106    assert_eq!(size.height, 25f32, "height of node {:?}. Expected {}. Actual {}", node00, 25f32, size.height);
107    assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node00, 8f32, location.x);
108    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node00, 8f32, location.y);
109    let layout = taffy.layout(node000).unwrap();
110    let Layout { size, location, .. } = layout;
111    assert_eq!(size.width, 36f32, "width of node {:?}. Expected {}. Actual {}", node000, 36f32, size.width);
112    assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node000, 6f32, size.height);
113    assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node000, 10f32, location.x);
114    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node000, 10f32, location.y);
115    let layout = taffy.layout(node1).unwrap();
116    let Layout { size, location, .. } = layout;
117    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1, 200f32, size.width);
118    assert_eq!(size.height, 149f32, "height of node {:?}. Expected {}. Actual {}", node1, 149f32, size.height);
119    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
120    assert_eq!(location.y, 51f32, "y of node {:?}. Expected {}. Actual {}", node1, 51f32, location.y);
121}
122
123#[test]
124#[allow(non_snake_case)]
125fn grid_percent_items_nested_with_padding_margin__content_box() {
126    #[allow(unused_imports)]
127    use taffy::{prelude::*, Layout};
128    let mut taffy = crate::new_test_tree();
129    let node000 = taffy
130        .new_leaf(taffy::style::Style {
131            box_sizing: taffy::style::BoxSizing::ContentBox,
132            size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(0.45f32), height: auto() },
133            margin: taffy::geometry::Rect {
134                left: percent(0.05f32),
135                right: percent(0.05f32),
136                top: percent(0.05f32),
137                bottom: percent(0.05f32),
138            },
139            padding: taffy::geometry::Rect {
140                left: length(3f32),
141                right: length(3f32),
142                top: length(3f32),
143                bottom: length(3f32),
144            },
145            ..Default::default()
146        })
147        .unwrap();
148    let node00 = taffy
149        .new_with_children(
150            taffy::style::Style {
151                display: taffy::style::Display::Grid,
152                box_sizing: taffy::style::BoxSizing::ContentBox,
153                size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(0.5f32), height: auto() },
154                margin: taffy::geometry::Rect {
155                    left: length(5f32),
156                    right: length(5f32),
157                    top: length(5f32),
158                    bottom: length(5f32),
159                },
160                padding: taffy::geometry::Rect {
161                    left: percent(0.03f32),
162                    right: percent(0.03f32),
163                    top: percent(0.03f32),
164                    bottom: percent(0.03f32),
165                },
166                ..Default::default()
167            },
168            &[node000],
169        )
170        .unwrap();
171    let node0 = taffy
172        .new_with_children(
173            taffy::style::Style {
174                display: taffy::style::Display::Grid,
175                box_sizing: taffy::style::BoxSizing::ContentBox,
176                min_size: taffy::geometry::Size {
177                    width: taffy::style::Dimension::from_percent(0.6f32),
178                    height: auto(),
179                },
180                margin: taffy::geometry::Rect {
181                    left: length(5f32),
182                    right: length(5f32),
183                    top: length(5f32),
184                    bottom: length(5f32),
185                },
186                padding: taffy::geometry::Rect {
187                    left: length(3f32),
188                    right: length(3f32),
189                    top: length(3f32),
190                    bottom: length(3f32),
191                },
192                ..Default::default()
193            },
194            &[node00],
195        )
196        .unwrap();
197    let node1 = taffy
198        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
199        .unwrap();
200    let node = taffy
201        .new_with_children(
202            taffy::style::Style {
203                display: taffy::style::Display::Grid,
204                box_sizing: taffy::style::BoxSizing::ContentBox,
205                grid_template_rows: vec![fr(1f32), fr(4f32)],
206                size: taffy::geometry::Size {
207                    width: taffy::style::Dimension::from_length(200f32),
208                    height: taffy::style::Dimension::from_length(200f32),
209                },
210                ..Default::default()
211            },
212            &[node0, node1],
213        )
214        .unwrap();
215    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
216    println!("\nComputed tree:");
217    taffy.print_tree(node);
218    println!();
219    let layout = taffy.layout(node).unwrap();
220    let Layout { size, location, .. } = layout;
221    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
222    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
223    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
224    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
225    let layout = taffy.layout(node0).unwrap();
226    let Layout { size, location, .. } = layout;
227    assert_eq!(size.width, 190f32, "width of node {:?}. Expected {}. Actual {}", node0, 190f32, size.width);
228    assert_eq!(size.height, 42f32, "height of node {:?}. Expected {}. Actual {}", node0, 42f32, size.height);
229    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
230    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
231    let layout = taffy.layout(node00).unwrap();
232    let Layout { size, location, .. } = layout;
233    assert_eq!(size.width, 103f32, "width of node {:?}. Expected {}. Actual {}", node00, 103f32, size.width);
234    assert_eq!(size.height, 26f32, "height of node {:?}. Expected {}. Actual {}", node00, 26f32, size.height);
235    assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node00, 8f32, location.x);
236    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node00, 8f32, location.y);
237    let layout = taffy.layout(node000).unwrap();
238    let Layout { size, location, .. } = layout;
239    assert_eq!(size.width, 48f32, "width of node {:?}. Expected {}. Actual {}", node000, 48f32, size.width);
240    assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node000, 6f32, size.height);
241    assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node000, 10f32, location.x);
242    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node000, 10f32, location.y);
243    let layout = taffy.layout(node1).unwrap();
244    let Layout { size, location, .. } = layout;
245    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1, 200f32, size.width);
246    assert_eq!(size.height, 148f32, "height of node {:?}. Expected {}. Actual {}", node1, 148f32, size.height);
247    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
248    assert_eq!(location.y, 52f32, "y of node {:?}. Expected {}. Actual {}", node1, 52f32, location.y);
249}