faststep 0.1.0

UIKit-inspired embedded UI framework built on embedded-graphics
Documentation
use embedded_graphics::primitives::Rectangle;

/// Redraw classes used by the compatibility [`crate::UiApp`] layer.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AppRedraw {
    /// No redraw is needed.
    None,
    /// A stack transition is active.
    StackMotion,
    /// An interactive region changed.
    Interactive,
    /// The full frame should be redrawn.
    Full,
}

impl AppRedraw {
    /// Merges two redraw requests.
    pub const fn merge(self, other: Self) -> Self {
        match (self, other) {
            (Self::Full, _) | (_, Self::Full) => Self::Full,
            (Self::StackMotion, _) | (_, Self::StackMotion) => Self::StackMotion,
            (Self::Interactive, _) | (_, Self::Interactive) => Self::Interactive,
            _ => Self::None,
        }
    }
}

/// Navigation action requested by the compatibility delegate API.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AppNavigation<ViewId> {
    /// Push a new view.
    Push(ViewId),
    /// Pop the current view.
    Pop,
}

/// Delegate response returned by compatibility views.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ViewResponse<ViewId> {
    /// Redraw request for the frame.
    pub redraw: AppRedraw,
    /// Optional navigation command.
    pub navigation: Option<AppNavigation<ViewId>>,
    /// Whether the interaction was captured.
    pub captured: bool,
}

impl<ViewId> ViewResponse<ViewId> {
    /// Returns a no-op response.
    pub const fn none() -> Self {
        Self {
            redraw: AppRedraw::None,
            navigation: None,
            captured: false,
        }
    }

    /// Creates a redraw-only response.
    pub const fn redraw(redraw: AppRedraw) -> Self {
        Self {
            redraw,
            navigation: None,
            captured: false,
        }
    }

    /// Creates a push-navigation response.
    pub fn push(view: ViewId) -> Self {
        Self {
            redraw: AppRedraw::None,
            navigation: Some(AppNavigation::Push(view)),
            captured: true,
        }
    }

    /// Creates a pop-navigation response.
    pub const fn pop() -> Self {
        Self {
            redraw: AppRedraw::None,
            navigation: Some(AppNavigation::Pop),
            captured: true,
        }
    }

    /// Merges in an extra redraw request.
    pub fn with_redraw(mut self, redraw: AppRedraw) -> Self {
        self.redraw = self.redraw.merge(redraw);
        self
    }

    /// Sets whether the interaction was captured.
    pub const fn with_capture(mut self, captured: bool) -> Self {
        self.captured = captured;
        self
    }
}

/// Result of handling one touch event through the compatibility layer.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct AppTouchResult {
    /// Redraw request for the frame.
    pub redraw: AppRedraw,
    /// Whether the touch was captured.
    pub captured: bool,
}

/// Geometry used during stack-motion presentation.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct StackMotion {
    /// Header region.
    pub header: Rectangle,
    /// Main body region.
    pub body: Rectangle,
    /// Overlay region for the entering or leaving view.
    pub overlay: Rectangle,
}