gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definitions

⎇ 0.4.x tests/generated/grid/grid_out_of_order_items.rs Rust · 303 lines · 13.0 KB History Who touched what raw

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

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