tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Sutichaykuna

⎇ 0.4.x tests/generated/grid/grid_max_width_greater_than_max_content.rs Rust · 147 siq'ikuna · 5.8 KB Ñawpa willay Pi imata llamkarqan ch'uya

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1#[test]
2fn grid_max_width_greater_than_max_content() {
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_with_context(
8            taffy::style::Style { ..Default::default() },
9            crate::TextMeasure {
10                text_content: "HH\u{200b}HH\u{200b}HH\u{200b}HH",
11                writing_mode: crate::WritingMode::Horizontal,
12                _aspect_ratio: None,
13            },
14        )
15        .unwrap();
16    let node01 = taffy
17        .new_leaf_with_context(
18            taffy::style::Style { ..Default::default() },
19            crate::TextMeasure {
20                text_content: "HH\u{200b}HH\u{200b}HH\u{200b}HH",
21                writing_mode: crate::WritingMode::Horizontal,
22                _aspect_ratio: None,
23            },
24        )
25        .unwrap();
26    let node0 = taffy
27        .new_with_children(
28            taffy::style::Style {
29                display: taffy::style::Display::Grid,
30                grid_template_columns: vec![auto(), auto()],
31                max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(400f32), height: auto() },
32                ..Default::default()
33            },
34            &[node00, node01],
35        )
36        .unwrap();
37    let node = taffy
38        .new_with_children(
39            taffy::style::Style {
40                display: taffy::style::Display::Grid,
41                grid_template_columns: vec![max_content()],
42                ..Default::default()
43            },
44            &[node0],
45        )
46        .unwrap();
47    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
48    println!("\nComputed tree:");
49    taffy.print_tree(node);
50    println!();
51    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
52    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
53    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node, 160f32, size.width);
54    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
55    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
56    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
57    #[cfg(feature = "content_size")]
58    assert_eq!(
59        layout.scroll_width(),
60        0f32,
61        "scroll_width of node {:?}. Expected {}. Actual {}",
62        node,
63        0f32,
64        layout.scroll_width()
65    );
66    #[cfg(feature = "content_size")]
67    assert_eq!(
68        layout.scroll_height(),
69        0f32,
70        "scroll_height of node {:?}. Expected {}. Actual {}",
71        node,
72        0f32,
73        layout.scroll_height()
74    );
75    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
76    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
77    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node0, 160f32, size.width);
78    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
79    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
80    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
81    #[cfg(feature = "content_size")]
82    assert_eq!(
83        layout.scroll_width(),
84        0f32,
85        "scroll_width of node {:?}. Expected {}. Actual {}",
86        node0,
87        0f32,
88        layout.scroll_width()
89    );
90    #[cfg(feature = "content_size")]
91    assert_eq!(
92        layout.scroll_height(),
93        0f32,
94        "scroll_height of node {:?}. Expected {}. Actual {}",
95        node0,
96        0f32,
97        layout.scroll_height()
98    );
99    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
100    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
101    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node00, 80f32, size.width);
102    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
103    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
104    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
105    #[cfg(feature = "content_size")]
106    assert_eq!(
107        layout.scroll_width(),
108        0f32,
109        "scroll_width of node {:?}. Expected {}. Actual {}",
110        node00,
111        0f32,
112        layout.scroll_width()
113    );
114    #[cfg(feature = "content_size")]
115    assert_eq!(
116        layout.scroll_height(),
117        0f32,
118        "scroll_height of node {:?}. Expected {}. Actual {}",
119        node00,
120        0f32,
121        layout.scroll_height()
122    );
123    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
124    let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
125    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node01, 80f32, size.width);
126    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01, 10f32, size.height);
127    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node01, 80f32, location.x);
128    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
129    #[cfg(feature = "content_size")]
130    assert_eq!(
131        layout.scroll_width(),
132        0f32,
133        "scroll_width of node {:?}. Expected {}. Actual {}",
134        node01,
135        0f32,
136        layout.scroll_width()
137    );
138    #[cfg(feature = "content_size")]
139    assert_eq!(
140        layout.scroll_height(),
141        0f32,
142        "scroll_height of node {:?}. Expected {}. Actual {}",
143        node01,
144        0f32,
145        layout.scroll_height()
146    );
147}