tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1077HTML 1008Markdown 12TOML 83209 Definitions

⎇ 832e2da45631009be13279a06c30f09962db0688 tests/root_constraints.rs Rust · 55 lines · 1.9 KB History Who touched what raw

Cleanup `new_with_children()` uses (#194) 832e2da45 · Andreas Weibye ·

1#[cfg(test)]
2mod root_constraints {
3
4    #[test]
5    fn root_with_percentage_size() {
6        let mut taffy = taffy::node::Taffy::new();
7        let node = taffy
8            .new_leaf(taffy::style::FlexboxLayout {
9                size: taffy::geometry::Size {
10                    width: taffy::style::Dimension::Percent(1.0),
11                    height: taffy::style::Dimension::Percent(1.0),
12                },
13                ..Default::default()
14            })
15            .unwrap();
16
17        taffy.compute_layout(node, taffy::geometry::Size { width: Some(100.0), height: Some(200.0) }).unwrap();
18        let layout = taffy.layout(node).unwrap();
19
20        assert_eq!(layout.size.width, 100.0);
21        assert_eq!(layout.size.height, 200.0);
22    }
23
24    #[test]
25    fn root_with_no_size() {
26        let mut taffy = taffy::node::Taffy::new();
27        let node = taffy.new_leaf(taffy::style::FlexboxLayout { ..Default::default() }).unwrap();
28
29        taffy.compute_layout(node, taffy::geometry::Size { width: Some(100.0), height: Some(100.0) }).unwrap();
30        let layout = taffy.layout(node).unwrap();
31
32        assert_eq!(layout.size.width, 0.0);
33        assert_eq!(layout.size.height, 0.0);
34    }
35
36    #[test]
37    fn root_with_larger_size() {
38        let mut taffy = taffy::node::Taffy::new();
39        let node = taffy
40            .new_leaf(taffy::style::FlexboxLayout {
41                size: taffy::geometry::Size {
42                    width: taffy::style::Dimension::Points(200.0),
43                    height: taffy::style::Dimension::Points(200.0),
44                },
45                ..Default::default()
46            })
47            .unwrap();
48
49        taffy.compute_layout(node, taffy::geometry::Size { width: Some(100.0), height: Some(100.0) }).unwrap();
50        let layout = taffy.layout(node).unwrap();
51
52        assert_eq!(layout.size.width, 200.0);
53        assert_eq!(layout.size.height, 200.0);
54    }
55}