tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

⎇ fd9112585b697975a342fdb76ca5b263a2b62891 tests/generated/block/block_margin_y_collapse_complex.rs Rust · 299 líneas · 12.3 KB Historia Quién tocó qué crudo

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

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