gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Sutichaykuna

⎇ 0.5.x tests/generated/flex/display_none_with_child.rs Rust · 180 siq'ikuna · 7.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn display_none_with_child() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            flex_grow: 1f32,
9            flex_shrink: 1f32,
10            flex_basis: taffy::style::Dimension::Percent(0f32),
11            ..Default::default()
12        })
13        .unwrap();
14    let node10 = taffy
15        .new_leaf(taffy::style::Style {
16            flex_grow: 1f32,
17            flex_shrink: 1f32,
18            flex_basis: taffy::style::Dimension::Percent(0f32),
19            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(20f32), height: auto() },
20            ..Default::default()
21        })
22        .unwrap();
23    let node1 = taffy
24        .new_with_children(
25            taffy::style::Style {
26                display: taffy::style::Display::None,
27                flex_direction: taffy::style::FlexDirection::Column,
28                flex_grow: 1f32,
29                flex_shrink: 1f32,
30                flex_basis: taffy::style::Dimension::Percent(0f32),
31                ..Default::default()
32            },
33            &[node10],
34        )
35        .unwrap();
36    let node2 = taffy
37        .new_leaf(taffy::style::Style {
38            flex_grow: 1f32,
39            flex_shrink: 1f32,
40            flex_basis: taffy::style::Dimension::Percent(0f32),
41            ..Default::default()
42        })
43        .unwrap();
44    let node = taffy
45        .new_with_children(
46            taffy::style::Style {
47                size: taffy::geometry::Size {
48                    width: taffy::style::Dimension::Length(100f32),
49                    height: taffy::style::Dimension::Length(100f32),
50                },
51                ..Default::default()
52            },
53            &[node0, node1, node2],
54        )
55        .unwrap();
56    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
57    println!("\nComputed tree:");
58    taffy.print_tree(node);
59    println!();
60    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
61    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
62    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
63    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
64    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
65    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 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        node,
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        node,
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(node0).unwrap();
86    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
87    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
88    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
89    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 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        node0,
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        node0,
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(node1).unwrap();
110    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1, 0f32, size.width);
111    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
112    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
113    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 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        node1,
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        node1,
129        0f32,
130        layout.scroll_height()
131    );
132    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
133    let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
134    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node10, 0f32, size.width);
135    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node10, 0f32, size.height);
136    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
137    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
138    #[cfg(feature = "content_size")]
139    assert_eq!(
140        layout.scroll_width(),
141        0f32,
142        "scroll_width of node {:?}. Expected {}. Actual {}",
143        node10,
144        0f32,
145        layout.scroll_width()
146    );
147    #[cfg(feature = "content_size")]
148    assert_eq!(
149        layout.scroll_height(),
150        0f32,
151        "scroll_height of node {:?}. Expected {}. Actual {}",
152        node10,
153        0f32,
154        layout.scroll_height()
155    );
156    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
157    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
158    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
159    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
160    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node2, 50f32, location.x);
161    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
162    #[cfg(feature = "content_size")]
163    assert_eq!(
164        layout.scroll_width(),
165        0f32,
166        "scroll_width of node {:?}. Expected {}. Actual {}",
167        node2,
168        0f32,
169        layout.scroll_width()
170    );
171    #[cfg(feature = "content_size")]
172    assert_eq!(
173        layout.scroll_height(),
174        0f32,
175        "scroll_height of node {:?}. Expected {}. Actual {}",
176        node2,
177        0f32,
178        layout.scroll_height()
179    );
180}