Skip to main content

rlvgl_core/
event.rs

1//! Basic UI events used for widgets.
2
3/// Maximum number of simultaneous touch contacts reported in a single frame.
4pub const MAX_TOUCH_POINTS: usize = 5;
5
6/// Per-point event flag reported by a touch controller.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum TouchState {
9    /// New contact this frame.
10    Down,
11    /// Contact lifted this frame.
12    Up,
13    /// Contact still held, possibly moved.
14    Contact,
15}
16
17/// A single touch contact point within a frame.
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub struct TouchPoint {
20    /// Touch tracking ID assigned by the controller (0–4 for FT5336).
21    pub id: u8,
22    /// Horizontal coordinate.
23    pub x: i32,
24    /// Vertical coordinate.
25    pub y: i32,
26    /// Per-point event flag.
27    pub state: TouchState,
28}
29
30impl Default for TouchPoint {
31    fn default() -> Self {
32        Self {
33            id: 0,
34            x: 0,
35            y: 0,
36            state: TouchState::Up,
37        }
38    }
39}
40
41/// Event types propagated through the widget tree.
42#[derive(Debug, Clone, PartialEq, Eq)]
43pub enum Event {
44    /// Called periodically to advance animations or timers.
45    Tick,
46    /// A pointer (mouse or touch) was pressed at the given coordinates.
47    PointerDown {
48        /// Horizontal coordinate relative to the widget origin.
49        x: i32,
50        /// Vertical coordinate relative to the widget origin.
51        y: i32,
52    },
53    /// The pointer was released.
54    PointerUp {
55        /// Horizontal coordinate relative to the widget origin.
56        x: i32,
57        /// Vertical coordinate relative to the widget origin.
58        y: i32,
59    },
60    /// The pointer moved while still pressed.
61    PointerMove {
62        /// Horizontal coordinate relative to the widget origin.
63        x: i32,
64        /// Vertical coordinate relative to the widget origin.
65        y: i32,
66    },
67    /// Multi-touch frame with per-point data.
68    ///
69    /// Emitted when two or more simultaneous contacts are detected.
70    /// Only `points[..count]` entries are valid.
71    Touch {
72        /// Number of active contact points (2..=[`MAX_TOUCH_POINTS`]).
73        count: u8,
74        /// Per-point data. Entries beyond `count` are meaningless.
75        points: [TouchPoint; MAX_TOUCH_POINTS],
76    },
77    /// Stable contact began (debounced). Use for visual press feedback
78    /// such as button highlighting. Emitted by the gesture recognizer,
79    /// not by raw hardware input.
80    PressDown {
81        /// Horizontal coordinate.
82        x: i32,
83        /// Vertical coordinate.
84        y: i32,
85    },
86    /// Stable contact released (debounced). The primary "click/tap" action
87    /// trigger. Widgets should match this instead of `PointerUp` for
88    /// reliable single-fire behavior.
89    PressRelease {
90        /// Horizontal coordinate.
91        x: i32,
92        /// Vertical coordinate.
93        y: i32,
94    },
95    /// Two consecutive short taps detected at the given coordinates.
96    /// Emitted by the `DoubleTapRecognizer` when two `PressRelease` events
97    /// with short hold durations occur within the double-tap time window.
98    DoubleTap {
99        /// Horizontal coordinate.
100        x: i32,
101        /// Vertical coordinate.
102        y: i32,
103    },
104    /// A keyboard key was pressed.
105    KeyDown {
106        /// Key that was pressed.
107        key: Key,
108    },
109    /// A keyboard key was released.
110    KeyUp {
111        /// Key that was released.
112        key: Key,
113    },
114}
115
116/// Identifiers for keyboard keys.
117#[derive(Debug, Clone, PartialEq, Eq)]
118pub enum Key {
119    /// Escape key.
120    Escape,
121    /// Enter/Return key.
122    Enter,
123    /// Spacebar key.
124    Space,
125    /// Up arrow key.
126    ArrowUp,
127    /// Down arrow key.
128    ArrowDown,
129    /// Left arrow key.
130    ArrowLeft,
131    /// Right arrow key.
132    ArrowRight,
133    /// Function key with the given index (1–12).
134    Function(u8),
135    /// Printable character key.
136    Character(char),
137    /// Any other key not explicitly covered above.
138    Other(u32),
139}