tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 735HTML 687Markdown 12TOML 62433 Definiciones

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/grid/grid_absolute_container_negative_position_margin.rs Rust · 260 líneas · 16.1 KB Historia Quién tocó qué crudo

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

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