1use crate::{Key, lvgl};
2
3#[derive(Debug, Clone)]
4pub struct Event {
5 pub code: EventKind,
6 pub target: *mut lvgl::lv_obj_t,
7 pub key: Option<Key>,
8}
9
10impl Event {
11 pub fn new(code: EventKind, target: *mut lvgl::lv_obj_t, key: Option<Key>) -> Self {
12 Self { code, target, key }
13 }
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17#[repr(u16)]
18pub enum EventKind {
19 All = lvgl::lv_event_code_t_LV_EVENT_ALL as u16,
20 Pressed = lvgl::lv_event_code_t_LV_EVENT_PRESSED as u16,
21 Pressing = lvgl::lv_event_code_t_LV_EVENT_PRESSING as u16,
22 PressLost = lvgl::lv_event_code_t_LV_EVENT_PRESS_LOST as u16,
23 ShortClicked = lvgl::lv_event_code_t_LV_EVENT_SHORT_CLICKED as u16,
24 SingleClicked = lvgl::lv_event_code_t_LV_EVENT_SINGLE_CLICKED as u16,
25 DoubleClicked = lvgl::lv_event_code_t_LV_EVENT_DOUBLE_CLICKED as u16,
26 TripleClicked = lvgl::lv_event_code_t_LV_EVENT_TRIPLE_CLICKED as u16,
27 LongPressed = lvgl::lv_event_code_t_LV_EVENT_LONG_PRESSED as u16,
28 LongPressedRepeat = lvgl::lv_event_code_t_LV_EVENT_LONG_PRESSED_REPEAT as u16,
29 Clicked = lvgl::lv_event_code_t_LV_EVENT_CLICKED as u16,
30 Released = lvgl::lv_event_code_t_LV_EVENT_RELEASED as u16,
31 ScrollBegin = lvgl::lv_event_code_t_LV_EVENT_SCROLL_BEGIN as u16,
32 ScrollThrowBegin = lvgl::lv_event_code_t_LV_EVENT_SCROLL_THROW_BEGIN as u16,
33 ScrollEnd = lvgl::lv_event_code_t_LV_EVENT_SCROLL_END as u16,
34 Scroll = lvgl::lv_event_code_t_LV_EVENT_SCROLL as u16,
35 Gesture = lvgl::lv_event_code_t_LV_EVENT_GESTURE as u16,
36 Key = lvgl::lv_event_code_t_LV_EVENT_KEY as u16,
37 Rotary = lvgl::lv_event_code_t_LV_EVENT_ROTARY as u16,
38 Focused = lvgl::lv_event_code_t_LV_EVENT_FOCUSED as u16,
39 Defocused = lvgl::lv_event_code_t_LV_EVENT_DEFOCUSED as u16,
40 Leave = lvgl::lv_event_code_t_LV_EVENT_LEAVE as u16,
41 HitTest = lvgl::lv_event_code_t_LV_EVENT_HIT_TEST as u16,
42 InputDeviceReset = lvgl::lv_event_code_t_LV_EVENT_INDEV_RESET as u16,
43 HoverOver = lvgl::lv_event_code_t_LV_EVENT_HOVER_OVER as u16,
44 HoverLeave = lvgl::lv_event_code_t_LV_EVENT_HOVER_LEAVE as u16,
45 CoverCheck = lvgl::lv_event_code_t_LV_EVENT_COVER_CHECK as u16,
46 RefreshExtDrawSize = lvgl::lv_event_code_t_LV_EVENT_REFR_EXT_DRAW_SIZE as u16,
47 DrawMainBegin = lvgl::lv_event_code_t_LV_EVENT_DRAW_MAIN_BEGIN as u16,
48 DrawMain = lvgl::lv_event_code_t_LV_EVENT_DRAW_MAIN as u16,
49 DrawMainEnd = lvgl::lv_event_code_t_LV_EVENT_DRAW_MAIN_END as u16,
50 DrawPostBegin = lvgl::lv_event_code_t_LV_EVENT_DRAW_POST_BEGIN as u16,
51 DrawPost = lvgl::lv_event_code_t_LV_EVENT_DRAW_POST as u16,
52 DrawPostEnd = lvgl::lv_event_code_t_LV_EVENT_DRAW_POST_END as u16,
53 DrawTaskAdded = lvgl::lv_event_code_t_LV_EVENT_DRAW_TASK_ADDED as u16,
54 ValueChanged = lvgl::lv_event_code_t_LV_EVENT_VALUE_CHANGED as u16,
55 Insert = lvgl::lv_event_code_t_LV_EVENT_INSERT as u16,
56 Refresh = lvgl::lv_event_code_t_LV_EVENT_REFRESH as u16,
57 Ready = lvgl::lv_event_code_t_LV_EVENT_READY as u16,
58 Cancel = lvgl::lv_event_code_t_LV_EVENT_CANCEL as u16,
59 Create = lvgl::lv_event_code_t_LV_EVENT_CREATE as u16,
60 Delete = lvgl::lv_event_code_t_LV_EVENT_DELETE as u16,
61 ChildChanged = lvgl::lv_event_code_t_LV_EVENT_CHILD_CHANGED as u16,
62 ChildCreated = lvgl::lv_event_code_t_LV_EVENT_CHILD_CREATED as u16,
63 ChildDeleted = lvgl::lv_event_code_t_LV_EVENT_CHILD_DELETED as u16,
64 ScreenUnloadStart = lvgl::lv_event_code_t_LV_EVENT_SCREEN_UNLOAD_START as u16,
65 ScreenLoadStart = lvgl::lv_event_code_t_LV_EVENT_SCREEN_LOAD_START as u16,
66 ScreenLoaded = lvgl::lv_event_code_t_LV_EVENT_SCREEN_LOADED as u16,
67 ScreenUnloaded = lvgl::lv_event_code_t_LV_EVENT_SCREEN_UNLOADED as u16,
68 SizeChanged = lvgl::lv_event_code_t_LV_EVENT_SIZE_CHANGED as u16,
69 StyleChanged = lvgl::lv_event_code_t_LV_EVENT_STYLE_CHANGED as u16,
70 LayoutChanged = lvgl::lv_event_code_t_LV_EVENT_LAYOUT_CHANGED as u16,
71 GetSelfSize = lvgl::lv_event_code_t_LV_EVENT_GET_SELF_SIZE as u16,
72 InvalidateArea = lvgl::lv_event_code_t_LV_EVENT_INVALIDATE_AREA as u16,
73 ResolutionChanged = lvgl::lv_event_code_t_LV_EVENT_RESOLUTION_CHANGED as u16,
74 ColorFormatChanged = lvgl::lv_event_code_t_LV_EVENT_COLOR_FORMAT_CHANGED as u16,
75 RefreshRequest = lvgl::lv_event_code_t_LV_EVENT_REFR_REQUEST as u16,
76 RefreshStart = lvgl::lv_event_code_t_LV_EVENT_REFR_START as u16,
77 RefreshReady = lvgl::lv_event_code_t_LV_EVENT_REFR_READY as u16,
78 RenderStart = lvgl::lv_event_code_t_LV_EVENT_RENDER_START as u16,
79 RenderReady = lvgl::lv_event_code_t_LV_EVENT_RENDER_READY as u16,
80 FlushStart = lvgl::lv_event_code_t_LV_EVENT_FLUSH_START as u16,
81 FlushFinish = lvgl::lv_event_code_t_LV_EVENT_FLUSH_FINISH as u16,
82 FlushWaitStart = lvgl::lv_event_code_t_LV_EVENT_FLUSH_WAIT_START as u16,
83 FlushWaitFinish = lvgl::lv_event_code_t_LV_EVENT_FLUSH_WAIT_FINISH as u16,
84 VerticalSynchronization = lvgl::lv_event_code_t_LV_EVENT_VSYNC as u16,
85 Last = lvgl::lv_event_code_t_LV_EVENT_LAST as u16,
86 Custom1,
87 Custom2,
88 Custom3,
89 Custom4,
90 Custom5,
91 Custom6,
92 Custom7,
93 Custom8,
94 Custom9,
95 Custom10,
96 Custom11,
97 Custom12,
98 Custom13,
99 Custom14,
100 Custom15,
101 Custom16,
102 Custom17,
103 Custom18,
104 Custom19,
105 Custom20,
106 Custom21,
107 Custom22,
108 Custom23,
109 Custom24,
110 Custom25,
111 Custom26,
112 Custom27,
113 Custom28,
114 Custom29,
115 Custom30,
116 Custom31,
117 Custom32,
118 Preprocess = lvgl::lv_event_code_t_LV_EVENT_PREPROCESS as u16,
119}
120
121impl EventKind {
122 pub const fn into_lvgl_code(self) -> lvgl::lv_event_code_t {
123 self as lvgl::lv_event_code_t
124 }
125
126 pub const fn from_lvgl_code(code: lvgl::lv_event_code_t) -> Self {
127 unsafe { core::mem::transmute(code as u16) }
128 }
129}
130
131impl From<EventKind> for lvgl::lv_event_code_t {
132 fn from(code: EventKind) -> Self {
133 code.into_lvgl_code()
134 }
135}
136
137impl From<lvgl::lv_event_code_t> for EventKind {
138 fn from(code: lvgl::lv_event_code_t) -> Self {
139 EventKind::from_lvgl_code(code)
140 }
141}