gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Definiciones

⎇ 0.4.x tests/generated/grid/grid_absolute_container_top_bottom.rs Rust · 287 líneas · 12.3 KB Historia Quién tocó qué crudo

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

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