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