tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definiciones

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