Skip to main content

embedded_gui/
present.rs

1use crate::geometry::Rect;
2
3#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
4pub struct PresentRegion {
5    pub x: usize,
6    pub y: usize,
7    pub width: usize,
8    pub height: usize,
9}
10
11impl PresentRegion {
12    pub const fn new(x: usize, y: usize, width: usize, height: usize) -> Self {
13        Self {
14            x,
15            y,
16            width,
17            height,
18        }
19    }
20
21    pub const fn is_empty(self) -> bool {
22        self.width == 0 || self.height == 0
23    }
24}
25
26impl From<Rect> for PresentRegion {
27    fn from(rect: Rect) -> Self {
28        if rect.is_empty() {
29            return Self::default();
30        }
31
32        Self {
33            x: rect.x.max(0) as usize,
34            y: rect.y.max(0) as usize,
35            width: rect.w as usize,
36            height: rect.h as usize,
37        }
38    }
39}