#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Size {
pub width: u16,
pub height: u16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Pos {
pub x: u16,
pub y: u16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Rect {
pub x: u16,
pub y: u16,
pub width: u16,
pub height: u16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Insets {
pub top: u16,
pub right: u16,
pub bottom: u16,
pub left: u16,
}
impl Insets {
pub const ZERO: Insets = Insets {
top: 0,
right: 0,
bottom: 0,
left: 0,
};
pub fn all(value: u16) -> Self {
Self {
top: value,
right: value,
bottom: value,
left: value,
}
}
}
impl Rect {
pub fn contains(&self, pos: Pos) -> bool {
pos.x >= self.x
&& pos.x < self.x.saturating_add(self.width)
&& pos.y >= self.y
&& pos.y < self.y.saturating_add(self.height)
}
pub fn inner(&self, insets: Insets) -> Rect {
let x = self.x.saturating_add(insets.left);
let y = self.y.saturating_add(insets.top);
let width = self
.width
.saturating_sub(insets.left.saturating_add(insets.right));
let height = self
.height
.saturating_sub(insets.top.saturating_add(insets.bottom));
Rect { x, y, width, height }
}
}