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