⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2
tests/generated/grid/grid_absolute_top_overrides_bottom.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_top_overrides_bottom__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 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
11 inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(2f32), bottom: length(5f32) },
12 ..Default::default()
13 })
14 .unwrap();
15 let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
16 let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
17 let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
18 let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
19 let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
20 let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
21 let node7 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
22 let node8 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
23 let node = taffy
24 .new_with_children(
25 taffy::style::Style {
26 display: taffy::style::Display::Grid,
27 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
28 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
29 padding: taffy::geometry::Rect {
30 left: length(40f32),
31 right: length(20f32),
32 top: length(10f32),
33 bottom: length(30f32),
34 },
35 ..Default::default()
36 },
37 &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
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 let layout = taffy.layout(node).unwrap();
45 let Layout { size, location, .. } = layout;
46 assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node, 180f32, size.width);
47 assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node, 160f32, 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 let layout = taffy.layout(node0).unwrap();
51 let Layout { size, location, .. } = layout;
52 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
53 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
54 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
55 assert_eq!(location.y, 2f32, "y of node {:?}. Expected {}. Actual {}", node0, 2f32, location.y);
56 let layout = taffy.layout(node1).unwrap();
57 let Layout { size, location, .. } = layout;
58 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
59 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
60 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
61 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
62 let layout = taffy.layout(node2).unwrap();
63 let Layout { size, location, .. } = layout;
64 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
65 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
66 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node2, 80f32, location.x);
67 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node2, 10f32, location.y);
68 let layout = taffy.layout(node3).unwrap();
69 let Layout { size, location, .. } = layout;
70 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
71 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
72 assert_eq!(location.x, 120f32, "x of node {:?}. Expected {}. Actual {}", node3, 120f32, location.x);
73 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node3, 10f32, location.y);
74 let layout = taffy.layout(node4).unwrap();
75 let Layout { size, location, .. } = layout;
76 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node4, 40f32, size.width);
77 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4, 40f32, size.height);
78 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node4, 40f32, location.x);
79 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node4, 50f32, location.y);
80 let layout = taffy.layout(node5).unwrap();
81 let Layout { size, location, .. } = layout;
82 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node5, 40f32, size.width);
83 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
84 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node5, 80f32, location.x);
85 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node5, 50f32, location.y);
86 let layout = taffy.layout(node6).unwrap();
87 let Layout { size, location, .. } = layout;
88 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node6, 40f32, size.width);
89 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node6, 40f32, size.height);
90 assert_eq!(location.x, 120f32, "x of node {:?}. Expected {}. Actual {}", node6, 120f32, location.x);
91 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node6, 50f32, location.y);
92 let layout = taffy.layout(node7).unwrap();
93 let Layout { size, location, .. } = layout;
94 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node7, 40f32, size.width);
95 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node7, 40f32, size.height);
96 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7, 40f32, location.x);
97 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node7, 90f32, location.y);
98 let layout = taffy.layout(node8).unwrap();
99 let Layout { size, location, .. } = layout;
100 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node8, 40f32, size.width);
101 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node8, 40f32, size.height);
102 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node8, 80f32, location.x);
103 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node8, 90f32, location.y);
104}
105
106#[test]
107#[allow(non_snake_case)]
108fn grid_absolute_top_overrides_bottom__content_box() {
109 #[allow(unused_imports)]
110 use taffy::{prelude::*, Layout};
111 let mut taffy = crate::new_test_tree();
112 let node0 = taffy
113 .new_leaf(taffy::style::Style {
114 box_sizing: taffy::style::BoxSizing::ContentBox,
115 position: taffy::style::Position::Absolute,
116 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
117 inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(2f32), bottom: length(5f32) },
118 ..Default::default()
119 })
120 .unwrap();
121 let node1 = taffy
122 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
123 .unwrap();
124 let node2 = taffy
125 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
126 .unwrap();
127 let node3 = taffy
128 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
129 .unwrap();
130 let node4 = taffy
131 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
132 .unwrap();
133 let node5 = taffy
134 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
135 .unwrap();
136 let node6 = taffy
137 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
138 .unwrap();
139 let node7 = taffy
140 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
141 .unwrap();
142 let node8 = taffy
143 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
144 .unwrap();
145 let node = taffy
146 .new_with_children(
147 taffy::style::Style {
148 display: taffy::style::Display::Grid,
149 box_sizing: taffy::style::BoxSizing::ContentBox,
150 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
151 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
152 padding: taffy::geometry::Rect {
153 left: length(40f32),
154 right: length(20f32),
155 top: length(10f32),
156 bottom: length(30f32),
157 },
158 ..Default::default()
159 },
160 &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
161 )
162 .unwrap();
163 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
164 println!("\nComputed tree:");
165 taffy.print_tree(node);
166 println!();
167 let layout = taffy.layout(node).unwrap();
168 let Layout { size, location, .. } = layout;
169 assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node, 180f32, size.width);
170 assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node, 160f32, size.height);
171 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
172 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
173 let layout = taffy.layout(node0).unwrap();
174 let Layout { size, location, .. } = layout;
175 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
176 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
177 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
178 assert_eq!(location.y, 2f32, "y of node {:?}. Expected {}. Actual {}", node0, 2f32, location.y);
179 let layout = taffy.layout(node1).unwrap();
180 let Layout { size, location, .. } = layout;
181 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
182 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
183 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
184 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
185 let layout = taffy.layout(node2).unwrap();
186 let Layout { size, location, .. } = layout;
187 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
188 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
189 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node2, 80f32, location.x);
190 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node2, 10f32, location.y);
191 let layout = taffy.layout(node3).unwrap();
192 let Layout { size, location, .. } = layout;
193 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
194 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
195 assert_eq!(location.x, 120f32, "x of node {:?}. Expected {}. Actual {}", node3, 120f32, location.x);
196 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node3, 10f32, location.y);
197 let layout = taffy.layout(node4).unwrap();
198 let Layout { size, location, .. } = layout;
199 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node4, 40f32, size.width);
200 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4, 40f32, size.height);
201 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node4, 40f32, location.x);
202 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node4, 50f32, location.y);
203 let layout = taffy.layout(node5).unwrap();
204 let Layout { size, location, .. } = layout;
205 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node5, 40f32, size.width);
206 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
207 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node5, 80f32, location.x);
208 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node5, 50f32, location.y);
209 let layout = taffy.layout(node6).unwrap();
210 let Layout { size, location, .. } = layout;
211 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node6, 40f32, size.width);
212 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node6, 40f32, size.height);
213 assert_eq!(location.x, 120f32, "x of node {:?}. Expected {}. Actual {}", node6, 120f32, location.x);
214 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node6, 50f32, location.y);
215 let layout = taffy.layout(node7).unwrap();
216 let Layout { size, location, .. } = layout;
217 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node7, 40f32, size.width);
218 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node7, 40f32, size.height);
219 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7, 40f32, location.x);
220 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node7, 90f32, location.y);
221 let layout = taffy.layout(node8).unwrap();
222 let Layout { size, location, .. } = layout;
223 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node8, 40f32, size.width);
224 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node8, 40f32, size.height);
225 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node8, 80f32, location.x);
226 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node8, 90f32, location.y);
227}