gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1090HTML 1022Markdown 12TOML 84418 Definitions

⎇ c154b8aa719da0d6f8636b123765a47fa40a3306 tests/generated/block/block_display_none_with_child.rs Rust · 170 lines · 6.8 KB History Who touched what raw

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

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