⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227
tests/generated/flex/percent_absolute_position.rs
History
Who touched what
raw
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn percent_absolute_position__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, tree::Layout, TaffyTree};
6 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7 let node00 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: auto() },
10 ..Default::default()
11 })
12 .unwrap();
13 let node01 = taffy
14 .new_leaf(taffy::style::Style {
15 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: auto() },
16 ..Default::default()
17 })
18 .unwrap();
19 let node0 = taffy
20 .new_with_children(
21 taffy::style::Style {
22 position: taffy::style::Position::Absolute,
23 size: taffy::geometry::Size {
24 width: taffy::style::Dimension::Percent(1f32),
25 height: taffy::style::Dimension::Length(50f32),
26 },
27 inset: taffy::geometry::Rect {
28 left: taffy::style::LengthPercentageAuto::Percent(0.5f32),
29 right: auto(),
30 top: auto(),
31 bottom: auto(),
32 },
33 ..Default::default()
34 },
35 &[node00, node01],
36 )
37 .unwrap();
38 let node = taffy
39 .new_with_children(
40 taffy::style::Style {
41 flex_direction: taffy::style::FlexDirection::Column,
42 size: taffy::geometry::Size {
43 width: taffy::style::Dimension::Length(60f32),
44 height: taffy::style::Dimension::Length(50f32),
45 },
46 ..Default::default()
47 },
48 &[node0],
49 )
50 .unwrap();
51 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
52 println!("\nComputed tree:");
53 taffy.print_tree(node);
54 println!();
55 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
56 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
57 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
58 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
59 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
60 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
61 #[cfg(feature = "content_size")]
62 assert_eq!(
63 layout.scroll_width(),
64 30f32,
65 "scroll_width of node {:?}. Expected {}. Actual {}",
66 node,
67 30f32,
68 layout.scroll_width()
69 );
70 #[cfg(feature = "content_size")]
71 assert_eq!(
72 layout.scroll_height(),
73 0f32,
74 "scroll_height of node {:?}. Expected {}. Actual {}",
75 node,
76 0f32,
77 layout.scroll_height()
78 );
79 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
80 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
81 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
82 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
83 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node0, 30f32, location.x);
84 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
85 #[cfg(feature = "content_size")]
86 assert_eq!(
87 layout.scroll_width(),
88 0f32,
89 "scroll_width of node {:?}. Expected {}. Actual {}",
90 node0,
91 0f32,
92 layout.scroll_width()
93 );
94 #[cfg(feature = "content_size")]
95 assert_eq!(
96 layout.scroll_height(),
97 0f32,
98 "scroll_height of node {:?}. Expected {}. Actual {}",
99 node0,
100 0f32,
101 layout.scroll_height()
102 );
103 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
104 let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
105 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node00, 30f32, size.width);
106 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
107 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
108 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
109 #[cfg(feature = "content_size")]
110 assert_eq!(
111 layout.scroll_width(),
112 0f32,
113 "scroll_width of node {:?}. Expected {}. Actual {}",
114 node00,
115 0f32,
116 layout.scroll_width()
117 );
118 #[cfg(feature = "content_size")]
119 assert_eq!(
120 layout.scroll_height(),
121 0f32,
122 "scroll_height of node {:?}. Expected {}. Actual {}",
123 node00,
124 0f32,
125 layout.scroll_height()
126 );
127 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
128 let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
129 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node01, 30f32, size.width);
130 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node01, 50f32, size.height);
131 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node01, 30f32, location.x);
132 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
133 #[cfg(feature = "content_size")]
134 assert_eq!(
135 layout.scroll_width(),
136 0f32,
137 "scroll_width of node {:?}. Expected {}. Actual {}",
138 node01,
139 0f32,
140 layout.scroll_width()
141 );
142 #[cfg(feature = "content_size")]
143 assert_eq!(
144 layout.scroll_height(),
145 0f32,
146 "scroll_height of node {:?}. Expected {}. Actual {}",
147 node01,
148 0f32,
149 layout.scroll_height()
150 );
151}
152
153#[test]
154#[allow(non_snake_case)]
155fn percent_absolute_position__content_box() {
156 #[allow(unused_imports)]
157 use taffy::{prelude::*, tree::Layout, TaffyTree};
158 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
159 let node00 = taffy
160 .new_leaf(taffy::style::Style {
161 box_sizing: taffy::style::BoxSizing::ContentBox,
162 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: auto() },
163 ..Default::default()
164 })
165 .unwrap();
166 let node01 = taffy
167 .new_leaf(taffy::style::Style {
168 box_sizing: taffy::style::BoxSizing::ContentBox,
169 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: auto() },
170 ..Default::default()
171 })
172 .unwrap();
173 let node0 = taffy
174 .new_with_children(
175 taffy::style::Style {
176 box_sizing: taffy::style::BoxSizing::ContentBox,
177 position: taffy::style::Position::Absolute,
178 size: taffy::geometry::Size {
179 width: taffy::style::Dimension::Percent(1f32),
180 height: taffy::style::Dimension::Length(50f32),
181 },
182 inset: taffy::geometry::Rect {
183 left: taffy::style::LengthPercentageAuto::Percent(0.5f32),
184 right: auto(),
185 top: auto(),
186 bottom: auto(),
187 },
188 ..Default::default()
189 },
190 &[node00, node01],
191 )
192 .unwrap();
193 let node = taffy
194 .new_with_children(
195 taffy::style::Style {
196 box_sizing: taffy::style::BoxSizing::ContentBox,
197 flex_direction: taffy::style::FlexDirection::Column,
198 size: taffy::geometry::Size {
199 width: taffy::style::Dimension::Length(60f32),
200 height: taffy::style::Dimension::Length(50f32),
201 },
202 ..Default::default()
203 },
204 &[node0],
205 )
206 .unwrap();
207 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
208 println!("\nComputed tree:");
209 taffy.print_tree(node);
210 println!();
211 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
212 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
213 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
214 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
215 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
216 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
217 #[cfg(feature = "content_size")]
218 assert_eq!(
219 layout.scroll_width(),
220 30f32,
221 "scroll_width of node {:?}. Expected {}. Actual {}",
222 node,
223 30f32,
224 layout.scroll_width()
225 );
226 #[cfg(feature = "content_size")]
227 assert_eq!(
228 layout.scroll_height(),
229 0f32,
230 "scroll_height of node {:?}. Expected {}. Actual {}",
231 node,
232 0f32,
233 layout.scroll_height()
234 );
235 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
236 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
237 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
238 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
239 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node0, 30f32, location.x);
240 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 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 node0,
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 node0,
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(node00).unwrap();
261 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node00, 30f32, size.width);
262 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
263 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
264 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
265 #[cfg(feature = "content_size")]
266 assert_eq!(
267 layout.scroll_width(),
268 0f32,
269 "scroll_width of node {:?}. Expected {}. Actual {}",
270 node00,
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 node00,
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(node01).unwrap();
285 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node01, 30f32, size.width);
286 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node01, 50f32, size.height);
287 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node01, 30f32, location.x);
288 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
289 #[cfg(feature = "content_size")]
290 assert_eq!(
291 layout.scroll_width(),
292 0f32,
293 "scroll_width of node {:?}. Expected {}. Actual {}",
294 node01,
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 node01,
304 0f32,
305 layout.scroll_height()
306 );
307}