tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 520HTML 244Markdown 7TOML 41339 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/align_baseline_multiline.rs Rust · 266 siq'ikuna · 13.6 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 align_baseline_multiline__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(50f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node10 = 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 node1 = taffy
26        .new_with_children(
27            taffy::style::Style {
28                flex_direction: taffy::style::FlexDirection::Column,
29                size: taffy::geometry::Size {
30                    width: taffy::style::Dimension::from_length(50f32),
31                    height: taffy::style::Dimension::from_length(20f32),
32                },
33                ..Default::default()
34            },
35            &[node10],
36        )
37        .unwrap();
38    let node20 = taffy
39        .new_leaf(taffy::style::Style {
40            size: taffy::geometry::Size {
41                width: taffy::style::Dimension::from_length(50f32),
42                height: taffy::style::Dimension::from_length(10f32),
43            },
44            ..Default::default()
45        })
46        .unwrap();
47    let node2 = taffy
48        .new_with_children(
49            taffy::style::Style {
50                flex_direction: taffy::style::FlexDirection::Column,
51                size: taffy::geometry::Size {
52                    width: taffy::style::Dimension::from_length(50f32),
53                    height: taffy::style::Dimension::from_length(20f32),
54                },
55                ..Default::default()
56            },
57            &[node20],
58        )
59        .unwrap();
60    let node3 = taffy
61        .new_leaf(taffy::style::Style {
62            size: taffy::geometry::Size {
63                width: taffy::style::Dimension::from_length(50f32),
64                height: taffy::style::Dimension::from_length(50f32),
65            },
66            ..Default::default()
67        })
68        .unwrap();
69    let node = taffy
70        .new_with_children(
71            taffy::style::Style {
72                flex_wrap: taffy::style::FlexWrap::Wrap,
73                align_items: Some(taffy::style::AlignItems::Baseline),
74                size: taffy::geometry::Size {
75                    width: taffy::style::Dimension::from_length(100f32),
76                    height: taffy::style::Dimension::from_length(100f32),
77                },
78                ..Default::default()
79            },
80            &[node0, node1, node2, node3],
81        )
82        .unwrap();
83    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
84    println!("\nComputed tree:");
85    taffy.print_tree(node);
86    println!();
87    let layout = taffy.layout(node).unwrap();
88    let Layout { size, location, .. } = layout;
89    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
90    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
91    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
92    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
93    let layout = taffy.layout(node0).unwrap();
94    let Layout { size, location, .. } = layout;
95    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
96    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
97    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
98    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
99    let layout = taffy.layout(node1).unwrap();
100    let Layout { size, location, .. } = layout;
101    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
102    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
103    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
104    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
105    let layout = taffy.layout(node10).unwrap();
106    let Layout { size, location, .. } = layout;
107    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
108    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
109    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
110    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
111    let layout = taffy.layout(node2).unwrap();
112    let Layout { size, location, .. } = layout;
113    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
114    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
115    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
116    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node2, 100f32, location.y);
117    let layout = taffy.layout(node20).unwrap();
118    let Layout { size, location, .. } = layout;
119    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node20, 50f32, size.width);
120    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20, 10f32, size.height);
121    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node20, 0f32, location.x);
122    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20, 0f32, location.y);
123    let layout = taffy.layout(node3).unwrap();
124    let Layout { size, location, .. } = layout;
125    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
126    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3, 50f32, size.height);
127    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
128    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node3, 60f32, location.y);
129}
130
131#[test]
132#[allow(non_snake_case)]
133fn align_baseline_multiline__content_box() {
134    #[allow(unused_imports)]
135    use taffy::{prelude::*, Layout};
136    let mut taffy = crate::new_test_tree();
137    let node0 = taffy
138        .new_leaf(taffy::style::Style {
139            box_sizing: taffy::style::BoxSizing::ContentBox,
140            size: taffy::geometry::Size {
141                width: taffy::style::Dimension::from_length(50f32),
142                height: taffy::style::Dimension::from_length(50f32),
143            },
144            ..Default::default()
145        })
146        .unwrap();
147    let node10 = taffy
148        .new_leaf(taffy::style::Style {
149            box_sizing: taffy::style::BoxSizing::ContentBox,
150            size: taffy::geometry::Size {
151                width: taffy::style::Dimension::from_length(50f32),
152                height: taffy::style::Dimension::from_length(10f32),
153            },
154            ..Default::default()
155        })
156        .unwrap();
157    let node1 = taffy
158        .new_with_children(
159            taffy::style::Style {
160                box_sizing: taffy::style::BoxSizing::ContentBox,
161                flex_direction: taffy::style::FlexDirection::Column,
162                size: taffy::geometry::Size {
163                    width: taffy::style::Dimension::from_length(50f32),
164                    height: taffy::style::Dimension::from_length(20f32),
165                },
166                ..Default::default()
167            },
168            &[node10],
169        )
170        .unwrap();
171    let node20 = taffy
172        .new_leaf(taffy::style::Style {
173            box_sizing: taffy::style::BoxSizing::ContentBox,
174            size: taffy::geometry::Size {
175                width: taffy::style::Dimension::from_length(50f32),
176                height: taffy::style::Dimension::from_length(10f32),
177            },
178            ..Default::default()
179        })
180        .unwrap();
181    let node2 = taffy
182        .new_with_children(
183            taffy::style::Style {
184                box_sizing: taffy::style::BoxSizing::ContentBox,
185                flex_direction: taffy::style::FlexDirection::Column,
186                size: taffy::geometry::Size {
187                    width: taffy::style::Dimension::from_length(50f32),
188                    height: taffy::style::Dimension::from_length(20f32),
189                },
190                ..Default::default()
191            },
192            &[node20],
193        )
194        .unwrap();
195    let node3 = taffy
196        .new_leaf(taffy::style::Style {
197            box_sizing: taffy::style::BoxSizing::ContentBox,
198            size: taffy::geometry::Size {
199                width: taffy::style::Dimension::from_length(50f32),
200                height: taffy::style::Dimension::from_length(50f32),
201            },
202            ..Default::default()
203        })
204        .unwrap();
205    let node = taffy
206        .new_with_children(
207            taffy::style::Style {
208                box_sizing: taffy::style::BoxSizing::ContentBox,
209                flex_wrap: taffy::style::FlexWrap::Wrap,
210                align_items: Some(taffy::style::AlignItems::Baseline),
211                size: taffy::geometry::Size {
212                    width: taffy::style::Dimension::from_length(100f32),
213                    height: taffy::style::Dimension::from_length(100f32),
214                },
215                ..Default::default()
216            },
217            &[node0, node1, node2, node3],
218        )
219        .unwrap();
220    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
221    println!("\nComputed tree:");
222    taffy.print_tree(node);
223    println!();
224    let layout = taffy.layout(node).unwrap();
225    let Layout { size, location, .. } = layout;
226    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
227    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
228    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
229    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
230    let layout = taffy.layout(node0).unwrap();
231    let Layout { size, location, .. } = layout;
232    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
233    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
234    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
235    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
236    let layout = taffy.layout(node1).unwrap();
237    let Layout { size, location, .. } = layout;
238    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
239    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
240    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
241    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
242    let layout = taffy.layout(node10).unwrap();
243    let Layout { size, location, .. } = layout;
244    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
245    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
246    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
247    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
248    let layout = taffy.layout(node2).unwrap();
249    let Layout { size, location, .. } = layout;
250    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
251    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
252    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
253    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node2, 100f32, location.y);
254    let layout = taffy.layout(node20).unwrap();
255    let Layout { size, location, .. } = layout;
256    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node20, 50f32, size.width);
257    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20, 10f32, size.height);
258    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node20, 0f32, location.x);
259    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20, 0f32, location.y);
260    let layout = taffy.layout(node3).unwrap();
261    let Layout { size, location, .. } = layout;
262    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
263    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3, 50f32, size.height);
264    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
265    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node3, 60f32, location.y);
266}