Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn align_baseline_child_padding__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 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::from_length(50f32),
11 height: taffy::style::Dimension::from_length(50f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node10 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::from_length(50f32),
20 height: taffy::style::Dimension::from_length(10f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node1 = taffy
26 .new_with_children(
27 taffy::style::Style {
28 flex_direction: taffy::style::FlexDirection::Column,
29 size: taffy::geometry::Size {
30 width: taffy::style::Dimension::from_length(50f32),
31 height: taffy::style::Dimension::from_length(20f32),
32 },
33 padding: taffy::geometry::Rect {
34 left: length(5f32),
35 right: length(5f32),
36 top: length(5f32),
37 bottom: length(5f32),
38 },
39 ..Default::default()
40 },
41 &[node10],
42 )
43 .unwrap();
44 let node = taffy
45 .new_with_children(
46 taffy::style::Style {
47 align_items: Some(taffy::style::AlignItems::Baseline),
48 size: taffy::geometry::Size {
49 width: taffy::style::Dimension::from_length(100f32),
50 height: taffy::style::Dimension::from_length(100f32),
51 },
52 padding: taffy::geometry::Rect {
53 left: length(5f32),
54 right: length(5f32),
55 top: length(5f32),
56 bottom: length(5f32),
57 },
58 ..Default::default()
59 },
60 &[node0, node1],
61 )
62 .unwrap();
63 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
64 println!("\nComputed tree:");
65 taffy.print_tree(node);
66 println!();
67 let layout = taffy.layout(node).unwrap();
68 let Layout { size, location, .. } = layout;
69 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
70 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
71 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
72 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
73 let layout = taffy.layout(node0).unwrap();
74 let Layout { size, location, .. } = layout;
75 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
76 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
77 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
78 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
79 let layout = taffy.layout(node1).unwrap();
80 let Layout { size, location, .. } = layout;
81 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
82 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
83 assert_eq!(location.x, 45f32, "x of node {:?}. Expected {}. Actual {}", node1, 45f32, location.x);
84 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
85 let layout = taffy.layout(node10).unwrap();
86 let Layout { size, location, .. } = layout;
87 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
88 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
89 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node10, 5f32, location.x);
90 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node10, 5f32, location.y);
91}
92
93#[test]
94#[allow(non_snake_case)]
95fn align_baseline_child_padding__content_box() {
96 #[allow(unused_imports)]
97 use taffy::{prelude::*, Layout};
98 let mut taffy = crate::new_test_tree();
99 let node0 = taffy
100 .new_leaf(taffy::style::Style {
101 box_sizing: taffy::style::BoxSizing::ContentBox,
102 size: taffy::geometry::Size {
103 width: taffy::style::Dimension::from_length(50f32),
104 height: taffy::style::Dimension::from_length(50f32),
105 },
106 ..Default::default()
107 })
108 .unwrap();
109 let node10 = taffy
110 .new_leaf(taffy::style::Style {
111 box_sizing: taffy::style::BoxSizing::ContentBox,
112 size: taffy::geometry::Size {
113 width: taffy::style::Dimension::from_length(50f32),
114 height: taffy::style::Dimension::from_length(10f32),
115 },
116 ..Default::default()
117 })
118 .unwrap();
119 let node1 = taffy
120 .new_with_children(
121 taffy::style::Style {
122 box_sizing: taffy::style::BoxSizing::ContentBox,
123 flex_direction: taffy::style::FlexDirection::Column,
124 size: taffy::geometry::Size {
125 width: taffy::style::Dimension::from_length(50f32),
126 height: taffy::style::Dimension::from_length(20f32),
127 },
128 padding: taffy::geometry::Rect {
129 left: length(5f32),
130 right: length(5f32),
131 top: length(5f32),
132 bottom: length(5f32),
133 },
134 ..Default::default()
135 },
136 &[node10],
137 )
138 .unwrap();
139 let node = taffy
140 .new_with_children(
141 taffy::style::Style {
142 box_sizing: taffy::style::BoxSizing::ContentBox,
143 align_items: Some(taffy::style::AlignItems::Baseline),
144 size: taffy::geometry::Size {
145 width: taffy::style::Dimension::from_length(100f32),
146 height: taffy::style::Dimension::from_length(100f32),
147 },
148 padding: taffy::geometry::Rect {
149 left: length(5f32),
150 right: length(5f32),
151 top: length(5f32),
152 bottom: length(5f32),
153 },
154 ..Default::default()
155 },
156 &[node0, node1],
157 )
158 .unwrap();
159 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
160 println!("\nComputed tree:");
161 taffy.print_tree(node);
162 println!();
163 let layout = taffy.layout(node).unwrap();
164 let Layout { size, location, .. } = layout;
165 assert_eq!(size.width, 110f32, "width of node {:?}. Expected {}. Actual {}", node, 110f32, size.width);
166 assert_eq!(size.height, 110f32, "height of node {:?}. Expected {}. Actual {}", node, 110f32, size.height);
167 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
168 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
169 let layout = taffy.layout(node0).unwrap();
170 let Layout { size, location, .. } = layout;
171 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
172 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
173 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
174 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
175 let layout = taffy.layout(node1).unwrap();
176 let Layout { size, location, .. } = layout;
177 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1, 60f32, size.width);
178 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
179 assert_eq!(location.x, 45f32, "x of node {:?}. Expected {}. Actual {}", node1, 45f32, location.x);
180 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
181 let layout = taffy.layout(node10).unwrap();
182 let Layout { size, location, .. } = layout;
183 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
184 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
185 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node10, 5f32, location.x);
186 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node10, 5f32, location.y);
187}