use layout_cat::{Color, Point, Rect};
#[derive(Debug, Clone, PartialEq)]
pub enum PaintCommand {
FillRect {
rect: Rect,
color: Color,
},
StrokeRect {
rect: Rect,
color: Color,
width: f64,
},
FillText {
rect: Rect,
text: String,
color: Color,
font_size: f64,
},
}
impl Eq for PaintCommand {}
impl PaintCommand {
#[must_use]
pub fn scaled(&self, factor: f64) -> Self {
match self {
Self::FillRect { rect, color } => Self::FillRect {
rect: scale_rect(rect, factor),
color: *color,
},
Self::StrokeRect { rect, color, width } => Self::StrokeRect {
rect: scale_rect(rect, factor),
color: *color,
width: width * factor,
},
Self::FillText {
rect,
text,
color,
font_size,
} => Self::FillText {
rect: scale_rect(rect, factor),
text: text.clone(),
color: *color,
font_size: font_size * factor,
},
}
}
}
fn scale_rect(rect: &Rect, factor: f64) -> Rect {
Rect::new(
Point::new(rect.origin().x() * factor, rect.origin().y() * factor),
rect.width() * factor,
rect.height() * factor,
)
}