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