tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Sutichaykuna

⎇ 6ce28e1535f2ab4631d0502f2fee13d4827f2a11 tests/min_max_overrides.rs Rust · 72 siq'ikuna · 2.3 KB Ñawpa willay Pi imata llamkarqan ch'uya

Min values should override max values (#262) b952c2b38 · George Atkinson ·

1#[cfg(test)]
2mod min_max_overrides {
3
4    use taffy::prelude::*;
5
6    #[test]
7    fn min_overrides_max() {
8        let mut taffy = Taffy::new();
9
10        let child = taffy
11            .new_leaf(Style {
12                size: Size { width: Dimension::Points(50.0), height: Dimension::Points(50.0) },
13                min_size: Size { width: Dimension::Points(100.0), height: Dimension::Points(100.0) },
14                max_size: Size { width: Dimension::Points(10.0), height: Dimension::Points(10.0) },
15                ..Default::default()
16            })
17            .unwrap();
18
19        taffy
20            .compute_layout(
21                child,
22                Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) },
23            )
24            .unwrap();
25
26        assert_eq!(taffy.layout(child).unwrap().size, Size { width: 100.0, height: 100.0 });
27    }
28
29    #[test]
30    fn max_overrides_size() {
31        let mut taffy = Taffy::new();
32
33        let child = taffy
34            .new_leaf(Style {
35                size: Size { width: Dimension::Points(50.0), height: Dimension::Points(50.0) },
36                max_size: Size { width: Dimension::Points(10.0), height: Dimension::Points(10.0) },
37                ..Default::default()
38            })
39            .unwrap();
40
41        taffy
42            .compute_layout(
43                child,
44                Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) },
45            )
46            .unwrap();
47
48        assert_eq!(taffy.layout(child).unwrap().size, Size { width: 10.0, height: 10.0 });
49    }
50
51    #[test]
52    fn min_overrides_size() {
53        let mut taffy = Taffy::new();
54
55        let child = taffy
56            .new_leaf(Style {
57                size: Size { width: Dimension::Points(50.0), height: Dimension::Points(50.0) },
58                min_size: Size { width: Dimension::Points(100.0), height: Dimension::Points(100.0) },
59                ..Default::default()
60            })
61            .unwrap();
62
63        taffy
64            .compute_layout(
65                child,
66                Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) },
67            )
68            .unwrap();
69
70        assert_eq!(taffy.layout(child).unwrap().size, Size { width: 100.0, height: 100.0 });
71    }
72}