faststep 0.1.0

UIKit-inspired embedded UI framework built on embedded-graphics
Documentation
use embedded_graphics::{prelude::Point, primitives::Rectangle};

/// One render layer used by stack-style presentation.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Layer<K> {
    /// Stable layer key.
    pub key: K,
    /// Base frame for the layer.
    pub frame: Rectangle,
    /// Translation offset applied during animation.
    pub offset: Point,
}

impl<K> Layer<K> {
    /// Creates a layer.
    pub const fn new(key: K, frame: Rectangle, offset: Point) -> Self {
        Self { key, frame, offset }
    }

    /// Returns the translated frame after applying the current offset.
    pub fn translated_frame(&self) -> Rectangle {
        Rectangle::new(self.frame.top_left + self.offset, self.frame.size)
    }
}

/// Render layer for a modal presentation.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ModalLayer<M> {
    /// Modal identifier.
    pub modal: M,
    /// Settled panel frame.
    pub panel: Rectangle,
    /// Vertical offset applied during animation.
    pub y_offset: i32,
    /// Backdrop dimming alpha.
    pub dim_alpha: u8,
}

impl<M> ModalLayer<M> {
    /// Creates a modal layer.
    pub const fn new(modal: M, panel: Rectangle, y_offset: i32, dim_alpha: u8) -> Self {
        Self {
            modal,
            panel,
            y_offset,
            dim_alpha,
        }
    }

    /// Returns the translated panel frame after applying `y_offset`.
    pub fn translated_panel(&self) -> Rectangle {
        Rectangle::new(
            self.panel.top_left + Point::new(0, self.y_offset),
            self.panel.size,
        )
    }
}