⎇ 25571b5d07206880207e451af69dd3b49b113628
tests/generated/flex/gap_row_gap_column_child_margins.rs
History
Who touched what
raw
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn gap_row_gap_column_child_margins__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 flex_grow: 1f32,
10 flex_shrink: 1f32,
11 flex_basis: taffy::style::Dimension::Percent(0f32),
12 margin: taffy::geometry::Rect {
13 left: zero(),
14 right: zero(),
15 top: taffy::style::LengthPercentageAuto::Length(2f32),
16 bottom: taffy::style::LengthPercentageAuto::Length(2f32),
17 },
18 ..Default::default()
19 })
20 .unwrap();
21 let node1 = taffy
22 .new_leaf(taffy::style::Style {
23 flex_grow: 1f32,
24 flex_shrink: 1f32,
25 flex_basis: taffy::style::Dimension::Percent(0f32),
26 margin: taffy::geometry::Rect {
27 left: zero(),
28 right: zero(),
29 top: taffy::style::LengthPercentageAuto::Length(10f32),
30 bottom: taffy::style::LengthPercentageAuto::Length(10f32),
31 },
32 ..Default::default()
33 })
34 .unwrap();
35 let node2 = taffy
36 .new_leaf(taffy::style::Style {
37 flex_grow: 1f32,
38 flex_shrink: 1f32,
39 flex_basis: taffy::style::Dimension::Percent(0f32),
40 margin: taffy::geometry::Rect {
41 left: zero(),
42 right: zero(),
43 top: taffy::style::LengthPercentageAuto::Length(15f32),
44 bottom: taffy::style::LengthPercentageAuto::Length(15f32),
45 },
46 ..Default::default()
47 })
48 .unwrap();
49 let node = taffy
50 .new_with_children(
51 taffy::style::Style {
52 flex_direction: taffy::style::FlexDirection::Column,
53 gap: taffy::geometry::Size { width: zero(), height: taffy::style::LengthPercentage::Length(10f32) },
54 size: taffy::geometry::Size {
55 width: taffy::style::Dimension::Length(100f32),
56 height: taffy::style::Dimension::Length(200f32),
57 },
58 ..Default::default()
59 },
60 &[node0, node1, node2],
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, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
94 assert_eq!(size.height, 42f32, "height of node {:?}. Expected {}. Actual {}", node0, 42f32, size.height);
95 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
96 assert_eq!(location.y, 2f32, "y of node {:?}. Expected {}. Actual {}", node0, 2f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
118 assert_eq!(size.height, 42f32, "height of node {:?}. Expected {}. Actual {}", node1, 42f32, size.height);
119 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
120 assert_eq!(location.y, 66f32, "y of node {:?}. Expected {}. Actual {}", node1, 66f32, location.y);
121 #[cfg(feature = "content_size")]
122 assert_eq!(
123 layout.scroll_width(),
124 0f32,
125 "scroll_width of node {:?}. Expected {}. Actual {}",
126 node1,
127 0f32,
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(node2).unwrap();
141 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
142 assert_eq!(size.height, 42f32, "height of node {:?}. Expected {}. Actual {}", node2, 42f32, size.height);
143 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
144 assert_eq!(location.y, 143f32, "y of node {:?}. Expected {}. Actual {}", node2, 143f32, location.y);
145 #[cfg(feature = "content_size")]
146 assert_eq!(
147 layout.scroll_width(),
148 0f32,
149 "scroll_width of node {:?}. Expected {}. Actual {}",
150 node2,
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 node2,
160 0f32,
161 layout.scroll_height()
162 );
163}
164
165#[test]
166#[allow(non_snake_case)]
167fn gap_row_gap_column_child_margins__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 flex_grow: 1f32,
175 flex_shrink: 1f32,
176 flex_basis: taffy::style::Dimension::Percent(0f32),
177 margin: taffy::geometry::Rect {
178 left: zero(),
179 right: zero(),
180 top: taffy::style::LengthPercentageAuto::Length(2f32),
181 bottom: taffy::style::LengthPercentageAuto::Length(2f32),
182 },
183 ..Default::default()
184 })
185 .unwrap();
186 let node1 = taffy
187 .new_leaf(taffy::style::Style {
188 box_sizing: taffy::style::BoxSizing::ContentBox,
189 flex_grow: 1f32,
190 flex_shrink: 1f32,
191 flex_basis: taffy::style::Dimension::Percent(0f32),
192 margin: taffy::geometry::Rect {
193 left: zero(),
194 right: zero(),
195 top: taffy::style::LengthPercentageAuto::Length(10f32),
196 bottom: taffy::style::LengthPercentageAuto::Length(10f32),
197 },
198 ..Default::default()
199 })
200 .unwrap();
201 let node2 = taffy
202 .new_leaf(taffy::style::Style {
203 box_sizing: taffy::style::BoxSizing::ContentBox,
204 flex_grow: 1f32,
205 flex_shrink: 1f32,
206 flex_basis: taffy::style::Dimension::Percent(0f32),
207 margin: taffy::geometry::Rect {
208 left: zero(),
209 right: zero(),
210 top: taffy::style::LengthPercentageAuto::Length(15f32),
211 bottom: taffy::style::LengthPercentageAuto::Length(15f32),
212 },
213 ..Default::default()
214 })
215 .unwrap();
216 let node = taffy
217 .new_with_children(
218 taffy::style::Style {
219 box_sizing: taffy::style::BoxSizing::ContentBox,
220 flex_direction: taffy::style::FlexDirection::Column,
221 gap: taffy::geometry::Size { width: zero(), height: taffy::style::LengthPercentage::Length(10f32) },
222 size: taffy::geometry::Size {
223 width: taffy::style::Dimension::Length(100f32),
224 height: taffy::style::Dimension::Length(200f32),
225 },
226 ..Default::default()
227 },
228 &[node0, node1, node2],
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, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
238 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
262 assert_eq!(size.height, 42f32, "height of node {:?}. Expected {}. Actual {}", node0, 42f32, size.height);
263 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
264 assert_eq!(location.y, 2f32, "y of node {:?}. Expected {}. Actual {}", node0, 2f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
286 assert_eq!(size.height, 42f32, "height of node {:?}. Expected {}. Actual {}", node1, 42f32, size.height);
287 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
288 assert_eq!(location.y, 66f32, "y of node {:?}. Expected {}. Actual {}", node1, 66f32, 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(node2).unwrap();
309 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
310 assert_eq!(size.height, 42f32, "height of node {:?}. Expected {}. Actual {}", node2, 42f32, size.height);
311 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
312 assert_eq!(location.y, 143f32, "y of node {:?}. Expected {}. Actual {}", node2, 143f32, location.y);
313 #[cfg(feature = "content_size")]
314 assert_eq!(
315 layout.scroll_width(),
316 0f32,
317 "scroll_width of node {:?}. Expected {}. Actual {}",
318 node2,
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 node2,
328 0f32,
329 layout.scroll_height()
330 );
331}