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