tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1345 Sutichaykuna

⎇ 40dd6120fc73aa866f30e52a51d1abaf39adce6f tests/generated/flex/gap_row_gap_align_items_stretch.rs Rust · 218 siq'ikuna · 12.5 KB Ñawpa willay Pi imata llamkarqan ch'uya

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn gap_row_gap_align_items_stretch__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
10            ..Default::default()
11        })
12        .unwrap();
13    let node1 = taffy
14        .new_leaf(taffy::style::Style {
15            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
16            ..Default::default()
17        })
18        .unwrap();
19    let node2 = taffy
20        .new_leaf(taffy::style::Style {
21            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
22            ..Default::default()
23        })
24        .unwrap();
25    let node3 = taffy
26        .new_leaf(taffy::style::Style {
27            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
28            ..Default::default()
29        })
30        .unwrap();
31    let node4 = taffy
32        .new_leaf(taffy::style::Style {
33            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
34            ..Default::default()
35        })
36        .unwrap();
37    let node5 = taffy
38        .new_leaf(taffy::style::Style {
39            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
40            ..Default::default()
41        })
42        .unwrap();
43    let node = taffy
44        .new_with_children(
45            taffy::style::Style {
46                flex_wrap: taffy::style::FlexWrap::Wrap,
47                align_items: Some(taffy::style::AlignItems::Stretch),
48                align_content: Some(taffy::style::AlignContent::Stretch),
49                gap: taffy::geometry::Size { width: length(10f32), height: length(20f32) },
50                size: taffy::geometry::Size {
51                    width: taffy::style::Dimension::from_length(100f32),
52                    height: taffy::style::Dimension::from_length(200f32),
53                },
54                ..Default::default()
55            },
56            &[node0, node1, node2, node3, node4, node5],
57        )
58        .unwrap();
59    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
60    println!("\nComputed tree:");
61    taffy.print_tree(node);
62    println!();
63    let layout = taffy.layout(node).unwrap();
64    let Layout { size, location, .. } = layout;
65    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
66    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
67    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
68    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
69    let layout = taffy.layout(node0).unwrap();
70    let Layout { size, location, .. } = layout;
71    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
72    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node0, 90f32, size.height);
73    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
74    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
75    let layout = taffy.layout(node1).unwrap();
76    let Layout { size, location, .. } = layout;
77    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
78    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node1, 90f32, size.height);
79    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
80    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
81    let layout = taffy.layout(node2).unwrap();
82    let Layout { size, location, .. } = layout;
83    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
84    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node2, 90f32, size.height);
85    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
86    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
87    let layout = taffy.layout(node3).unwrap();
88    let Layout { size, location, .. } = layout;
89    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
90    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node3, 90f32, size.height);
91    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
92    assert_eq!(location.y, 110f32, "y of node {:?}. Expected {}. Actual {}", node3, 110f32, location.y);
93    let layout = taffy.layout(node4).unwrap();
94    let Layout { size, location, .. } = layout;
95    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
96    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node4, 90f32, size.height);
97    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4, 30f32, location.x);
98    assert_eq!(location.y, 110f32, "y of node {:?}. Expected {}. Actual {}", node4, 110f32, location.y);
99    let layout = taffy.layout(node5).unwrap();
100    let Layout { size, location, .. } = layout;
101    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
102    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node5, 90f32, size.height);
103    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node5, 60f32, location.x);
104    assert_eq!(location.y, 110f32, "y of node {:?}. Expected {}. Actual {}", node5, 110f32, location.y);
105}
106
107#[test]
108#[allow(non_snake_case)]
109fn gap_row_gap_align_items_stretch__content_box() {
110    #[allow(unused_imports)]
111    use taffy::{prelude::*, Layout};
112    let mut taffy = crate::new_test_tree();
113    let node0 = taffy
114        .new_leaf(taffy::style::Style {
115            box_sizing: taffy::style::BoxSizing::ContentBox,
116            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
117            ..Default::default()
118        })
119        .unwrap();
120    let node1 = taffy
121        .new_leaf(taffy::style::Style {
122            box_sizing: taffy::style::BoxSizing::ContentBox,
123            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
124            ..Default::default()
125        })
126        .unwrap();
127    let node2 = taffy
128        .new_leaf(taffy::style::Style {
129            box_sizing: taffy::style::BoxSizing::ContentBox,
130            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
131            ..Default::default()
132        })
133        .unwrap();
134    let node3 = taffy
135        .new_leaf(taffy::style::Style {
136            box_sizing: taffy::style::BoxSizing::ContentBox,
137            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
138            ..Default::default()
139        })
140        .unwrap();
141    let node4 = taffy
142        .new_leaf(taffy::style::Style {
143            box_sizing: taffy::style::BoxSizing::ContentBox,
144            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
145            ..Default::default()
146        })
147        .unwrap();
148    let node5 = taffy
149        .new_leaf(taffy::style::Style {
150            box_sizing: taffy::style::BoxSizing::ContentBox,
151            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
152            ..Default::default()
153        })
154        .unwrap();
155    let node = taffy
156        .new_with_children(
157            taffy::style::Style {
158                box_sizing: taffy::style::BoxSizing::ContentBox,
159                flex_wrap: taffy::style::FlexWrap::Wrap,
160                align_items: Some(taffy::style::AlignItems::Stretch),
161                align_content: Some(taffy::style::AlignContent::Stretch),
162                gap: taffy::geometry::Size { width: length(10f32), height: length(20f32) },
163                size: taffy::geometry::Size {
164                    width: taffy::style::Dimension::from_length(100f32),
165                    height: taffy::style::Dimension::from_length(200f32),
166                },
167                ..Default::default()
168            },
169            &[node0, node1, node2, node3, node4, node5],
170        )
171        .unwrap();
172    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
173    println!("\nComputed tree:");
174    taffy.print_tree(node);
175    println!();
176    let layout = taffy.layout(node).unwrap();
177    let Layout { size, location, .. } = layout;
178    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
179    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
180    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
181    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
182    let layout = taffy.layout(node0).unwrap();
183    let Layout { size, location, .. } = layout;
184    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
185    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node0, 90f32, size.height);
186    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
187    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
188    let layout = taffy.layout(node1).unwrap();
189    let Layout { size, location, .. } = layout;
190    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
191    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node1, 90f32, size.height);
192    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
193    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
194    let layout = taffy.layout(node2).unwrap();
195    let Layout { size, location, .. } = layout;
196    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
197    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node2, 90f32, size.height);
198    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
199    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
200    let layout = taffy.layout(node3).unwrap();
201    let Layout { size, location, .. } = layout;
202    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
203    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node3, 90f32, size.height);
204    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
205    assert_eq!(location.y, 110f32, "y of node {:?}. Expected {}. Actual {}", node3, 110f32, location.y);
206    let layout = taffy.layout(node4).unwrap();
207    let Layout { size, location, .. } = layout;
208    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
209    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node4, 90f32, size.height);
210    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4, 30f32, location.x);
211    assert_eq!(location.y, 110f32, "y of node {:?}. Expected {}. Actual {}", node4, 110f32, location.y);
212    let layout = taffy.layout(node5).unwrap();
213    let Layout { size, location, .. } = layout;
214    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
215    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node5, 90f32, size.height);
216    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node5, 60f32, location.x);
217    assert_eq!(location.y, 110f32, "y of node {:?}. Expected {}. Actual {}", node5, 110f32, location.y);
218}