tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definiciones

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