tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

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