gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81412 Definitions

⎇ morphorm tests/min_max_overrides.rs Rust · 71 lines · 2.3 KB History Who touched what raw

Replace per-node measure functions with a single measure function + per-node context (#490) be627e7fa · Nico Burns ·

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