use rlvgl_core::event::{Event, Key, MAX_TOUCH_POINTS, TouchPoint, TouchState};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Command<'a> {
Inject(EventSpec),
InjectTagged(&'a str, EventSpec),
Query(QuerySpec<'a>),
DumpPixels(DumpSpec),
Status,
RecordStart,
RecordStop,
RecordDump,
Extension(&'a [u8]),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum EventSpec {
Tick,
PressRelease { x: i32, y: i32 },
PressDown { x: i32, y: i32 },
PointerDown { x: i32, y: i32 },
PointerUp { x: i32, y: i32 },
PointerMove { x: i32, y: i32 },
DoubleTap { x: i32, y: i32 },
KeyDown { key: KeySpec },
KeyUp { key: KeySpec },
Touch {
count: u8,
points: [TouchPointSpec; MAX_TOUCH_POINTS],
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum TouchStateSpec {
Down,
Up,
Contact,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TouchPointSpec {
pub id: u8,
pub state: TouchStateSpec,
pub x: i32,
pub y: i32,
}
impl TouchStateSpec {
pub fn to_core(self) -> TouchState {
match self {
Self::Down => TouchState::Down,
Self::Up => TouchState::Up,
Self::Contact => TouchState::Contact,
}
}
}
impl Default for TouchPointSpec {
fn default() -> Self {
Self {
id: 0,
state: TouchStateSpec::Up,
x: 0,
y: 0,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum KeySpec {
Escape,
Enter,
Space,
ArrowUp,
ArrowDown,
ArrowLeft,
ArrowRight,
Function(u8),
Character(char),
Other(u32),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum QuerySpec<'a> {
Bounds(&'a str),
Exists(&'a str),
ChildCount(&'a str),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DumpSpec {
pub x: i32,
pub y: i32,
pub width: u16,
pub height: u16,
pub frames: u8,
}
impl KeySpec {
pub fn to_key(self) -> Key {
match self {
Self::Escape => Key::Escape,
Self::Enter => Key::Enter,
Self::Space => Key::Space,
Self::ArrowUp => Key::ArrowUp,
Self::ArrowDown => Key::ArrowDown,
Self::ArrowLeft => Key::ArrowLeft,
Self::ArrowRight => Key::ArrowRight,
Self::Function(n) => Key::Function(n),
Self::Character(c) => Key::Character(c),
Self::Other(v) => Key::Other(v),
}
}
}
impl EventSpec {
pub fn to_event(self) -> Event {
match self {
Self::Tick => Event::Tick,
Self::PressRelease { x, y } => Event::PressRelease { x, y },
Self::PressDown { x, y } => Event::PressDown { x, y },
Self::PointerDown { x, y } => Event::PointerDown { x, y },
Self::PointerUp { x, y } => Event::PointerUp { x, y },
Self::PointerMove { x, y } => Event::PointerMove { x, y },
Self::DoubleTap { x, y } => Event::DoubleTap { x, y },
Self::KeyDown { key } => Event::KeyDown { key: key.to_key() },
Self::KeyUp { key } => Event::KeyUp { key: key.to_key() },
Self::Touch { count, points } => {
let mut core_points = [TouchPoint::default(); MAX_TOUCH_POINTS];
for i in 0..MAX_TOUCH_POINTS {
core_points[i] = TouchPoint {
id: points[i].id,
x: points[i].x,
y: points[i].y,
state: points[i].state.to_core(),
};
}
Event::Touch {
count,
points: core_points,
}
}
}
}
}