tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 496HTML 245JavaScript 8CSS 61215 Definiciones

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/align_baseline_multiline_column.rs Rust · 268 líneas · 13.8 KB Historia Quién tocó qué crudo

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

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