tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 500HTML 254C 19JavaScript 81398 Definiciones

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