⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227
tests/generated/flex/margin_auto_multiple_children_column.rs
Historia
Quién tocó qué
crudo
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn margin_auto_multiple_children_column__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, tree::Layout, TaffyTree};
6 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(50f32),
11 height: taffy::style::Dimension::Length(50f32),
12 },
13 margin: taffy::geometry::Rect {
14 left: zero(),
15 right: zero(),
16 top: taffy::style::LengthPercentageAuto::Auto,
17 bottom: zero(),
18 },
19 ..Default::default()
20 })
21 .unwrap();
22 let node1 = taffy
23 .new_leaf(taffy::style::Style {
24 size: taffy::geometry::Size {
25 width: taffy::style::Dimension::Length(50f32),
26 height: taffy::style::Dimension::Length(50f32),
27 },
28 margin: taffy::geometry::Rect {
29 left: zero(),
30 right: zero(),
31 top: taffy::style::LengthPercentageAuto::Auto,
32 bottom: zero(),
33 },
34 ..Default::default()
35 })
36 .unwrap();
37 let node2 = taffy
38 .new_leaf(taffy::style::Style {
39 size: taffy::geometry::Size {
40 width: taffy::style::Dimension::Length(50f32),
41 height: taffy::style::Dimension::Length(50f32),
42 },
43 ..Default::default()
44 })
45 .unwrap();
46 let node = taffy
47 .new_with_children(
48 taffy::style::Style {
49 flex_direction: taffy::style::FlexDirection::Column,
50 align_items: Some(taffy::style::AlignItems::Center),
51 size: taffy::geometry::Size {
52 width: taffy::style::Dimension::Length(200f32),
53 height: taffy::style::Dimension::Length(200f32),
54 },
55 ..Default::default()
56 },
57 &[node0, node1, node2],
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 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
65 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
66 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
67 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, 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 #[cfg(feature = "content_size")]
71 assert_eq!(
72 layout.scroll_width(),
73 0f32,
74 "scroll_width of node {:?}. Expected {}. Actual {}",
75 node,
76 0f32,
77 layout.scroll_width()
78 );
79 #[cfg(feature = "content_size")]
80 assert_eq!(
81 layout.scroll_height(),
82 0f32,
83 "scroll_height of node {:?}. Expected {}. Actual {}",
84 node,
85 0f32,
86 layout.scroll_height()
87 );
88 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
89 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
90 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
91 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
92 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node0, 75f32, location.x);
93 assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node0, 25f32, location.y);
94 #[cfg(feature = "content_size")]
95 assert_eq!(
96 layout.scroll_width(),
97 0f32,
98 "scroll_width of node {:?}. Expected {}. Actual {}",
99 node0,
100 0f32,
101 layout.scroll_width()
102 );
103 #[cfg(feature = "content_size")]
104 assert_eq!(
105 layout.scroll_height(),
106 0f32,
107 "scroll_height of node {:?}. Expected {}. Actual {}",
108 node0,
109 0f32,
110 layout.scroll_height()
111 );
112 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
113 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
114 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
115 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
116 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node1, 75f32, location.x);
117 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node1, 100f32, location.y);
118 #[cfg(feature = "content_size")]
119 assert_eq!(
120 layout.scroll_width(),
121 0f32,
122 "scroll_width of node {:?}. Expected {}. Actual {}",
123 node1,
124 0f32,
125 layout.scroll_width()
126 );
127 #[cfg(feature = "content_size")]
128 assert_eq!(
129 layout.scroll_height(),
130 0f32,
131 "scroll_height of node {:?}. Expected {}. Actual {}",
132 node1,
133 0f32,
134 layout.scroll_height()
135 );
136 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
137 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
138 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
139 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
140 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node2, 75f32, location.x);
141 assert_eq!(location.y, 150f32, "y of node {:?}. Expected {}. Actual {}", node2, 150f32, location.y);
142 #[cfg(feature = "content_size")]
143 assert_eq!(
144 layout.scroll_width(),
145 0f32,
146 "scroll_width of node {:?}. Expected {}. Actual {}",
147 node2,
148 0f32,
149 layout.scroll_width()
150 );
151 #[cfg(feature = "content_size")]
152 assert_eq!(
153 layout.scroll_height(),
154 0f32,
155 "scroll_height of node {:?}. Expected {}. Actual {}",
156 node2,
157 0f32,
158 layout.scroll_height()
159 );
160}
161
162#[test]
163#[allow(non_snake_case)]
164fn margin_auto_multiple_children_column__content_box() {
165 #[allow(unused_imports)]
166 use taffy::{prelude::*, tree::Layout, TaffyTree};
167 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
168 let node0 = taffy
169 .new_leaf(taffy::style::Style {
170 box_sizing: taffy::style::BoxSizing::ContentBox,
171 size: taffy::geometry::Size {
172 width: taffy::style::Dimension::Length(50f32),
173 height: taffy::style::Dimension::Length(50f32),
174 },
175 margin: taffy::geometry::Rect {
176 left: zero(),
177 right: zero(),
178 top: taffy::style::LengthPercentageAuto::Auto,
179 bottom: zero(),
180 },
181 ..Default::default()
182 })
183 .unwrap();
184 let node1 = taffy
185 .new_leaf(taffy::style::Style {
186 box_sizing: taffy::style::BoxSizing::ContentBox,
187 size: taffy::geometry::Size {
188 width: taffy::style::Dimension::Length(50f32),
189 height: taffy::style::Dimension::Length(50f32),
190 },
191 margin: taffy::geometry::Rect {
192 left: zero(),
193 right: zero(),
194 top: taffy::style::LengthPercentageAuto::Auto,
195 bottom: zero(),
196 },
197 ..Default::default()
198 })
199 .unwrap();
200 let node2 = taffy
201 .new_leaf(taffy::style::Style {
202 box_sizing: taffy::style::BoxSizing::ContentBox,
203 size: taffy::geometry::Size {
204 width: taffy::style::Dimension::Length(50f32),
205 height: taffy::style::Dimension::Length(50f32),
206 },
207 ..Default::default()
208 })
209 .unwrap();
210 let node = taffy
211 .new_with_children(
212 taffy::style::Style {
213 box_sizing: taffy::style::BoxSizing::ContentBox,
214 flex_direction: taffy::style::FlexDirection::Column,
215 align_items: Some(taffy::style::AlignItems::Center),
216 size: taffy::geometry::Size {
217 width: taffy::style::Dimension::Length(200f32),
218 height: taffy::style::Dimension::Length(200f32),
219 },
220 ..Default::default()
221 },
222 &[node0, node1, node2],
223 )
224 .unwrap();
225 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
226 println!("\nComputed tree:");
227 taffy.print_tree(node);
228 println!();
229 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
230 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
231 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
232 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
233 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
234 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
235 #[cfg(feature = "content_size")]
236 assert_eq!(
237 layout.scroll_width(),
238 0f32,
239 "scroll_width of node {:?}. Expected {}. Actual {}",
240 node,
241 0f32,
242 layout.scroll_width()
243 );
244 #[cfg(feature = "content_size")]
245 assert_eq!(
246 layout.scroll_height(),
247 0f32,
248 "scroll_height of node {:?}. Expected {}. Actual {}",
249 node,
250 0f32,
251 layout.scroll_height()
252 );
253 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
254 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
255 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
256 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
257 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node0, 75f32, location.x);
258 assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node0, 25f32, location.y);
259 #[cfg(feature = "content_size")]
260 assert_eq!(
261 layout.scroll_width(),
262 0f32,
263 "scroll_width of node {:?}. Expected {}. Actual {}",
264 node0,
265 0f32,
266 layout.scroll_width()
267 );
268 #[cfg(feature = "content_size")]
269 assert_eq!(
270 layout.scroll_height(),
271 0f32,
272 "scroll_height of node {:?}. Expected {}. Actual {}",
273 node0,
274 0f32,
275 layout.scroll_height()
276 );
277 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
278 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
279 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
280 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
281 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node1, 75f32, location.x);
282 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node1, 100f32, location.y);
283 #[cfg(feature = "content_size")]
284 assert_eq!(
285 layout.scroll_width(),
286 0f32,
287 "scroll_width of node {:?}. Expected {}. Actual {}",
288 node1,
289 0f32,
290 layout.scroll_width()
291 );
292 #[cfg(feature = "content_size")]
293 assert_eq!(
294 layout.scroll_height(),
295 0f32,
296 "scroll_height of node {:?}. Expected {}. Actual {}",
297 node1,
298 0f32,
299 layout.scroll_height()
300 );
301 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
302 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
303 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
304 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
305 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node2, 75f32, location.x);
306 assert_eq!(location.y, 150f32, "y of node {:?}. Expected {}. Actual {}", node2, 150f32, location.y);
307 #[cfg(feature = "content_size")]
308 assert_eq!(
309 layout.scroll_width(),
310 0f32,
311 "scroll_width of node {:?}. Expected {}. Actual {}",
312 node2,
313 0f32,
314 layout.scroll_width()
315 );
316 #[cfg(feature = "content_size")]
317 assert_eq!(
318 layout.scroll_height(),
319 0f32,
320 "scroll_height of node {:?}. Expected {}. Actual {}",
321 node2,
322 0f32,
323 layout.scroll_height()
324 );
325}