tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5334Rust 85Markdown 12TOML 91813 Definiciones

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