tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Sutichaykuna

⎇ 0.2.x tests/root_constraints.rs Rust · 80 siq'ikuna · 2.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

Rename FlexboxLayout back to Style (#251) 49893a7d9 · Nico Burns ·

1#[cfg(test)]
2mod root_constraints {
3    use taffy::layout::AvailableSpace;
4
5    #[test]
6    fn root_with_percentage_size() {
7        let mut taffy = taffy::node::Taffy::new();
8        let node = taffy
9            .new_leaf(taffy::style::Style {
10                size: taffy::geometry::Size {
11                    width: taffy::style::Dimension::Percent(1.0),
12                    height: taffy::style::Dimension::Percent(1.0),
13                },
14                ..Default::default()
15            })
16            .unwrap();
17
18        taffy
19            .compute_layout(
20                node,
21                taffy::geometry::Size {
22                    width: AvailableSpace::Definite(100.0),
23                    height: AvailableSpace::Definite(200.0),
24                },
25            )
26            .unwrap();
27        let layout = taffy.layout(node).unwrap();
28
29        assert_eq!(layout.size.width, 100.0);
30        assert_eq!(layout.size.height, 200.0);
31    }
32
33    #[test]
34    fn root_with_no_size() {
35        let mut taffy = taffy::node::Taffy::new();
36        let node = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
37
38        taffy
39            .compute_layout(
40                node,
41                taffy::geometry::Size {
42                    width: AvailableSpace::Definite(100.0),
43                    height: AvailableSpace::Definite(100.0),
44                },
45            )
46            .unwrap();
47        let layout = taffy.layout(node).unwrap();
48
49        assert_eq!(layout.size.width, 0.0);
50        assert_eq!(layout.size.height, 0.0);
51    }
52
53    #[test]
54    fn root_with_larger_size() {
55        let mut taffy = taffy::node::Taffy::new();
56        let node = taffy
57            .new_leaf(taffy::style::Style {
58                size: taffy::geometry::Size {
59                    width: taffy::style::Dimension::Points(200.0),
60                    height: taffy::style::Dimension::Points(200.0),
61                },
62                ..Default::default()
63            })
64            .unwrap();
65
66        taffy
67            .compute_layout(
68                node,
69                taffy::geometry::Size {
70                    width: AvailableSpace::Definite(100.0),
71                    height: AvailableSpace::Definite(100.0),
72                },
73            )
74            .unwrap();
75        let layout = taffy.layout(node).unwrap();
76
77        assert_eq!(layout.size.width, 200.0);
78        assert_eq!(layout.size.height, 200.0);
79    }
80}