tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 238Markdown 7TOML 31453 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/block/block_absolute_layout_within_border.rs Rust · 258 siq'ikuna · 13.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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