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