tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/align_content_center_single_line.rs Rust · 248 lines · 13.0 KB History Who touched what raw

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

1#[test]
2#[allow(non_snake_case)]
3fn align_content_center_single_line__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 {
10                width: taffy::style::Dimension::from_length(50f32),
11                height: taffy::style::Dimension::from_length(10f32),
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::from_length(50f32),
20                height: taffy::style::Dimension::from_length(10f32),
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::from_length(50f32),
29                height: taffy::style::Dimension::from_length(10f32),
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::from_length(50f32),
38                height: taffy::style::Dimension::from_length(10f32),
39            },
40            ..Default::default()
41        })
42        .unwrap();
43    let node4 = taffy
44        .new_leaf(taffy::style::Style {
45            size: taffy::geometry::Size {
46                width: taffy::style::Dimension::from_length(50f32),
47                height: taffy::style::Dimension::from_length(10f32),
48            },
49            ..Default::default()
50        })
51        .unwrap();
52    let node5 = taffy
53        .new_leaf(taffy::style::Style {
54            size: taffy::geometry::Size {
55                width: taffy::style::Dimension::from_length(50f32),
56                height: taffy::style::Dimension::from_length(10f32),
57            },
58            ..Default::default()
59        })
60        .unwrap();
61    let node = taffy
62        .new_with_children(
63            taffy::style::Style {
64                align_content: Some(taffy::style::AlignContent::Center),
65                size: taffy::geometry::Size {
66                    width: taffy::style::Dimension::from_length(120f32),
67                    height: taffy::style::Dimension::from_length(100f32),
68                },
69                ..Default::default()
70            },
71            &[node0, node1, node2, node3, node4, node5],
72        )
73        .unwrap();
74    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
75    println!("\nComputed tree:");
76    taffy.print_tree(node);
77    println!();
78    let layout = taffy.layout(node).unwrap();
79    let Layout { size, location, .. } = layout;
80    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
81    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
82    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
83    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
84    let layout = taffy.layout(node0).unwrap();
85    let Layout { size, location, .. } = layout;
86    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
87    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
88    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
89    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
90    let layout = taffy.layout(node1).unwrap();
91    let Layout { size, location, .. } = layout;
92    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
93    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
94    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node1, 20f32, location.x);
95    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
96    let layout = taffy.layout(node2).unwrap();
97    let Layout { size, location, .. } = layout;
98    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
99    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
100    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node2, 40f32, location.x);
101    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
102    let layout = taffy.layout(node3).unwrap();
103    let Layout { size, location, .. } = layout;
104    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
105    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
106    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node3, 60f32, location.x);
107    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
108    let layout = taffy.layout(node4).unwrap();
109    let Layout { size, location, .. } = layout;
110    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
111    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node4, 10f32, size.height);
112    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node4, 80f32, location.x);
113    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
114    let layout = taffy.layout(node5).unwrap();
115    let Layout { size, location, .. } = layout;
116    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
117    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node5, 10f32, size.height);
118    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node5, 100f32, location.x);
119    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node5, 0f32, location.y);
120}
121
122#[test]
123#[allow(non_snake_case)]
124fn align_content_center_single_line__content_box() {
125    #[allow(unused_imports)]
126    use taffy::{prelude::*, Layout};
127    let mut taffy = crate::new_test_tree();
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::from_length(50f32),
133                height: taffy::style::Dimension::from_length(10f32),
134            },
135            ..Default::default()
136        })
137        .unwrap();
138    let node1 = taffy
139        .new_leaf(taffy::style::Style {
140            box_sizing: taffy::style::BoxSizing::ContentBox,
141            size: taffy::geometry::Size {
142                width: taffy::style::Dimension::from_length(50f32),
143                height: taffy::style::Dimension::from_length(10f32),
144            },
145            ..Default::default()
146        })
147        .unwrap();
148    let node2 = taffy
149        .new_leaf(taffy::style::Style {
150            box_sizing: taffy::style::BoxSizing::ContentBox,
151            size: taffy::geometry::Size {
152                width: taffy::style::Dimension::from_length(50f32),
153                height: taffy::style::Dimension::from_length(10f32),
154            },
155            ..Default::default()
156        })
157        .unwrap();
158    let node3 = taffy
159        .new_leaf(taffy::style::Style {
160            box_sizing: taffy::style::BoxSizing::ContentBox,
161            size: taffy::geometry::Size {
162                width: taffy::style::Dimension::from_length(50f32),
163                height: taffy::style::Dimension::from_length(10f32),
164            },
165            ..Default::default()
166        })
167        .unwrap();
168    let node4 = taffy
169        .new_leaf(taffy::style::Style {
170            box_sizing: taffy::style::BoxSizing::ContentBox,
171            size: taffy::geometry::Size {
172                width: taffy::style::Dimension::from_length(50f32),
173                height: taffy::style::Dimension::from_length(10f32),
174            },
175            ..Default::default()
176        })
177        .unwrap();
178    let node5 = taffy
179        .new_leaf(taffy::style::Style {
180            box_sizing: taffy::style::BoxSizing::ContentBox,
181            size: taffy::geometry::Size {
182                width: taffy::style::Dimension::from_length(50f32),
183                height: taffy::style::Dimension::from_length(10f32),
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_content: Some(taffy::style::AlignContent::Center),
193                size: taffy::geometry::Size {
194                    width: taffy::style::Dimension::from_length(120f32),
195                    height: taffy::style::Dimension::from_length(100f32),
196                },
197                ..Default::default()
198            },
199            &[node0, node1, node2, node3, node4, node5],
200        )
201        .unwrap();
202    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
203    println!("\nComputed tree:");
204    taffy.print_tree(node);
205    println!();
206    let layout = taffy.layout(node).unwrap();
207    let Layout { size, location, .. } = layout;
208    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
209    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
210    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
211    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
212    let layout = taffy.layout(node0).unwrap();
213    let Layout { size, location, .. } = layout;
214    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
215    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
216    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
217    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
218    let layout = taffy.layout(node1).unwrap();
219    let Layout { size, location, .. } = layout;
220    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
221    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
222    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node1, 20f32, location.x);
223    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
224    let layout = taffy.layout(node2).unwrap();
225    let Layout { size, location, .. } = layout;
226    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
227    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
228    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node2, 40f32, location.x);
229    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
230    let layout = taffy.layout(node3).unwrap();
231    let Layout { size, location, .. } = layout;
232    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
233    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
234    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node3, 60f32, location.x);
235    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
236    let layout = taffy.layout(node4).unwrap();
237    let Layout { size, location, .. } = layout;
238    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
239    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node4, 10f32, size.height);
240    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node4, 80f32, location.x);
241    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
242    let layout = taffy.layout(node5).unwrap();
243    let Layout { size, location, .. } = layout;
244    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5, 20f32, size.width);
245    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node5, 10f32, size.height);
246    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node5, 100f32, location.x);
247    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node5, 0f32, location.y);
248}