gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Sutichaykuna

⎇ 0.4.x tests/generated/grid/grid_absolute_with_padding.rs Rust · 298 siq'ikuna · 12.7 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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