⎇ 0.4.x
tests/generated/grid/grid_percent_tracks_indefinite_with_content_underflow.rs
Historia
Quién tocó qué
crudo
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn grid_percent_tracks_indefinite_with_content_underflow() {
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_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
9 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
10 size: taffy::geometry::Size {
11 width: taffy::style::Dimension::Length(100f32),
12 height: taffy::style::Dimension::Length(100f32),
13 },
14 ..Default::default()
15 })
16 .unwrap();
17 let node1 = taffy
18 .new_leaf(taffy::style::Style {
19 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
20 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
21 ..Default::default()
22 })
23 .unwrap();
24 let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
25 let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
26 let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
27 let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
28 let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
29 let node = taffy
30 .new_with_children(
31 taffy::style::Style {
32 display: taffy::style::Display::Grid,
33 grid_template_rows: vec![percent(0.3f32), percent(0.6f32)],
34 grid_template_columns: vec![percent(0.1f32), percent(0.2f32), percent(0.3f32)],
35 ..Default::default()
36 },
37 &[node0, node1, node2, node3, node4, node5, node6],
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, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, 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(node1).unwrap();
94 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node1, 10f32, size.width);
95 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
96 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
97 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 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 node1,
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 node1,
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(node2).unwrap();
118 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
119 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
120 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node2, 10f32, location.x);
121 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 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 node2,
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 node2,
137 0f32,
138 layout.scroll_height()
139 );
140 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
141 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
142 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node3, 30f32, size.width);
143 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node3, 30f32, size.height);
144 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node3, 30f32, location.x);
145 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
146 #[cfg(feature = "content_size")]
147 assert_eq!(
148 layout.scroll_width(),
149 0f32,
150 "scroll_width of node {:?}. Expected {}. Actual {}",
151 node3,
152 0f32,
153 layout.scroll_width()
154 );
155 #[cfg(feature = "content_size")]
156 assert_eq!(
157 layout.scroll_height(),
158 0f32,
159 "scroll_height of node {:?}. Expected {}. Actual {}",
160 node3,
161 0f32,
162 layout.scroll_height()
163 );
164 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
165 let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
166 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node4, 10f32, size.width);
167 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node4, 60f32, size.height);
168 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
169 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node4, 30f32, location.y);
170 #[cfg(feature = "content_size")]
171 assert_eq!(
172 layout.scroll_width(),
173 0f32,
174 "scroll_width of node {:?}. Expected {}. Actual {}",
175 node4,
176 0f32,
177 layout.scroll_width()
178 );
179 #[cfg(feature = "content_size")]
180 assert_eq!(
181 layout.scroll_height(),
182 0f32,
183 "scroll_height of node {:?}. Expected {}. Actual {}",
184 node4,
185 0f32,
186 layout.scroll_height()
187 );
188 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
189 let layout @ Layout { size, location, .. } = taffy.layout(node5).unwrap();
190 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
191 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node5, 60f32, size.height);
192 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node5, 10f32, location.x);
193 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node5, 30f32, location.y);
194 #[cfg(feature = "content_size")]
195 assert_eq!(
196 layout.scroll_width(),
197 0f32,
198 "scroll_width of node {:?}. Expected {}. Actual {}",
199 node5,
200 0f32,
201 layout.scroll_width()
202 );
203 #[cfg(feature = "content_size")]
204 assert_eq!(
205 layout.scroll_height(),
206 0f32,
207 "scroll_height of node {:?}. Expected {}. Actual {}",
208 node5,
209 0f32,
210 layout.scroll_height()
211 );
212 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
213 let layout @ Layout { size, location, .. } = taffy.layout(node6).unwrap();
214 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node6, 30f32, size.width);
215 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node6, 60f32, size.height);
216 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node6, 30f32, location.x);
217 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node6, 30f32, location.y);
218 #[cfg(feature = "content_size")]
219 assert_eq!(
220 layout.scroll_width(),
221 0f32,
222 "scroll_width of node {:?}. Expected {}. Actual {}",
223 node6,
224 0f32,
225 layout.scroll_width()
226 );
227 #[cfg(feature = "content_size")]
228 assert_eq!(
229 layout.scroll_height(),
230 0f32,
231 "scroll_height of node {:?}. Expected {}. Actual {}",
232 node6,
233 0f32,
234 layout.scroll_height()
235 );
236}