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