gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91841 Definitions

⎇ b1ea6794519524c818057af327f78c09ff379453 tests/root_constraints.rs Rust · 61 lines · 2.0 KB History Who touched what raw

Replace Number type with a simpler Option<f32> (#144) b1ea67945 · Alice Cecile ·

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_with_children(
9                taffy::style::FlexboxLayout {
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                &[],
17            )
18            .unwrap();
19
20        taffy.compute_layout(node, taffy::geometry::Size { width: Some(100.0), height: Some(200.0) }).unwrap();
21        let layout = taffy.layout(node).unwrap();
22
23        assert_eq!(layout.size.width, 100.0);
24        assert_eq!(layout.size.height, 200.0);
25    }
26
27    #[test]
28    fn root_with_no_size() {
29        let mut taffy = taffy::node::Taffy::new();
30        let node = taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[]).unwrap();
31
32        taffy.compute_layout(node, taffy::geometry::Size { width: Some(100.0), height: Some(100.0) }).unwrap();
33        let layout = taffy.layout(node).unwrap();
34
35        assert_eq!(layout.size.width, 0.0);
36        assert_eq!(layout.size.height, 0.0);
37    }
38
39    #[test]
40    fn root_with_larger_size() {
41        let mut taffy = taffy::node::Taffy::new();
42        let node = taffy
43            .new_with_children(
44                taffy::style::FlexboxLayout {
45                    size: taffy::geometry::Size {
46                        width: taffy::style::Dimension::Points(200.0),
47                        height: taffy::style::Dimension::Points(200.0),
48                    },
49                    ..Default::default()
50                },
51                &[],
52            )
53            .unwrap();
54
55        taffy.compute_layout(node, taffy::geometry::Size { width: Some(100.0), height: Some(100.0) }).unwrap();
56        let layout = taffy.layout(node).unwrap();
57
58        assert_eq!(layout.size.width, 200.0);
59        assert_eq!(layout.size.height, 200.0);
60    }
61}