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