tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Definiciones

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