faststep 0.1.0

UIKit-inspired embedded UI framework built on embedded-graphics
Documentation
#![allow(dead_code)]

use core::convert::Infallible;

use embedded_graphics::{
    Pixel,
    draw_target::DrawTarget,
    geometry::{OriginDimensions, Size},
    pixelcolor::Rgb565,
    prelude::Point,
    primitives::Rectangle,
};

use faststep::{DisplayPort, FsTheme, I18n, UiCanvas};

pub fn bounds(width: u32, height: u32) -> Rectangle {
    Rectangle::new(Point::zero(), Size::new(width, height))
}

pub fn theme() -> FsTheme {
    FsTheme::default()
}

pub fn i18n() -> I18n<'static> {
    I18n::new("en", "en", &[])
}

pub struct NullDisplay {
    bounds: Rectangle,
}

impl NullDisplay {
    pub fn new(bounds: Rectangle) -> Self {
        Self { bounds }
    }
}

pub struct NullCanvas {
    size: Size,
}

impl NullCanvas {
    pub fn new(size: Size) -> Self {
        Self { size }
    }
}

impl OriginDimensions for NullCanvas {
    fn size(&self) -> Size {
        self.size
    }
}

impl DrawTarget for NullCanvas {
    type Color = Rgb565;
    type Error = Infallible;

    fn draw_iter<I>(&mut self, _pixels: I) -> Result<(), Self::Error>
    where
        I: IntoIterator<Item = Pixel<Self::Color>>,
    {
        Ok(())
    }
}

impl UiCanvas for NullCanvas {
    fn dim_rect(&mut self, _area: Rectangle, _alpha: u8) {}
}

impl DisplayPort for NullDisplay {
    type Canvas = NullCanvas;
    type Error = Infallible;

    fn bounds(&self) -> Rectangle {
        self.bounds
    }

    fn draw_frame<F>(&mut self, draw: F) -> Result<(), Self::Error>
    where
        F: FnOnce(&mut Self::Canvas),
    {
        let mut canvas = NullCanvas::new(self.bounds.size);
        draw(&mut canvas);
        Ok(())
    }
}