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 drag gesture started: the pointer moved at least the start
105    /// threshold away from its press origin. Emitted once per drag by the
106    /// `DragRecognizer`. A contact that starts a drag will not also
107    /// produce a `PressRelease` (click-vs-drag suppression — INPUT-00 §6).
108    DragStart {
109        /// Horizontal coordinate of the move that crossed the threshold.
110        x: i32,
111        /// Vertical coordinate of the move that crossed the threshold.
112        y: i32,
113        /// Horizontal coordinate of the originating press.
114        origin_x: i32,
115        /// Vertical coordinate of the originating press.
116        origin_y: i32,
117    },
118    /// Pointer position update while a drag is in progress. Emitted by
119    /// the `DragRecognizer` for every `PointerMove` after `DragStart`.
120    DragMove {
121        /// Horizontal coordinate.
122        x: i32,
123        /// Vertical coordinate.
124        y: i32,
125    },
126    /// The dragged pointer lifted; drop position for resolution logic.
127    /// Emitted by the `DragRecognizer` in place of the raw `PointerUp`.
128    DragEnd {
129        /// Horizontal coordinate.
130        x: i32,
131        /// Vertical coordinate.
132        y: i32,
133    },
134    /// A keyboard key was pressed.
135    KeyDown {
136        /// Key that was pressed.
137        key: Key,
138    },
139    /// A keyboard key was released.
140    KeyUp {
141        /// Key that was released.
142        key: Key,
143    },
144    /// Rotary encoder rotation since the last read, in detent steps
145    /// (positive clockwise). Mirrors `lv_indev_data_t::enc_diff`. Emitted
146    /// by an encoder input device, not by raw hardware (LPAR-04 §5.5).
147    Encoder {
148        /// Net rotation steps since the previous read.
149        diff: i32,
150    },
151    /// A held contact reached the long-press threshold. Emitted once per
152    /// contact by the long-press recognizer (LPAR-04 §9). A pending long
153    /// press is disarmed by `DragStart`.
154    LongPress {
155        /// Horizontal coordinate of the held contact.
156        x: i32,
157        /// Vertical coordinate of the held contact.
158        y: i32,
159    },
160    /// A long-pressed contact crossed another repeat interval. Emitted
161    /// every repeat period after the initial `LongPress` by the long-press
162    /// recognizer (LPAR-04 §9).
163    LongPressRepeat {
164        /// Horizontal coordinate of the held contact.
165        x: i32,
166        /// Vertical coordinate of the held contact.
167        y: i32,
168    },
169}
170
171/// Identifiers for keyboard keys.
172#[derive(Debug, Clone, PartialEq, Eq)]
173pub enum Key {
174    /// Escape key.
175    Escape,
176    /// Enter/Return key.
177    Enter,
178    /// Spacebar key.
179    Space,
180    /// Backspace key — editable fields delete the character before the
181    /// caret (WID-00 §5.3).
182    Backspace,
183    /// Up arrow key.
184    ArrowUp,
185    /// Down arrow key.
186    ArrowDown,
187    /// Left arrow key.
188    ArrowLeft,
189    /// Right arrow key.
190    ArrowRight,
191    /// Function key with the given index (1–12).
192    Function(u8),
193    /// Printable character key.
194    Character(char),
195    /// Any other key not explicitly covered above.
196    Other(u32),
197}