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