use embedded_graphics::iterator::raw::RawDataSlice;
use embedded_graphics::pixelcolor::raw::BigEndian;
use embedded_graphics::pixelcolor::{BinaryColor, PixelColor};
use embedded_graphics::text::DecorationColor;
use crate::color::{Invert, Screen, WeightedAvg};
use crate::font::BitmapFont;
use crate::style::BitmapFontStyle;
#[derive(Debug, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BitmapFontStyleBuilder<'a, 'b, T, C, const N: usize>
where
C: PixelColor + From<C::Raw>,
T: PixelColor + Default + Invert + Screen + WeightedAvg,
RawDataSlice<'a, C::Raw, BigEndian>: IntoIterator<Item = C::Raw>,
{
style: BitmapFontStyle<'a, 'b, T, C, N>,
}
impl<'a, 'b, T, C, const N: usize> BitmapFontStyleBuilder<'a, 'b, T, C, N>
where
C: PixelColor + From<C::Raw>,
T: PixelColor + Default + Invert + Screen + WeightedAvg,
RawDataSlice<'a, C::Raw, BigEndian>: IntoIterator<Item = C::Raw>,
{
pub const fn reset_text_color(mut self) -> Self {
self.style.text_color = None;
self
}
pub const fn reset_background_color(mut self) -> Self {
self.style.background_color = None;
self
}
pub const fn reset_underline(mut self) -> Self {
self.style.underline_color = DecorationColor::None;
self
}
pub const fn reset_strikethrough(mut self) -> Self {
self.style.strikethrough_color = DecorationColor::None;
self
}
pub const fn underline(mut self) -> Self {
self.style.underline_color = DecorationColor::TextColor;
self
}
pub const fn strikethrough(mut self) -> Self {
self.style.strikethrough_color = DecorationColor::TextColor;
self
}
pub const fn text_color(mut self, text_color: T) -> Self {
self.style.text_color = Some(text_color);
self
}
pub const fn background_color(mut self, background_color: T) -> Self {
self.style.background_color = Some(background_color);
self
}
pub const fn underline_with_color(mut self, underline_color: T) -> Self {
self.style.underline_color = DecorationColor::Custom(underline_color);
self
}
pub const fn strikethrough_with_color(mut self, strikethrough_color: T) -> Self {
self.style.strikethrough_color = DecorationColor::Custom(strikethrough_color);
self
}
pub const fn font<'z, D, const M: usize>(
self,
font: &'z BitmapFont<'a, D, M>,
) -> BitmapFontStyleBuilder<'a, 'z, T, D, M>
where
D: PixelColor + From<D::Raw>,
RawDataSlice<'a, D::Raw, BigEndian>: IntoIterator<Item = D::Raw>,
{
let mut style = BitmapFontStyle::const_default();
style.font = font;
style.text_color = self.style.text_color;
style.background_color = self.style.background_color;
style.underline_color = self.style.underline_color;
style.strikethrough_color = self.style.strikethrough_color;
BitmapFontStyleBuilder { style }
}
pub const fn build(self) -> BitmapFontStyle<'a, 'b, T, C, N> {
self.style
}
}
impl<T> BitmapFontStyleBuilder<'_, '_, T, BinaryColor, 0>
where
T: PixelColor + Default + Invert + Screen + WeightedAvg,
{
pub const fn new() -> Self {
Self {
style: BitmapFontStyle::const_default(),
}
}
}
impl<'a, T, C, const N: usize> Default for BitmapFontStyleBuilder<'a, '_, T, C, N>
where
C: PixelColor + From<C::Raw>,
T: PixelColor + Default + Invert + Screen + WeightedAvg,
RawDataSlice<'a, C::Raw, BigEndian>: IntoIterator<Item = C::Raw>,
{
fn default() -> Self {
Self {
style: BitmapFontStyle::const_default(),
}
}
}