faststep 0.1.0

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

/// Phase of a touch interaction.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TouchPhase {
    /// Finger or stylus touched the surface.
    Start,
    /// Pointer moved while still active.
    Move,
    /// Pointer was released.
    End,
    /// Gesture was cancelled by the system.
    Cancel,
}

/// One touch sample routed through the UI framework.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TouchEvent {
    /// Absolute point in display coordinates.
    pub point: Point,
    /// Gesture phase for this sample.
    pub phase: TouchPhase,
    /// Monotonic timestamp in milliseconds.
    pub timestamp_ms: u32,
}

impl TouchEvent {
    /// Creates a new touch event.
    pub const fn new(point: Point, phase: TouchPhase, timestamp_ms: u32) -> Self {
        Self {
            point,
            phase,
            timestamp_ms,
        }
    }

    /// Returns `true` for touch release events.
    pub fn is_release(self) -> bool {
        matches!(self.phase, TouchPhase::End)
    }

    /// Returns `true` while the touch is active.
    pub fn is_active(self) -> bool {
        matches!(self.phase, TouchPhase::Start | TouchPhase::Move)
    }

    /// Returns `true` when the point lies within `frame`.
    pub fn within(self, frame: Rectangle) -> bool {
        let left = frame.top_left.x;
        let top = frame.top_left.y;
        let right = left + frame.size.width as i32;
        let bottom = top + frame.size.height as i32;

        self.point.x >= left && self.point.x < right && self.point.y >= top && self.point.y < bottom
    }
}