tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

⎇ direction-floats tests/generated/grid/grid_align_items_baseline_double_nested_child.rs Rust · 208 lines · 10.4 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_double_nested_child__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node00 = 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(20f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node0 = taffy
18        .new_with_children(
19            taffy::style::Style {
20                display: taffy::style::Display::Grid,
21                size: taffy::geometry::Size {
22                    width: taffy::style::Dimension::from_length(50f32),
23                    height: taffy::style::Dimension::from_length(50f32),
24                },
25                ..Default::default()
26            },
27            &[node00],
28        )
29        .unwrap();
30    let node10 = taffy
31        .new_leaf(taffy::style::Style {
32            display: taffy::style::Display::Grid,
33            size: taffy::geometry::Size {
34                width: taffy::style::Dimension::from_length(50f32),
35                height: taffy::style::Dimension::from_length(15f32),
36            },
37            ..Default::default()
38        })
39        .unwrap();
40    let node1 = taffy
41        .new_with_children(
42            taffy::style::Style {
43                display: taffy::style::Display::Grid,
44                size: taffy::geometry::Size {
45                    width: taffy::style::Dimension::from_length(50f32),
46                    height: taffy::style::Dimension::from_length(20f32),
47                },
48                ..Default::default()
49            },
50            &[node10],
51        )
52        .unwrap();
53    let node = taffy
54        .new_with_children(
55            taffy::style::Style {
56                display: taffy::style::Display::Grid,
57                align_items: Some(taffy::style::AlignItems::Baseline),
58                size: taffy::geometry::Size {
59                    width: taffy::style::Dimension::from_length(100f32),
60                    height: taffy::style::Dimension::from_length(100f32),
61                },
62                ..Default::default()
63            },
64            &[node0, node1],
65        )
66        .unwrap();
67    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
68    println!("\nComputed tree:");
69    taffy.print_tree(node);
70    println!();
71    let layout = taffy.layout(node).unwrap();
72    let Layout { size, location, .. } = layout;
73    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
74    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
75    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
76    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
77    let layout = taffy.layout(node0).unwrap();
78    let Layout { size, location, .. } = layout;
79    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
80    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
81    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
82    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
83    let layout = taffy.layout(node00).unwrap();
84    let Layout { size, location, .. } = layout;
85    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
86    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
87    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
88    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
89    let layout = taffy.layout(node1).unwrap();
90    let Layout { size, location, .. } = layout;
91    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
92    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
93    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
94    assert_eq!(location.y, 65f32, "y of node {:?}. Expected {}. Actual {}", node1, 65f32, location.y);
95    let layout = taffy.layout(node10).unwrap();
96    let Layout { size, location, .. } = layout;
97    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
98    assert_eq!(size.height, 15f32, "height of node {:?}. Expected {}. Actual {}", node10, 15f32, size.height);
99    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
100    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
101}
102
103#[test]
104#[allow(non_snake_case)]
105fn grid_align_items_baseline_double_nested_child__content_box() {
106    #[allow(unused_imports)]
107    use taffy::{prelude::*, Layout};
108    let mut taffy = crate::new_test_tree();
109    let node00 = taffy
110        .new_leaf(taffy::style::Style {
111            display: taffy::style::Display::Grid,
112            box_sizing: taffy::style::BoxSizing::ContentBox,
113            size: taffy::geometry::Size {
114                width: taffy::style::Dimension::from_length(50f32),
115                height: taffy::style::Dimension::from_length(20f32),
116            },
117            ..Default::default()
118        })
119        .unwrap();
120    let node0 = taffy
121        .new_with_children(
122            taffy::style::Style {
123                display: taffy::style::Display::Grid,
124                box_sizing: taffy::style::BoxSizing::ContentBox,
125                size: taffy::geometry::Size {
126                    width: taffy::style::Dimension::from_length(50f32),
127                    height: taffy::style::Dimension::from_length(50f32),
128                },
129                ..Default::default()
130            },
131            &[node00],
132        )
133        .unwrap();
134    let node10 = 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(15f32),
141            },
142            ..Default::default()
143        })
144        .unwrap();
145    let node1 = taffy
146        .new_with_children(
147            taffy::style::Style {
148                display: taffy::style::Display::Grid,
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(20f32),
153                },
154                ..Default::default()
155            },
156            &[node10],
157        )
158        .unwrap();
159    let node = taffy
160        .new_with_children(
161            taffy::style::Style {
162                display: taffy::style::Display::Grid,
163                box_sizing: taffy::style::BoxSizing::ContentBox,
164                align_items: Some(taffy::style::AlignItems::Baseline),
165                size: taffy::geometry::Size {
166                    width: taffy::style::Dimension::from_length(100f32),
167                    height: taffy::style::Dimension::from_length(100f32),
168                },
169                ..Default::default()
170            },
171            &[node0, node1],
172        )
173        .unwrap();
174    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
175    println!("\nComputed tree:");
176    taffy.print_tree(node);
177    println!();
178    let layout = taffy.layout(node).unwrap();
179    let Layout { size, location, .. } = layout;
180    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
181    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
182    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
183    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
184    let layout = taffy.layout(node0).unwrap();
185    let Layout { size, location, .. } = layout;
186    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
187    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
188    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
189    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
190    let layout = taffy.layout(node00).unwrap();
191    let Layout { size, location, .. } = layout;
192    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
193    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
194    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
195    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
196    let layout = taffy.layout(node1).unwrap();
197    let Layout { size, location, .. } = layout;
198    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
199    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
200    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
201    assert_eq!(location.y, 65f32, "y of node {:?}. Expected {}. Actual {}", node1, 65f32, location.y);
202    let layout = taffy.layout(node10).unwrap();
203    let Layout { size, location, .. } = layout;
204    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
205    assert_eq!(size.height, 15f32, "height of node {:?}. Expected {}. Actual {}", node10, 15f32, size.height);
206    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
207    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
208}