tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

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