tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 709HTML 662Markdown 12TOML 62348 Definitions

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