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