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