⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2
tests/generated/grid/grid_max_content_single_item_margin_percent.rs
History
Who touched what
raw
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn grid_max_content_single_item_margin_percent__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8 let node1 = taffy
9 .new_leaf_with_context(
10 taffy::style::Style {
11 margin: taffy::geometry::Rect {
12 left: percent(0.2f32),
13 right: percent(0.1f32),
14 top: percent(0.05f32),
15 bottom: percent(0.15f32),
16 },
17 ..Default::default()
18 },
19 crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
20 )
21 .unwrap();
22 let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
23 let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
24 let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
25 let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
26 let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
27 let node7 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
28 let node8 = 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![length(40f32), length(40f32), length(40f32)],
34 grid_template_columns: vec![length(40f32), max_content(), length(40f32)],
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, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
47 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, 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, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
53 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
54 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
55 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
56 let layout = taffy.layout(node1).unwrap();
57 let Layout { size, location, .. } = layout;
58 assert_eq!(size.width, 28f32, "width of node {:?}. Expected {}. Actual {}", node1, 28f32, size.width);
59 assert_eq!(size.height, 32f32, "height of node {:?}. Expected {}. Actual {}", node1, 32f32, size.height);
60 assert_eq!(location.x, 48f32, "x of node {:?}. Expected {}. Actual {}", node1, 48f32, location.x);
61 assert_eq!(location.y, 2f32, "y of node {:?}. Expected {}. Actual {}", node1, 2f32, 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, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, 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, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
73 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, 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, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, 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, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, 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, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
91 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, 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, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, 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, 80f32, "y of node {:?}. Expected {}. Actual {}", node8, 80f32, location.y);
104}
105
106#[test]
107#[allow(non_snake_case)]
108fn grid_max_content_single_item_margin_percent__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 { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
114 .unwrap();
115 let node1 = taffy
116 .new_leaf_with_context(
117 taffy::style::Style {
118 box_sizing: taffy::style::BoxSizing::ContentBox,
119 margin: taffy::geometry::Rect {
120 left: percent(0.2f32),
121 right: percent(0.1f32),
122 top: percent(0.05f32),
123 bottom: percent(0.15f32),
124 },
125 ..Default::default()
126 },
127 crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
128 )
129 .unwrap();
130 let node2 = taffy
131 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
132 .unwrap();
133 let node3 = taffy
134 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
135 .unwrap();
136 let node4 = taffy
137 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
138 .unwrap();
139 let node5 = taffy
140 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
141 .unwrap();
142 let node6 = taffy
143 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
144 .unwrap();
145 let node7 = taffy
146 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
147 .unwrap();
148 let node8 = taffy
149 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
150 .unwrap();
151 let node = taffy
152 .new_with_children(
153 taffy::style::Style {
154 display: taffy::style::Display::Grid,
155 box_sizing: taffy::style::BoxSizing::ContentBox,
156 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
157 grid_template_columns: vec![length(40f32), max_content(), length(40f32)],
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, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
170 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, 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, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
176 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
177 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
178 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
179 let layout = taffy.layout(node1).unwrap();
180 let Layout { size, location, .. } = layout;
181 assert_eq!(size.width, 28f32, "width of node {:?}. Expected {}. Actual {}", node1, 28f32, size.width);
182 assert_eq!(size.height, 32f32, "height of node {:?}. Expected {}. Actual {}", node1, 32f32, size.height);
183 assert_eq!(location.x, 48f32, "x of node {:?}. Expected {}. Actual {}", node1, 48f32, location.x);
184 assert_eq!(location.y, 2f32, "y of node {:?}. Expected {}. Actual {}", node1, 2f32, 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, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, 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, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
196 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, 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, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, 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, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, 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, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
214 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, 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, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, 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, 80f32, "y of node {:?}. Expected {}. Actual {}", node8, 80f32, location.y);
227}