gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Sutichaykuna

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