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