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