use crate::Color;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct PhysicalRect {
pub x: u32,
pub y: u32,
pub width: u32,
pub height: u32,
}
impl PhysicalRect {
pub const fn new(x: u32, y: u32, width: u32, height: u32) -> Self {
Self {
x,
y,
width,
height,
}
}
pub const fn whole([width, height]: [u32; 2]) -> Self {
Self::new(0, 0, width, height)
}
pub const fn size(&self) -> [u32; 2] {
[self.width, self.height]
}
pub const fn is_empty(&self) -> bool {
self.width == 0 || self.height == 0
}
pub fn fits(&self, [width, height]: [u32; 2]) -> bool {
self.x.checked_add(self.width).is_some_and(|x| x <= width)
&& self.y.checked_add(self.height).is_some_and(|y| y <= height)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct EmbedViewport {
pub region: PhysicalRect,
pub target: [u32; 2],
}
impl EmbedViewport {
pub const fn whole(target: [u32; 2]) -> Self {
Self {
region: PhysicalRect::whole(target),
target,
}
}
pub const fn region(target: [u32; 2], region: PhysicalRect) -> Self {
Self { region, target }
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum EmbedLoad {
Keep,
Clear(Color),
}