tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Sutichaykuna

⎇ a326c263b98a061174e52d41773d59289e379b9b tests/generated/grid/chrome_issue_325928327.rs Rust · 112 siq'ikuna · 4.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

Use grid area size rather than available space when applying aspect ratio to grid items (#656) a326c263b · Nico Burns ·

1#[test]
2fn chrome_issue_325928327() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node00 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(1f32) },
9            aspect_ratio: Some(1f32),
10            ..Default::default()
11        })
12        .unwrap();
13    let node0 = taffy
14        .new_with_children(
15            taffy::style::Style {
16                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(1f32) },
17                ..Default::default()
18            },
19            &[node00],
20        )
21        .unwrap();
22    let node = taffy
23        .new_with_children(
24            taffy::style::Style {
25                display: taffy::style::Display::Grid,
26                justify_items: Some(taffy::style::JustifyItems::Center),
27                size: taffy::geometry::Size {
28                    width: taffy::style::Dimension::Percent(1f32),
29                    height: taffy::style::Dimension::Length(40f32),
30                },
31                ..Default::default()
32            },
33            &[node0],
34        )
35        .unwrap();
36    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
37    println!("\nComputed tree:");
38    taffy.print_tree(node);
39    println!();
40    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
41    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
42    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node, 40f32, size.width);
43    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
44    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
45    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
46    #[cfg(feature = "content_size")]
47    assert_eq!(
48        layout.scroll_width(),
49        0f32,
50        "scroll_width of node {:?}. Expected {}. Actual {}",
51        node,
52        0f32,
53        layout.scroll_width()
54    );
55    #[cfg(feature = "content_size")]
56    assert_eq!(
57        layout.scroll_height(),
58        0f32,
59        "scroll_height of node {:?}. Expected {}. Actual {}",
60        node,
61        0f32,
62        layout.scroll_height()
63    );
64    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
65    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
66    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
67    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
68    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
69    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
70    #[cfg(feature = "content_size")]
71    assert_eq!(
72        layout.scroll_width(),
73        0f32,
74        "scroll_width of node {:?}. Expected {}. Actual {}",
75        node0,
76        0f32,
77        layout.scroll_width()
78    );
79    #[cfg(feature = "content_size")]
80    assert_eq!(
81        layout.scroll_height(),
82        0f32,
83        "scroll_height of node {:?}. Expected {}. Actual {}",
84        node0,
85        0f32,
86        layout.scroll_height()
87    );
88    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
89    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
90    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node00, 40f32, size.width);
91    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00, 40f32, size.height);
92    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
93    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
94    #[cfg(feature = "content_size")]
95    assert_eq!(
96        layout.scroll_width(),
97        0f32,
98        "scroll_width of node {:?}. Expected {}. Actual {}",
99        node00,
100        0f32,
101        layout.scroll_width()
102    );
103    #[cfg(feature = "content_size")]
104    assert_eq!(
105        layout.scroll_height(),
106        0f32,
107        "scroll_height of node {:?}. Expected {}. Actual {}",
108        node00,
109        0f32,
110        layout.scroll_height()
111    );
112}