tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definiciones

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