#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Rect {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
}
impl Rect {
pub fn expanded_by(&self, edge: EdgeSizes) -> Rect {
Rect {
x: self.x - edge.left,
y: self.y - edge.top,
width: self.width + edge.left + edge.right,
height: self.height + edge.top + edge.bottom,
}
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct EdgeSizes {
pub top: f32,
pub right: f32,
pub bottom: f32,
pub left: f32,
}
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Dimensions {
pub content: Rect,
pub padding: EdgeSizes,
pub border: EdgeSizes,
pub margin: EdgeSizes,
}
impl Dimensions {
pub fn padding_box(&self) -> Rect {
self.content.expanded_by(self.padding)
}
pub fn border_box(&self) -> Rect {
self.padding_box().expanded_by(self.border)
}
pub fn margin_box(&self) -> Rect {
self.border_box().expanded_by(self.margin)
}
}