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