tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

⎇ b746ac4f346dde8a2b6f85d3a428c02a2342f099 tests/generated/flex/blitz_issue_88.rs Rust · 307 lines · 12.1 KB History Who touched what raw

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

1#[test]
2#[allow(non_snake_case)]
3fn blitz_issue_88__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, tree::Layout, TaffyTree};
6    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7    let node000 = taffy
8        .new_leaf_with_context(
9            taffy::style::Style {
10                display: taffy::style::Display::Block,
11                flex_grow: 1f32,
12                flex_basis: taffy::style::Dimension::Length(0f32),
13                ..Default::default()
14            },
15            crate::TextMeasure {
16                text_content: "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH",
17                writing_mode: crate::WritingMode::Horizontal,
18                _aspect_ratio: None,
19            },
20        )
21        .unwrap();
22    let node00 = taffy
23        .new_with_children(
24            taffy::style::Style { display: taffy::style::Display::Flex, flex_grow: 1f32, ..Default::default() },
25            &[node000],
26        )
27        .unwrap();
28    let node0 = taffy
29        .new_with_children(
30            taffy::style::Style {
31                display: taffy::style::Display::Flex,
32                flex_direction: taffy::style::FlexDirection::Column,
33                justify_content: Some(taffy::style::JustifyContent::Start),
34                ..Default::default()
35            },
36            &[node00],
37        )
38        .unwrap();
39    let node = taffy
40        .new_with_children(
41            taffy::style::Style {
42                display: taffy::style::Display::Block,
43                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(600f32), height: auto() },
44                ..Default::default()
45            },
46            &[node0],
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    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
54    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
55    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node, 600f32, size.width);
56    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, 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    #[cfg(feature = "content_size")]
60    assert_eq!(
61        layout.scroll_width(),
62        0f32,
63        "scroll_width of node {:?}. Expected {}. Actual {}",
64        node,
65        0f32,
66        layout.scroll_width()
67    );
68    #[cfg(feature = "content_size")]
69    assert_eq!(
70        layout.scroll_height(),
71        0f32,
72        "scroll_height of node {:?}. Expected {}. Actual {}",
73        node,
74        0f32,
75        layout.scroll_height()
76    );
77    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
78    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
79    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node0, 600f32, size.width);
80    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
81    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
82    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
83    #[cfg(feature = "content_size")]
84    assert_eq!(
85        layout.scroll_width(),
86        0f32,
87        "scroll_width of node {:?}. Expected {}. Actual {}",
88        node0,
89        0f32,
90        layout.scroll_width()
91    );
92    #[cfg(feature = "content_size")]
93    assert_eq!(
94        layout.scroll_height(),
95        0f32,
96        "scroll_height of node {:?}. Expected {}. Actual {}",
97        node0,
98        0f32,
99        layout.scroll_height()
100    );
101    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
102    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
103    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node00, 600f32, size.width);
104    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
105    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
106    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
107    #[cfg(feature = "content_size")]
108    assert_eq!(
109        layout.scroll_width(),
110        0f32,
111        "scroll_width of node {:?}. Expected {}. Actual {}",
112        node00,
113        0f32,
114        layout.scroll_width()
115    );
116    #[cfg(feature = "content_size")]
117    assert_eq!(
118        layout.scroll_height(),
119        0f32,
120        "scroll_height of node {:?}. Expected {}. Actual {}",
121        node00,
122        0f32,
123        layout.scroll_height()
124    );
125    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
126    let layout @ Layout { size, location, .. } = taffy.layout(node000).unwrap();
127    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node000, 600f32, size.width);
128    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
129    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
130    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
131    #[cfg(feature = "content_size")]
132    assert_eq!(
133        layout.scroll_width(),
134        0f32,
135        "scroll_width of node {:?}. Expected {}. Actual {}",
136        node000,
137        0f32,
138        layout.scroll_width()
139    );
140    #[cfg(feature = "content_size")]
141    assert_eq!(
142        layout.scroll_height(),
143        0f32,
144        "scroll_height of node {:?}. Expected {}. Actual {}",
145        node000,
146        0f32,
147        layout.scroll_height()
148    );
149}
150
151#[test]
152#[allow(non_snake_case)]
153fn blitz_issue_88__content_box() {
154    #[allow(unused_imports)]
155    use taffy::{prelude::*, tree::Layout, TaffyTree};
156    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
157    let node000 = taffy
158        .new_leaf_with_context(
159            taffy::style::Style {
160                display: taffy::style::Display::Block,
161                box_sizing: taffy::style::BoxSizing::ContentBox,
162                flex_grow: 1f32,
163                flex_basis: taffy::style::Dimension::Length(0f32),
164                ..Default::default()
165            },
166            crate::TextMeasure {
167                text_content: "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH",
168                writing_mode: crate::WritingMode::Horizontal,
169                _aspect_ratio: None,
170            },
171        )
172        .unwrap();
173    let node00 = taffy
174        .new_with_children(
175            taffy::style::Style {
176                display: taffy::style::Display::Flex,
177                box_sizing: taffy::style::BoxSizing::ContentBox,
178                flex_grow: 1f32,
179                ..Default::default()
180            },
181            &[node000],
182        )
183        .unwrap();
184    let node0 = taffy
185        .new_with_children(
186            taffy::style::Style {
187                display: taffy::style::Display::Flex,
188                box_sizing: taffy::style::BoxSizing::ContentBox,
189                flex_direction: taffy::style::FlexDirection::Column,
190                justify_content: Some(taffy::style::JustifyContent::Start),
191                ..Default::default()
192            },
193            &[node00],
194        )
195        .unwrap();
196    let node = taffy
197        .new_with_children(
198            taffy::style::Style {
199                display: taffy::style::Display::Block,
200                box_sizing: taffy::style::BoxSizing::ContentBox,
201                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(600f32), height: auto() },
202                ..Default::default()
203            },
204            &[node0],
205        )
206        .unwrap();
207    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
208    println!("\nComputed tree:");
209    taffy.print_tree(node);
210    println!();
211    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
212    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
213    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node, 600f32, size.width);
214    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
215    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
216    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
217    #[cfg(feature = "content_size")]
218    assert_eq!(
219        layout.scroll_width(),
220        0f32,
221        "scroll_width of node {:?}. Expected {}. Actual {}",
222        node,
223        0f32,
224        layout.scroll_width()
225    );
226    #[cfg(feature = "content_size")]
227    assert_eq!(
228        layout.scroll_height(),
229        0f32,
230        "scroll_height of node {:?}. Expected {}. Actual {}",
231        node,
232        0f32,
233        layout.scroll_height()
234    );
235    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
236    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
237    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node0, 600f32, size.width);
238    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
239    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
240    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
241    #[cfg(feature = "content_size")]
242    assert_eq!(
243        layout.scroll_width(),
244        0f32,
245        "scroll_width of node {:?}. Expected {}. Actual {}",
246        node0,
247        0f32,
248        layout.scroll_width()
249    );
250    #[cfg(feature = "content_size")]
251    assert_eq!(
252        layout.scroll_height(),
253        0f32,
254        "scroll_height of node {:?}. Expected {}. Actual {}",
255        node0,
256        0f32,
257        layout.scroll_height()
258    );
259    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
260    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
261    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node00, 600f32, size.width);
262    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
263    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
264    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
265    #[cfg(feature = "content_size")]
266    assert_eq!(
267        layout.scroll_width(),
268        0f32,
269        "scroll_width of node {:?}. Expected {}. Actual {}",
270        node00,
271        0f32,
272        layout.scroll_width()
273    );
274    #[cfg(feature = "content_size")]
275    assert_eq!(
276        layout.scroll_height(),
277        0f32,
278        "scroll_height of node {:?}. Expected {}. Actual {}",
279        node00,
280        0f32,
281        layout.scroll_height()
282    );
283    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
284    let layout @ Layout { size, location, .. } = taffy.layout(node000).unwrap();
285    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node000, 600f32, size.width);
286    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
287    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
288    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
289    #[cfg(feature = "content_size")]
290    assert_eq!(
291        layout.scroll_width(),
292        0f32,
293        "scroll_width of node {:?}. Expected {}. Actual {}",
294        node000,
295        0f32,
296        layout.scroll_width()
297    );
298    #[cfg(feature = "content_size")]
299    assert_eq!(
300        layout.scroll_height(),
301        0f32,
302        "scroll_height of node {:?}. Expected {}. Actual {}",
303        node000,
304        0f32,
305        layout.scroll_height()
306    );
307}