gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5334Rust 85Markdown 12TOML 91813 Definitions

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/wrap_column.rs Rust · 368 lines · 14.6 KB History Who touched what raw

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

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