tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/grid/grid_align_items_baseline_child_padding.rs Rust · 193 siq'ikuna · 9.3 KB Ñawpa willay Pi imata llamkarqan ch'uya

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_padding__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(50f32),
22                height: taffy::style::Dimension::from_length(10f32),
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(50f32),
33                    height: taffy::style::Dimension::from_length(20f32),
34                },
35                padding: taffy::geometry::Rect {
36                    left: length(5f32),
37                    right: length(5f32),
38                    top: length(5f32),
39                    bottom: length(5f32),
40                },
41                ..Default::default()
42            },
43            &[node10],
44        )
45        .unwrap();
46    let node = taffy
47        .new_with_children(
48            taffy::style::Style {
49                display: taffy::style::Display::Grid,
50                align_items: Some(taffy::style::AlignItems::Baseline),
51                size: taffy::geometry::Size {
52                    width: taffy::style::Dimension::from_length(100f32),
53                    height: taffy::style::Dimension::from_length(100f32),
54                },
55                padding: taffy::geometry::Rect {
56                    left: length(5f32),
57                    right: length(5f32),
58                    top: length(5f32),
59                    bottom: length(5f32),
60                },
61                ..Default::default()
62            },
63            &[node0, node1],
64        )
65        .unwrap();
66    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
67    println!("\nComputed tree:");
68    taffy.print_tree(node);
69    println!();
70    let layout = taffy.layout(node).unwrap();
71    let Layout { size, location, .. } = layout;
72    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
73    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
74    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
76    let layout = taffy.layout(node0).unwrap();
77    let Layout { size, location, .. } = layout;
78    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
79    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
80    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
81    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
82    let layout = taffy.layout(node1).unwrap();
83    let Layout { size, location, .. } = layout;
84    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
85    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
86    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node1, 5f32, location.x);
87    assert_eq!(location.y, 65f32, "y of node {:?}. Expected {}. Actual {}", node1, 65f32, location.y);
88    let layout = taffy.layout(node10).unwrap();
89    let Layout { size, location, .. } = layout;
90    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
91    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
92    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node10, 5f32, location.x);
93    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node10, 5f32, location.y);
94}
95
96#[test]
97#[allow(non_snake_case)]
98fn grid_align_items_baseline_child_padding__content_box() {
99    #[allow(unused_imports)]
100    use taffy::{prelude::*, Layout};
101    let mut taffy = crate::new_test_tree();
102    let node0 = taffy
103        .new_leaf(taffy::style::Style {
104            display: taffy::style::Display::Grid,
105            box_sizing: taffy::style::BoxSizing::ContentBox,
106            size: taffy::geometry::Size {
107                width: taffy::style::Dimension::from_length(50f32),
108                height: taffy::style::Dimension::from_length(50f32),
109            },
110            ..Default::default()
111        })
112        .unwrap();
113    let node10 = taffy
114        .new_leaf(taffy::style::Style {
115            display: taffy::style::Display::Grid,
116            box_sizing: taffy::style::BoxSizing::ContentBox,
117            size: taffy::geometry::Size {
118                width: taffy::style::Dimension::from_length(50f32),
119                height: taffy::style::Dimension::from_length(10f32),
120            },
121            ..Default::default()
122        })
123        .unwrap();
124    let node1 = taffy
125        .new_with_children(
126            taffy::style::Style {
127                display: taffy::style::Display::Grid,
128                box_sizing: taffy::style::BoxSizing::ContentBox,
129                size: taffy::geometry::Size {
130                    width: taffy::style::Dimension::from_length(50f32),
131                    height: taffy::style::Dimension::from_length(20f32),
132                },
133                padding: taffy::geometry::Rect {
134                    left: length(5f32),
135                    right: length(5f32),
136                    top: length(5f32),
137                    bottom: length(5f32),
138                },
139                ..Default::default()
140            },
141            &[node10],
142        )
143        .unwrap();
144    let node = taffy
145        .new_with_children(
146            taffy::style::Style {
147                display: taffy::style::Display::Grid,
148                box_sizing: taffy::style::BoxSizing::ContentBox,
149                align_items: Some(taffy::style::AlignItems::Baseline),
150                size: taffy::geometry::Size {
151                    width: taffy::style::Dimension::from_length(100f32),
152                    height: taffy::style::Dimension::from_length(100f32),
153                },
154                padding: taffy::geometry::Rect {
155                    left: length(5f32),
156                    right: length(5f32),
157                    top: length(5f32),
158                    bottom: length(5f32),
159                },
160                ..Default::default()
161            },
162            &[node0, node1],
163        )
164        .unwrap();
165    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
166    println!("\nComputed tree:");
167    taffy.print_tree(node);
168    println!();
169    let layout = taffy.layout(node).unwrap();
170    let Layout { size, location, .. } = layout;
171    assert_eq!(size.width, 110f32, "width of node {:?}. Expected {}. Actual {}", node, 110f32, size.width);
172    assert_eq!(size.height, 110f32, "height of node {:?}. Expected {}. Actual {}", node, 110f32, size.height);
173    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
174    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
175    let layout = taffy.layout(node0).unwrap();
176    let Layout { size, location, .. } = layout;
177    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
178    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
179    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
180    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
181    let layout = taffy.layout(node1).unwrap();
182    let Layout { size, location, .. } = layout;
183    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1, 60f32, size.width);
184    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
185    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node1, 5f32, location.x);
186    assert_eq!(location.y, 65f32, "y of node {:?}. Expected {}. Actual {}", node1, 65f32, location.y);
187    let layout = taffy.layout(node10).unwrap();
188    let Layout { size, location, .. } = layout;
189    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
190    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
191    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node10, 5f32, location.x);
192    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node10, 5f32, location.y);
193}