use crate::{Rect, V2};
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Frame {
pub bottom_left: V2,
pub size: V2,
pub margin: V2,
}
impl Frame {
pub fn new(size: V2, margin: V2) -> Self {
Self {
bottom_left: V2::xy(0.0),
size,
margin,
}
}
pub fn new_at(bottom_left: V2, size: V2, margin: V2) -> Self {
Self {
bottom_left,
size,
margin,
}
}
pub fn new_from_rect(rect: Rect, margin: V2) -> Self {
Self {
bottom_left: rect.bl(),
size: rect.size(),
margin,
}
}
pub fn new_xy(size: V2, margin: f32) -> Self {
Self {
bottom_left: V2::xy(0.0),
size,
margin: V2::xy(margin),
}
}
pub fn new_at_xy(bottom_left: V2, size: V2, margin: f32) -> Self {
Self {
bottom_left,
size,
margin: V2::xy(margin),
}
}
pub fn new_from_rect_xy(rect: Rect, margin: f32) -> Self {
Self {
bottom_left: rect.bl(),
size: rect.size(),
margin: V2::xy(margin),
}
}
pub fn inner_rect(&self) -> Rect {
Rect::new(
self.bottom_left + self.margin,
self.bottom_left + self.size - self.margin,
)
}
pub fn outer_rect(&self) -> Rect {
Rect::new(self.bottom_left, self.bottom_left + self.size)
}
pub fn center(&self) -> V2 {
self.outer_rect().center()
}
}