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