screen_buffer_ui/
rect.rs

1#[derive(Debug, Clone, Copy, PartialEq)]
2pub struct Rect {
3    pub x: u16,
4    pub y: u16,
5    pub width: u16,
6    pub height: u16,
7}
8
9impl Rect {
10    pub fn new(x: u16, y: u16, width: u16, height: u16) -> Self {
11        Self {
12            x,
13            y,
14            width,
15            height,
16        }
17    }
18    pub fn default() -> Self {
19        Self {
20            x: 0,
21            y: 0,
22            width: 0,
23            height: 0,
24        }
25    }
26    pub fn x(&self, x: u16) -> Self {
27        Self::new(x, self.y, self.width, self.height)
28    }
29    pub fn y(&self, y: u16) -> Self {
30        Self::new(self.x, y, self.width, self.height)
31    }
32    pub fn w(&self, w: u16) -> Self {
33        Self::new(self.x, self.y, w, self.height)
34    }
35    pub fn h(&self, h: u16) -> Self {
36        Self::new(self.x, self.y, self.width, h)
37    }
38    pub fn intersects(&self, rect: &Rect) -> bool {
39        self.x < rect.x + rect.width
40            && rect.x < self.x + self.width
41            && self.y < rect.y + rect.height
42            && rect.y < self.y + self.height
43    }
44}