use crate::utils::font_ext::FontExt;
use core::marker::PhantomData;
use embedded_graphics::fonts::Font;
pub trait SpaceConfig: Copy + Default {
type Font: Font;
fn peek_next_width(&self, n: u32) -> u32;
fn consume(&mut self, n: u32) -> u32;
}
#[derive(Copy, Clone, Debug)]
pub struct UniformSpaceConfig<F> {
_font: PhantomData<F>,
pub space_width: u32,
}
impl<F> Default for UniformSpaceConfig<F>
where
F: Font + Copy,
{
#[inline]
#[must_use]
fn default() -> Self {
Self {
_font: PhantomData,
space_width: F::total_char_width(' '),
}
}
}
impl<F> SpaceConfig for UniformSpaceConfig<F>
where
F: Font + Copy,
{
type Font = F;
#[inline]
fn peek_next_width(&self, n: u32) -> u32 {
n * self.space_width
}
#[inline]
fn consume(&mut self, n: u32) -> u32 {
self.peek_next_width(n)
}
}