tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definiciones

⎇ 40dd6120fc73aa866f30e52a51d1abaf39adce6f tests/generated/flex/rounding_total_fractial_nested.rs Rust · 215 líneas · 11.9 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_total_fractial_nested__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            flex_grow: 1f32,
10            flex_basis: taffy::style::Dimension::from_length(0.3f32),
11            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(9.9f32) },
12            inset: taffy::geometry::Rect { left: auto(), right: auto(), top: auto(), bottom: length(13.3f32) },
13            ..Default::default()
14        })
15        .unwrap();
16    let node01 = taffy
17        .new_leaf(taffy::style::Style {
18            flex_grow: 4f32,
19            flex_basis: taffy::style::Dimension::from_length(0.3f32),
20            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(1.1f32) },
21            inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(13.3f32), bottom: auto() },
22            ..Default::default()
23        })
24        .unwrap();
25    let node0 = taffy
26        .new_with_children(
27            taffy::style::Style {
28                flex_direction: taffy::style::FlexDirection::Column,
29                flex_grow: 0.7f32,
30                flex_basis: taffy::style::Dimension::from_length(50.3f32),
31                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(20.3f32) },
32                ..Default::default()
33            },
34            &[node00, node01],
35        )
36        .unwrap();
37    let node1 = taffy
38        .new_leaf(taffy::style::Style {
39            flex_grow: 1.6f32,
40            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
41            ..Default::default()
42        })
43        .unwrap();
44    let node2 = taffy
45        .new_leaf(taffy::style::Style {
46            flex_grow: 1.1f32,
47            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10.7f32) },
48            ..Default::default()
49        })
50        .unwrap();
51    let node = taffy
52        .new_with_children(
53            taffy::style::Style {
54                flex_direction: taffy::style::FlexDirection::Column,
55                size: taffy::geometry::Size {
56                    width: taffy::style::Dimension::from_length(87.4f32),
57                    height: taffy::style::Dimension::from_length(113.4f32),
58                },
59                ..Default::default()
60            },
61            &[node0, node1, node2],
62        )
63        .unwrap();
64    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
65    println!("\nComputed tree:");
66    taffy.print_tree(node);
67    println!();
68    let layout = taffy.layout(node).unwrap();
69    let Layout { size, location, .. } = layout;
70    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node, 87f32, size.width);
71    assert_eq!(size.height, 113f32, "height of node {:?}. Expected {}. Actual {}", node, 113f32, size.height);
72    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
73    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
74    let layout = taffy.layout(node0).unwrap();
75    let Layout { size, location, .. } = layout;
76    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node0, 87f32, size.width);
77    assert_eq!(size.height, 59f32, "height of node {:?}. Expected {}. Actual {}", node0, 59f32, size.height);
78    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
79    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
80    let layout = taffy.layout(node00).unwrap();
81    let Layout { size, location, .. } = layout;
82    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node00, 87f32, size.width);
83    assert_eq!(size.height, 12f32, "height of node {:?}. Expected {}. Actual {}", node00, 12f32, size.height);
84    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
85    assert_eq!(location.y, -13f32, "y of node {:?}. Expected {}. Actual {}", node00, -13f32, location.y);
86    let layout = taffy.layout(node01).unwrap();
87    let Layout { size, location, .. } = layout;
88    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node01, 87f32, size.width);
89    assert_eq!(size.height, 47f32, "height of node {:?}. Expected {}. Actual {}", node01, 47f32, size.height);
90    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
91    assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node01, 25f32, location.y);
92    let layout = taffy.layout(node1).unwrap();
93    let Layout { size, location, .. } = layout;
94    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node1, 87f32, size.width);
95    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
96    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
97    assert_eq!(location.y, 59f32, "y of node {:?}. Expected {}. Actual {}", node1, 59f32, location.y);
98    let layout = taffy.layout(node2).unwrap();
99    let Layout { size, location, .. } = layout;
100    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node2, 87f32, size.width);
101    assert_eq!(size.height, 24f32, "height of node {:?}. Expected {}. Actual {}", node2, 24f32, size.height);
102    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
103    assert_eq!(location.y, 89f32, "y of node {:?}. Expected {}. Actual {}", node2, 89f32, location.y);
104}
105
106#[test]
107#[allow(non_snake_case)]
108fn rounding_total_fractial_nested__content_box() {
109    #[allow(unused_imports)]
110    use taffy::{prelude::*, Layout};
111    let mut taffy = crate::new_test_tree();
112    let node00 = taffy
113        .new_leaf(taffy::style::Style {
114            box_sizing: taffy::style::BoxSizing::ContentBox,
115            flex_grow: 1f32,
116            flex_basis: taffy::style::Dimension::from_length(0.3f32),
117            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(9.9f32) },
118            inset: taffy::geometry::Rect { left: auto(), right: auto(), top: auto(), bottom: length(13.3f32) },
119            ..Default::default()
120        })
121        .unwrap();
122    let node01 = taffy
123        .new_leaf(taffy::style::Style {
124            box_sizing: taffy::style::BoxSizing::ContentBox,
125            flex_grow: 4f32,
126            flex_basis: taffy::style::Dimension::from_length(0.3f32),
127            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(1.1f32) },
128            inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(13.3f32), bottom: auto() },
129            ..Default::default()
130        })
131        .unwrap();
132    let node0 = taffy
133        .new_with_children(
134            taffy::style::Style {
135                box_sizing: taffy::style::BoxSizing::ContentBox,
136                flex_direction: taffy::style::FlexDirection::Column,
137                flex_grow: 0.7f32,
138                flex_basis: taffy::style::Dimension::from_length(50.3f32),
139                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(20.3f32) },
140                ..Default::default()
141            },
142            &[node00, node01],
143        )
144        .unwrap();
145    let node1 = taffy
146        .new_leaf(taffy::style::Style {
147            box_sizing: taffy::style::BoxSizing::ContentBox,
148            flex_grow: 1.6f32,
149            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
150            ..Default::default()
151        })
152        .unwrap();
153    let node2 = taffy
154        .new_leaf(taffy::style::Style {
155            box_sizing: taffy::style::BoxSizing::ContentBox,
156            flex_grow: 1.1f32,
157            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10.7f32) },
158            ..Default::default()
159        })
160        .unwrap();
161    let node = taffy
162        .new_with_children(
163            taffy::style::Style {
164                box_sizing: taffy::style::BoxSizing::ContentBox,
165                flex_direction: taffy::style::FlexDirection::Column,
166                size: taffy::geometry::Size {
167                    width: taffy::style::Dimension::from_length(87.4f32),
168                    height: taffy::style::Dimension::from_length(113.4f32),
169                },
170                ..Default::default()
171            },
172            &[node0, node1, node2],
173        )
174        .unwrap();
175    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
176    println!("\nComputed tree:");
177    taffy.print_tree(node);
178    println!();
179    let layout = taffy.layout(node).unwrap();
180    let Layout { size, location, .. } = layout;
181    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node, 87f32, size.width);
182    assert_eq!(size.height, 113f32, "height of node {:?}. Expected {}. Actual {}", node, 113f32, size.height);
183    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
184    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
185    let layout = taffy.layout(node0).unwrap();
186    let Layout { size, location, .. } = layout;
187    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node0, 87f32, size.width);
188    assert_eq!(size.height, 59f32, "height of node {:?}. Expected {}. Actual {}", node0, 59f32, size.height);
189    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
190    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
191    let layout = taffy.layout(node00).unwrap();
192    let Layout { size, location, .. } = layout;
193    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node00, 87f32, size.width);
194    assert_eq!(size.height, 12f32, "height of node {:?}. Expected {}. Actual {}", node00, 12f32, size.height);
195    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
196    assert_eq!(location.y, -13f32, "y of node {:?}. Expected {}. Actual {}", node00, -13f32, location.y);
197    let layout = taffy.layout(node01).unwrap();
198    let Layout { size, location, .. } = layout;
199    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node01, 87f32, size.width);
200    assert_eq!(size.height, 47f32, "height of node {:?}. Expected {}. Actual {}", node01, 47f32, size.height);
201    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
202    assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node01, 25f32, location.y);
203    let layout = taffy.layout(node1).unwrap();
204    let Layout { size, location, .. } = layout;
205    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node1, 87f32, size.width);
206    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
207    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
208    assert_eq!(location.y, 59f32, "y of node {:?}. Expected {}. Actual {}", node1, 59f32, location.y);
209    let layout = taffy.layout(node2).unwrap();
210    let Layout { size, location, .. } = layout;
211    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node2, 87f32, size.width);
212    assert_eq!(size.height, 24f32, "height of node {:?}. Expected {}. Actual {}", node2, 24f32, size.height);
213    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
214    assert_eq!(location.y, 89f32, "y of node {:?}. Expected {}. Actual {}", node2, 89f32, location.y);
215}