use crate::battery_icon::{BatteryIconBuilder, ChargerAlignment};
use crate::font::OVERPASS_NUMBERS_FONT;
use crate::styled::Styled;
use crate::watchface_data::Watchface;
use core::fmt::Write;
use core::marker::PhantomData;
use embedded_graphics::{
draw_target::DrawTarget, mono_font::MonoTextStyle, prelude::*, text::Text, Drawable,
};
use embedded_layout::prelude::*;
use heapless::consts::*;
use heapless::String;
#[derive(Default)]
pub struct SimpleWatchfaceStyle<C> {
_phantom_data: PhantomData<C>,
}
impl<C> Drawable for Styled<Watchface, SimpleWatchfaceStyle<C>>
where
C: RgbColor,
{
type Color = C;
type Output = ();
fn draw<D: DrawTarget<Color = C>>(
&self,
display: &mut D,
) -> Result<(), <D as DrawTarget>::Error> {
let display_area = display.bounding_box();
display.clear(C::BLACK)?;
if let Some(time) = &self.watchface.time {
let time_text_style = MonoTextStyle::new(&OVERPASS_NUMBERS_FONT, C::WHITE);
let mut text = String::<U8>::new();
write!(
&mut text,
"{:02}:{:02}",
time.hours_local(),
time.minutes_local(),
)
.unwrap();
Text::new(&text, Point::new(10, 70), time_text_style)
.align_to(&display_area, horizontal::Center, vertical::Center)
.draw(display)?;
}
let mut icon_builder = BatteryIconBuilder::new(Point::new(10, 10));
if let Some(battery) = &self.watchface.battery {
icon_builder = icon_builder.with_state_of_charge(*battery);
}
if let Some(charger) = &self.watchface.charger {
icon_builder = icon_builder.with_charger(*charger);
}
icon_builder
.with_charger_alignment(ChargerAlignment::Left)
.build()
.align_to(&display_area, horizontal::Right, vertical::Top)
.draw(display)?;
Ok(())
}
}