faststep 0.1.0

UIKit-inspired embedded UI framework built on embedded-graphics
Documentation
use crate::{FsTheme, I18n, TouchEvent, UiCanvas};

use super::{ViewEvent, ViewRegistration};

/// Immutable environment passed to drawing and event callbacks.
#[derive(Clone, Copy, Debug)]
pub struct ViewEnvironment<'env, 'text> {
    /// Active semantic theme.
    pub theme: &'env FsTheme,
    /// Active localization table.
    pub i18n: &'env I18n<'text>,
}

/// Root contract implemented by application-defined views.
pub trait UiView<'text, ViewId, Message, const N: usize> {
    /// Declares the view frame, title, and child hierarchy.
    fn configure(&mut self, registration: &mut ViewRegistration<'text, ViewId, N>);

    /// Advances internal state and returns any redraw or message output.
    fn update(
        &mut self,
        _dt_ms: u32,
        _registration: &ViewRegistration<'text, ViewId, N>,
        _env: &ViewEnvironment<'_, 'text>,
    ) -> ViewEvent<Message> {
        ViewEvent::none()
    }

    /// Handles a touch event routed to the view tree.
    fn handle_touch(
        &mut self,
        touch: TouchEvent,
        registration: &ViewRegistration<'text, ViewId, N>,
        env: &ViewEnvironment<'_, 'text>,
    ) -> ViewEvent<Message>;

    /// Draws the current view state.
    fn draw<D>(
        &self,
        display: &mut D,
        registration: &ViewRegistration<'text, ViewId, N>,
        env: &ViewEnvironment<'_, 'text>,
    ) where
        D: UiCanvas;
}