tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Sutichaykuna

⎇ 40dd6120fc73aa866f30e52a51d1abaf39adce6f tests/generated/flex/aspect_ratio_flex_row_stretch_fill_width.rs Rust · 89 siq'ikuna · 4.3 KB Ñawpa willay Pi imata llamkarqan ch'uya

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn aspect_ratio_flex_row_stretch_fill_width__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            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(40f32) },
10            aspect_ratio: Some(2f32),
11            ..Default::default()
12        })
13        .unwrap();
14    let node = taffy
15        .new_with_children(
16            taffy::style::Style {
17                display: taffy::style::Display::Flex,
18                size: taffy::geometry::Size {
19                    width: taffy::style::Dimension::from_length(100f32),
20                    height: taffy::style::Dimension::from_length(100f32),
21                },
22                ..Default::default()
23            },
24            &[node0],
25        )
26        .unwrap();
27    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
28    println!("\nComputed tree:");
29    taffy.print_tree(node);
30    println!();
31    let layout = taffy.layout(node).unwrap();
32    let Layout { size, location, .. } = layout;
33    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
34    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
35    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
36    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
37    let layout = taffy.layout(node0).unwrap();
38    let Layout { size, location, .. } = layout;
39    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0, 80f32, size.width);
40    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
41    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
42    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
43}
44
45#[test]
46#[allow(non_snake_case)]
47fn aspect_ratio_flex_row_stretch_fill_width__content_box() {
48    #[allow(unused_imports)]
49    use taffy::{prelude::*, Layout};
50    let mut taffy = crate::new_test_tree();
51    let node0 = taffy
52        .new_leaf(taffy::style::Style {
53            box_sizing: taffy::style::BoxSizing::ContentBox,
54            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(40f32) },
55            aspect_ratio: Some(2f32),
56            ..Default::default()
57        })
58        .unwrap();
59    let node = taffy
60        .new_with_children(
61            taffy::style::Style {
62                display: taffy::style::Display::Flex,
63                box_sizing: taffy::style::BoxSizing::ContentBox,
64                size: taffy::geometry::Size {
65                    width: taffy::style::Dimension::from_length(100f32),
66                    height: taffy::style::Dimension::from_length(100f32),
67                },
68                ..Default::default()
69            },
70            &[node0],
71        )
72        .unwrap();
73    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
74    println!("\nComputed tree:");
75    taffy.print_tree(node);
76    println!();
77    let layout = taffy.layout(node).unwrap();
78    let Layout { size, location, .. } = layout;
79    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
80    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
81    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
82    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
83    let layout = taffy.layout(node0).unwrap();
84    let Layout { size, location, .. } = layout;
85    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0, 80f32, size.width);
86    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
87    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
88    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
89}