1use rlvgl_core::event::{Event, Key, MAX_TOUCH_POINTS, TouchPoint, TouchState};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum Command<'a> {
8 Inject(EventSpec),
10 InjectTagged(&'a str, EventSpec),
12 Query(QuerySpec<'a>),
14 DumpPixels(DumpSpec),
16 Status,
18 RecordStart,
20 RecordStop,
22 RecordDump,
24 Extension(&'a [u8]),
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33#[allow(missing_docs)]
34pub enum EventSpec {
35 Tick,
37 PressRelease { x: i32, y: i32 },
39 PressDown { x: i32, y: i32 },
41 PointerDown { x: i32, y: i32 },
43 PointerUp { x: i32, y: i32 },
45 PointerMove { x: i32, y: i32 },
47 DoubleTap { x: i32, y: i32 },
49 KeyDown { key: KeySpec },
51 KeyUp { key: KeySpec },
53 Touch {
55 count: u8,
56 points: [TouchPointSpec; MAX_TOUCH_POINTS],
57 },
58}
59
60#[derive(Debug, Clone, Copy, PartialEq, Eq)]
62#[allow(missing_docs)]
63pub enum TouchStateSpec {
64 Down,
66 Up,
68 Contact,
70}
71
72#[derive(Debug, Clone, Copy, PartialEq, Eq)]
74pub struct TouchPointSpec {
75 pub id: u8,
77 pub state: TouchStateSpec,
79 pub x: i32,
81 pub y: i32,
83}
84
85impl TouchStateSpec {
86 pub fn to_core(self) -> TouchState {
88 match self {
89 Self::Down => TouchState::Down,
90 Self::Up => TouchState::Up,
91 Self::Contact => TouchState::Contact,
92 }
93 }
94}
95
96impl Default for TouchPointSpec {
97 fn default() -> Self {
98 Self {
99 id: 0,
100 state: TouchStateSpec::Up,
101 x: 0,
102 y: 0,
103 }
104 }
105}
106
107#[derive(Debug, Clone, Copy, PartialEq, Eq)]
111#[allow(missing_docs)]
112pub enum KeySpec {
113 Escape,
114 Enter,
115 Space,
116 ArrowUp,
117 ArrowDown,
118 ArrowLeft,
119 ArrowRight,
120 Function(u8),
121 Character(char),
122 Other(u32),
123}
124
125#[derive(Debug, Clone, PartialEq, Eq)]
127pub enum QuerySpec<'a> {
128 Bounds(&'a str),
130 Exists(&'a str),
132 ChildCount(&'a str),
134}
135
136#[derive(Debug, Clone, Copy, PartialEq, Eq)]
138pub struct DumpSpec {
139 pub x: i32,
141 pub y: i32,
143 pub width: u16,
145 pub height: u16,
147 pub frames: u8,
149}
150
151impl KeySpec {
156 pub fn to_key(self) -> Key {
158 match self {
159 Self::Escape => Key::Escape,
160 Self::Enter => Key::Enter,
161 Self::Space => Key::Space,
162 Self::ArrowUp => Key::ArrowUp,
163 Self::ArrowDown => Key::ArrowDown,
164 Self::ArrowLeft => Key::ArrowLeft,
165 Self::ArrowRight => Key::ArrowRight,
166 Self::Function(n) => Key::Function(n),
167 Self::Character(c) => Key::Character(c),
168 Self::Other(v) => Key::Other(v),
169 }
170 }
171}
172
173impl EventSpec {
174 pub fn to_event(self) -> Event {
176 match self {
177 Self::Tick => Event::Tick,
178 Self::PressRelease { x, y } => Event::PressRelease { x, y },
179 Self::PressDown { x, y } => Event::PressDown { x, y },
180 Self::PointerDown { x, y } => Event::PointerDown { x, y },
181 Self::PointerUp { x, y } => Event::PointerUp { x, y },
182 Self::PointerMove { x, y } => Event::PointerMove { x, y },
183 Self::DoubleTap { x, y } => Event::DoubleTap { x, y },
184 Self::KeyDown { key } => Event::KeyDown { key: key.to_key() },
185 Self::KeyUp { key } => Event::KeyUp { key: key.to_key() },
186 Self::Touch { count, points } => {
187 let mut core_points = [TouchPoint::default(); MAX_TOUCH_POINTS];
188 for i in 0..MAX_TOUCH_POINTS {
189 core_points[i] = TouchPoint {
190 id: points[i].id,
191 x: points[i].x,
192 y: points[i].y,
193 state: points[i].state.to_core(),
194 };
195 }
196 Event::Touch {
197 count,
198 points: core_points,
199 }
200 }
201 }
202 }
203}