⎇ 25571b5d07206880207e451af69dd3b49b113628
tests/generated/flex/align_baseline.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn align_baseline__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, tree::Layout, TaffyTree};
6 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(50f32),
11 height: taffy::style::Dimension::Length(50f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node1 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::Length(50f32),
20 height: taffy::style::Dimension::Length(20f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node = taffy
26 .new_with_children(
27 taffy::style::Style {
28 align_items: Some(taffy::style::AlignItems::Baseline),
29 size: taffy::geometry::Size {
30 width: taffy::style::Dimension::Length(100f32),
31 height: taffy::style::Dimension::Length(100f32),
32 },
33 ..Default::default()
34 },
35 &[node0, node1],
36 )
37 .unwrap();
38 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
39 println!("\nComputed tree:");
40 taffy.print_tree(node);
41 println!();
42 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
43 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
44 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
45 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
46 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
47 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
48 #[cfg(feature = "content_size")]
49 assert_eq!(
50 layout.scroll_width(),
51 0f32,
52 "scroll_width of node {:?}. Expected {}. Actual {}",
53 node,
54 0f32,
55 layout.scroll_width()
56 );
57 #[cfg(feature = "content_size")]
58 assert_eq!(
59 layout.scroll_height(),
60 0f32,
61 "scroll_height of node {:?}. Expected {}. Actual {}",
62 node,
63 0f32,
64 layout.scroll_height()
65 );
66 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
67 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
68 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
69 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
70 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
71 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
72 #[cfg(feature = "content_size")]
73 assert_eq!(
74 layout.scroll_width(),
75 0f32,
76 "scroll_width of node {:?}. Expected {}. Actual {}",
77 node0,
78 0f32,
79 layout.scroll_width()
80 );
81 #[cfg(feature = "content_size")]
82 assert_eq!(
83 layout.scroll_height(),
84 0f32,
85 "scroll_height of node {:?}. Expected {}. Actual {}",
86 node0,
87 0f32,
88 layout.scroll_height()
89 );
90 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
91 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
92 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
93 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
94 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
95 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node1, 30f32, location.y);
96 #[cfg(feature = "content_size")]
97 assert_eq!(
98 layout.scroll_width(),
99 0f32,
100 "scroll_width of node {:?}. Expected {}. Actual {}",
101 node1,
102 0f32,
103 layout.scroll_width()
104 );
105 #[cfg(feature = "content_size")]
106 assert_eq!(
107 layout.scroll_height(),
108 0f32,
109 "scroll_height of node {:?}. Expected {}. Actual {}",
110 node1,
111 0f32,
112 layout.scroll_height()
113 );
114}
115
116#[test]
117#[allow(non_snake_case)]
118fn align_baseline__content_box() {
119 #[allow(unused_imports)]
120 use taffy::{prelude::*, tree::Layout, TaffyTree};
121 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
122 let node0 = taffy
123 .new_leaf(taffy::style::Style {
124 box_sizing: taffy::style::BoxSizing::ContentBox,
125 size: taffy::geometry::Size {
126 width: taffy::style::Dimension::Length(50f32),
127 height: taffy::style::Dimension::Length(50f32),
128 },
129 ..Default::default()
130 })
131 .unwrap();
132 let node1 = taffy
133 .new_leaf(taffy::style::Style {
134 box_sizing: taffy::style::BoxSizing::ContentBox,
135 size: taffy::geometry::Size {
136 width: taffy::style::Dimension::Length(50f32),
137 height: taffy::style::Dimension::Length(20f32),
138 },
139 ..Default::default()
140 })
141 .unwrap();
142 let node = taffy
143 .new_with_children(
144 taffy::style::Style {
145 box_sizing: taffy::style::BoxSizing::ContentBox,
146 align_items: Some(taffy::style::AlignItems::Baseline),
147 size: taffy::geometry::Size {
148 width: taffy::style::Dimension::Length(100f32),
149 height: taffy::style::Dimension::Length(100f32),
150 },
151 ..Default::default()
152 },
153 &[node0, node1],
154 )
155 .unwrap();
156 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
157 println!("\nComputed tree:");
158 taffy.print_tree(node);
159 println!();
160 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
161 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
162 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
163 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
164 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
165 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
166 #[cfg(feature = "content_size")]
167 assert_eq!(
168 layout.scroll_width(),
169 0f32,
170 "scroll_width of node {:?}. Expected {}. Actual {}",
171 node,
172 0f32,
173 layout.scroll_width()
174 );
175 #[cfg(feature = "content_size")]
176 assert_eq!(
177 layout.scroll_height(),
178 0f32,
179 "scroll_height of node {:?}. Expected {}. Actual {}",
180 node,
181 0f32,
182 layout.scroll_height()
183 );
184 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
185 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
186 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
187 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
188 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
189 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
190 #[cfg(feature = "content_size")]
191 assert_eq!(
192 layout.scroll_width(),
193 0f32,
194 "scroll_width of node {:?}. Expected {}. Actual {}",
195 node0,
196 0f32,
197 layout.scroll_width()
198 );
199 #[cfg(feature = "content_size")]
200 assert_eq!(
201 layout.scroll_height(),
202 0f32,
203 "scroll_height of node {:?}. Expected {}. Actual {}",
204 node0,
205 0f32,
206 layout.scroll_height()
207 );
208 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
209 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
210 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
211 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
212 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
213 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node1, 30f32, location.y);
214 #[cfg(feature = "content_size")]
215 assert_eq!(
216 layout.scroll_width(),
217 0f32,
218 "scroll_width of node {:?}. Expected {}. Actual {}",
219 node1,
220 0f32,
221 layout.scroll_width()
222 );
223 #[cfg(feature = "content_size")]
224 assert_eq!(
225 layout.scroll_height(),
226 0f32,
227 "scroll_height of node {:?}. Expected {}. Actual {}",
228 node1,
229 0f32,
230 layout.scroll_height()
231 );
232}