use crate::theme::BinaryColorTheme;
use embedded_graphics::prelude::*;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct OutputSettings {
pub scale: u32,
pub pixel_spacing: u32,
pub theme: BinaryColorTheme,
}
#[cfg(feature = "with-sdl")]
impl OutputSettings {
pub(crate) const fn output_to_display(&self, output_point: Point) -> Point {
let pitch = self.pixel_pitch() as i32;
Point::new(output_point.x / pitch, output_point.y / pitch)
}
pub(crate) const fn pixel_pitch(&self) -> u32 {
self.scale + self.pixel_spacing
}
}
impl Default for OutputSettings {
fn default() -> Self {
OutputSettingsBuilder::new().build()
}
}
#[derive(Default)]
pub struct OutputSettingsBuilder {
scale: Option<u32>,
pixel_spacing: Option<u32>,
theme: BinaryColorTheme,
}
impl OutputSettingsBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn scale(mut self, scale: u32) -> Self {
assert!(scale > 0, "scale must be > 0");
self.scale = Some(scale);
self
}
pub fn theme(mut self, theme: BinaryColorTheme) -> Self {
self.theme = theme;
self.scale.get_or_insert(3);
self.pixel_spacing.get_or_insert(1);
self
}
pub fn pixel_spacing(mut self, pixel_spacing: u32) -> Self {
self.pixel_spacing = Some(pixel_spacing);
self
}
pub fn build(self) -> OutputSettings {
OutputSettings {
scale: self.scale.unwrap_or(1),
pixel_spacing: self.pixel_spacing.unwrap_or(0),
theme: self.theme,
}
}
}