gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1344 Definiciones

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/align_self_baseline.rs Rust · 307 líneas · 12.1 KB Historia Quién tocó qué crudo

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn align_self_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            align_self: Some(taffy::style::AlignSelf::Baseline),
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::Length(50f32),
12                height: taffy::style::Dimension::Length(50f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node10 = taffy
18        .new_leaf(taffy::style::Style {
19            size: taffy::geometry::Size {
20                width: taffy::style::Dimension::Length(50f32),
21                height: taffy::style::Dimension::Length(10f32),
22            },
23            ..Default::default()
24        })
25        .unwrap();
26    let node1 = taffy
27        .new_with_children(
28            taffy::style::Style {
29                align_self: Some(taffy::style::AlignSelf::Baseline),
30                size: taffy::geometry::Size {
31                    width: taffy::style::Dimension::Length(50f32),
32                    height: taffy::style::Dimension::Length(20f32),
33                },
34                ..Default::default()
35            },
36            &[node10],
37        )
38        .unwrap();
39    let node = taffy
40        .new_with_children(
41            taffy::style::Style {
42                size: taffy::geometry::Size {
43                    width: taffy::style::Dimension::Length(100f32),
44                    height: taffy::style::Dimension::Length(100f32),
45                },
46                ..Default::default()
47            },
48            &[node0, node1],
49        )
50        .unwrap();
51    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
52    println!("\nComputed tree:");
53    taffy.print_tree(node);
54    println!();
55    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
56    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
57    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
58    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
61    #[cfg(feature = "content_size")]
62    assert_eq!(
63        layout.scroll_width(),
64        0f32,
65        "scroll_width of node {:?}. Expected {}. Actual {}",
66        node,
67        0f32,
68        layout.scroll_width()
69    );
70    #[cfg(feature = "content_size")]
71    assert_eq!(
72        layout.scroll_height(),
73        0f32,
74        "scroll_height of node {:?}. Expected {}. Actual {}",
75        node,
76        0f32,
77        layout.scroll_height()
78    );
79    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
80    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
81    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
82    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
83    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
84    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
85    #[cfg(feature = "content_size")]
86    assert_eq!(
87        layout.scroll_width(),
88        0f32,
89        "scroll_width of node {:?}. Expected {}. Actual {}",
90        node0,
91        0f32,
92        layout.scroll_width()
93    );
94    #[cfg(feature = "content_size")]
95    assert_eq!(
96        layout.scroll_height(),
97        0f32,
98        "scroll_height of node {:?}. Expected {}. Actual {}",
99        node0,
100        0f32,
101        layout.scroll_height()
102    );
103    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
104    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
105    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
106    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
107    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
108    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
109    #[cfg(feature = "content_size")]
110    assert_eq!(
111        layout.scroll_width(),
112        0f32,
113        "scroll_width of node {:?}. Expected {}. Actual {}",
114        node1,
115        0f32,
116        layout.scroll_width()
117    );
118    #[cfg(feature = "content_size")]
119    assert_eq!(
120        layout.scroll_height(),
121        0f32,
122        "scroll_height of node {:?}. Expected {}. Actual {}",
123        node1,
124        0f32,
125        layout.scroll_height()
126    );
127    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
128    let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
129    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
130    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
131    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
132    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
133    #[cfg(feature = "content_size")]
134    assert_eq!(
135        layout.scroll_width(),
136        0f32,
137        "scroll_width of node {:?}. Expected {}. Actual {}",
138        node10,
139        0f32,
140        layout.scroll_width()
141    );
142    #[cfg(feature = "content_size")]
143    assert_eq!(
144        layout.scroll_height(),
145        0f32,
146        "scroll_height of node {:?}. Expected {}. Actual {}",
147        node10,
148        0f32,
149        layout.scroll_height()
150    );
151}
152
153#[test]
154#[allow(non_snake_case)]
155fn align_self_baseline__content_box() {
156    #[allow(unused_imports)]
157    use taffy::{prelude::*, tree::Layout, TaffyTree};
158    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
159    let node0 = taffy
160        .new_leaf(taffy::style::Style {
161            box_sizing: taffy::style::BoxSizing::ContentBox,
162            align_self: Some(taffy::style::AlignSelf::Baseline),
163            size: taffy::geometry::Size {
164                width: taffy::style::Dimension::Length(50f32),
165                height: taffy::style::Dimension::Length(50f32),
166            },
167            ..Default::default()
168        })
169        .unwrap();
170    let node10 = taffy
171        .new_leaf(taffy::style::Style {
172            box_sizing: taffy::style::BoxSizing::ContentBox,
173            size: taffy::geometry::Size {
174                width: taffy::style::Dimension::Length(50f32),
175                height: taffy::style::Dimension::Length(10f32),
176            },
177            ..Default::default()
178        })
179        .unwrap();
180    let node1 = taffy
181        .new_with_children(
182            taffy::style::Style {
183                box_sizing: taffy::style::BoxSizing::ContentBox,
184                align_self: Some(taffy::style::AlignSelf::Baseline),
185                size: taffy::geometry::Size {
186                    width: taffy::style::Dimension::Length(50f32),
187                    height: taffy::style::Dimension::Length(20f32),
188                },
189                ..Default::default()
190            },
191            &[node10],
192        )
193        .unwrap();
194    let node = taffy
195        .new_with_children(
196            taffy::style::Style {
197                box_sizing: taffy::style::BoxSizing::ContentBox,
198                size: taffy::geometry::Size {
199                    width: taffy::style::Dimension::Length(100f32),
200                    height: taffy::style::Dimension::Length(100f32),
201                },
202                ..Default::default()
203            },
204            &[node0, node1],
205        )
206        .unwrap();
207    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
208    println!("\nComputed tree:");
209    taffy.print_tree(node);
210    println!();
211    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
212    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
213    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
214    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
215    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
216    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
217    #[cfg(feature = "content_size")]
218    assert_eq!(
219        layout.scroll_width(),
220        0f32,
221        "scroll_width of node {:?}. Expected {}. Actual {}",
222        node,
223        0f32,
224        layout.scroll_width()
225    );
226    #[cfg(feature = "content_size")]
227    assert_eq!(
228        layout.scroll_height(),
229        0f32,
230        "scroll_height of node {:?}. Expected {}. Actual {}",
231        node,
232        0f32,
233        layout.scroll_height()
234    );
235    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
236    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
237    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
238    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
239    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
240    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
241    #[cfg(feature = "content_size")]
242    assert_eq!(
243        layout.scroll_width(),
244        0f32,
245        "scroll_width of node {:?}. Expected {}. Actual {}",
246        node0,
247        0f32,
248        layout.scroll_width()
249    );
250    #[cfg(feature = "content_size")]
251    assert_eq!(
252        layout.scroll_height(),
253        0f32,
254        "scroll_height of node {:?}. Expected {}. Actual {}",
255        node0,
256        0f32,
257        layout.scroll_height()
258    );
259    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
260    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
261    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
262    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
263    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
264    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
265    #[cfg(feature = "content_size")]
266    assert_eq!(
267        layout.scroll_width(),
268        0f32,
269        "scroll_width of node {:?}. Expected {}. Actual {}",
270        node1,
271        0f32,
272        layout.scroll_width()
273    );
274    #[cfg(feature = "content_size")]
275    assert_eq!(
276        layout.scroll_height(),
277        0f32,
278        "scroll_height of node {:?}. Expected {}. Actual {}",
279        node1,
280        0f32,
281        layout.scroll_height()
282    );
283    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
284    let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
285    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
286    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
287    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
288    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
289    #[cfg(feature = "content_size")]
290    assert_eq!(
291        layout.scroll_width(),
292        0f32,
293        "scroll_width of node {:?}. Expected {}. Actual {}",
294        node10,
295        0f32,
296        layout.scroll_width()
297    );
298    #[cfg(feature = "content_size")]
299    assert_eq!(
300        layout.scroll_height(),
301        0f32,
302        "scroll_height of node {:?}. Expected {}. Actual {}",
303        node10,
304        0f32,
305        layout.scroll_height()
306    );
307}