gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1111HTML 1039Markdown 12TOML 94524 Definiciones

⎇ 0.1.x tests/root_constraints.rs Rust · 77 líneas · 2.3 KB Historia Quién tocó qué crudo

Rename sprawl to taffy (#134) 8936790d6 · Alice Cecile ·

1#[cfg(test)]
2mod root_constraints {
3    use taffy::number::*;
4
5    #[test]
6    fn root_with_percentage_size() {
7        let mut taffy = taffy::node::Taffy::new();
8        let node = taffy
9            .new_node(
10                taffy::style::Style {
11                    size: taffy::geometry::Size {
12                        width: taffy::style::Dimension::Percent(1.0),
13                        height: taffy::style::Dimension::Percent(1.0),
14                    },
15                    ..Default::default()
16                },
17                &[],
18            )
19            .unwrap();
20
21        taffy
22            .compute_layout(
23                node,
24                taffy::geometry::Size { width: Number::Defined(100.0), height: Number::Defined(200.0) },
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_node(taffy::style::Style { ..Default::default() }, &[]).unwrap();
37
38        taffy
39            .compute_layout(
40                node,
41                taffy::geometry::Size { width: Number::Defined(100.0), height: Number::Defined(100.0) },
42            )
43            .unwrap();
44        let layout = taffy.layout(node).unwrap();
45
46        assert_eq!(layout.size.width, 0.0);
47        assert_eq!(layout.size.height, 0.0);
48    }
49
50    #[test]
51    fn root_with_larger_size() {
52        let mut taffy = taffy::node::Taffy::new();
53        let node = taffy
54            .new_node(
55                taffy::style::Style {
56                    size: taffy::geometry::Size {
57                        width: taffy::style::Dimension::Points(200.0),
58                        height: taffy::style::Dimension::Points(200.0),
59                    },
60                    ..Default::default()
61                },
62                &[],
63            )
64            .unwrap();
65
66        taffy
67            .compute_layout(
68                node,
69                taffy::geometry::Size { width: Number::Defined(100.0), height: Number::Defined(100.0) },
70            )
71            .unwrap();
72        let layout = taffy.layout(node).unwrap();
73
74        assert_eq!(layout.size.width, 200.0);
75        assert_eq!(layout.size.height, 200.0);
76    }
77}