1use embedded_graphics::{prelude::Point, primitives::Rectangle};
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum TouchPhase {
6 Start,
8 Move,
10 End,
12 Cancel,
14}
15
16#[derive(Clone, Copy, Debug, PartialEq, Eq)]
18pub struct TouchEvent {
19 pub point: Point,
21 pub phase: TouchPhase,
23 pub timestamp_ms: u32,
25}
26
27impl TouchEvent {
28 pub const fn new(point: Point, phase: TouchPhase, timestamp_ms: u32) -> Self {
30 Self {
31 point,
32 phase,
33 timestamp_ms,
34 }
35 }
36
37 pub fn is_release(self) -> bool {
39 matches!(self.phase, TouchPhase::End)
40 }
41
42 pub fn is_active(self) -> bool {
44 matches!(self.phase, TouchPhase::Start | TouchPhase::Move)
45 }
46
47 pub fn within(self, frame: Rectangle) -> bool {
49 let left = frame.top_left.x;
50 let top = frame.top_left.y;
51 let right = left + frame.size.width as i32;
52 let bottom = top + frame.size.height as i32;
53
54 self.point.x >= left && self.point.x < right && self.point.y >= top && self.point.y < bottom
55 }
56}