tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5334Rust 85Markdown 12TOML 91813 Definitions

⎇ e6255f79aa9a3f8065504fddb315ff4a6dfe6d0f tests/generated/flex/rounding_flex_basis_flex_shrink_row.rs Rust · 275 lines · 11.0 KB History Who touched what raw

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

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