ul_next/
rect.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! A container for Rectangle structure.
#[derive(Clone, Copy, Debug)]
/// Rectangle structure
pub struct Rect<T> {
    pub left: T,
    pub top: T,
    pub right: T,
    pub bottom: T,
}

impl Rect<i32> {
    /// Whether the rectangle is empty or not.
    pub fn is_empty(&self) -> bool {
        self.left == 0 && self.top == 0 && self.right == 0 && self.bottom == 0
    }
}

impl From<ul_sys::ULRect> for Rect<f32> {
    fn from(r: ul_sys::ULRect) -> Self {
        Rect {
            left: r.left,
            top: r.top,
            right: r.right,
            bottom: r.bottom,
        }
    }
}

impl From<ul_sys::ULIntRect> for Rect<i32> {
    fn from(r: ul_sys::ULIntRect) -> Self {
        Rect {
            left: r.left,
            top: r.top,
            right: r.right,
            bottom: r.bottom,
        }
    }
}

impl From<Rect<f32>> for ul_sys::ULRect {
    fn from(r: Rect<f32>) -> Self {
        ul_sys::ULRect {
            left: r.left,
            top: r.top,
            right: r.right,
            bottom: r.bottom,
        }
    }
}

impl From<Rect<i32>> for ul_sys::ULIntRect {
    fn from(r: Rect<i32>) -> Self {
        ul_sys::ULIntRect {
            left: r.left,
            top: r.top,
            right: r.right,
            bottom: r.bottom,
        }
    }
}