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 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 1,
87 Custom2 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 2,
88 CloseRequested = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 3,
89 Custom4 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 4,
90 Custom5 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 5,
91 Custom6 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 6,
92 Custom7 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 7,
93 Custom8 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 8,
94 Custom9 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 9,
95 Custom10 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 10,
96 Custom11 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 11,
97 Custom12 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 12,
98 Custom13 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 13,
99 Custom14 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 14,
100 Custom15 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 15,
101 Custom16 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 16,
102 Custom17 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 17,
103 Custom18 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 18,
104 Custom19 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 19,
105 Custom20 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 20,
106 Custom21 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 21,
107 Custom22 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 22,
108 Custom23 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 23,
109 Custom24 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 24,
110 Custom25 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 25,
111 Custom26 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 26,
112 Custom27 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 27,
113 Custom28 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 28,
114 Custom29 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 29,
115 Custom30 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 30,
116 Custom31 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 31,
117 Custom32 = lvgl::lv_event_code_t_LV_EVENT_LAST as u16 + 32,
118 Preprocess = 0x8000,
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 match code {
128 lvgl::lv_event_code_t_LV_EVENT_ALL => Self::All,
129 lvgl::lv_event_code_t_LV_EVENT_PRESSED => Self::Pressed,
130 lvgl::lv_event_code_t_LV_EVENT_PRESSING => Self::Pressing,
131 lvgl::lv_event_code_t_LV_EVENT_PRESS_LOST => Self::PressLost,
132 lvgl::lv_event_code_t_LV_EVENT_SHORT_CLICKED => Self::ShortClicked,
133 lvgl::lv_event_code_t_LV_EVENT_SINGLE_CLICKED => Self::SingleClicked,
134 lvgl::lv_event_code_t_LV_EVENT_DOUBLE_CLICKED => Self::DoubleClicked,
135 lvgl::lv_event_code_t_LV_EVENT_TRIPLE_CLICKED => Self::TripleClicked,
136 lvgl::lv_event_code_t_LV_EVENT_LONG_PRESSED => Self::LongPressed,
137 lvgl::lv_event_code_t_LV_EVENT_LONG_PRESSED_REPEAT => Self::LongPressedRepeat,
138 lvgl::lv_event_code_t_LV_EVENT_CLICKED => Self::Clicked,
139 lvgl::lv_event_code_t_LV_EVENT_RELEASED => Self::Released,
140 lvgl::lv_event_code_t_LV_EVENT_SCROLL_BEGIN => Self::ScrollBegin,
141 lvgl::lv_event_code_t_LV_EVENT_SCROLL_THROW_BEGIN => Self::ScrollThrowBegin,
142 lvgl::lv_event_code_t_LV_EVENT_SCROLL_END => Self::ScrollEnd,
143 lvgl::lv_event_code_t_LV_EVENT_SCROLL => Self::Scroll,
144 lvgl::lv_event_code_t_LV_EVENT_GESTURE => Self::Gesture,
145 lvgl::lv_event_code_t_LV_EVENT_KEY => Self::Key,
146 lvgl::lv_event_code_t_LV_EVENT_ROTARY => Self::Rotary,
147 lvgl::lv_event_code_t_LV_EVENT_FOCUSED => Self::Focused,
148 lvgl::lv_event_code_t_LV_EVENT_DEFOCUSED => Self::Defocused,
149 lvgl::lv_event_code_t_LV_EVENT_LEAVE => Self::Leave,
150 lvgl::lv_event_code_t_LV_EVENT_HIT_TEST => Self::HitTest,
151 lvgl::lv_event_code_t_LV_EVENT_INDEV_RESET => Self::InputDeviceReset,
152 lvgl::lv_event_code_t_LV_EVENT_HOVER_OVER => Self::HoverOver,
153 lvgl::lv_event_code_t_LV_EVENT_HOVER_LEAVE => Self::HoverLeave,
154 lvgl::lv_event_code_t_LV_EVENT_COVER_CHECK => Self::CoverCheck,
155 lvgl::lv_event_code_t_LV_EVENT_REFR_EXT_DRAW_SIZE => Self::RefreshExtDrawSize,
156 lvgl::lv_event_code_t_LV_EVENT_DRAW_MAIN_BEGIN => Self::DrawMainBegin,
157 lvgl::lv_event_code_t_LV_EVENT_DRAW_MAIN => Self::DrawMain,
158 lvgl::lv_event_code_t_LV_EVENT_DRAW_MAIN_END => Self::DrawMainEnd,
159 lvgl::lv_event_code_t_LV_EVENT_DRAW_POST_BEGIN => Self::DrawPostBegin,
160 lvgl::lv_event_code_t_LV_EVENT_DRAW_POST => Self::DrawPost,
161 lvgl::lv_event_code_t_LV_EVENT_DRAW_POST_END => Self::DrawPostEnd,
162 lvgl::lv_event_code_t_LV_EVENT_DRAW_TASK_ADDED => Self::DrawTaskAdded,
163 lvgl::lv_event_code_t_LV_EVENT_VALUE_CHANGED => Self::ValueChanged,
164 lvgl::lv_event_code_t_LV_EVENT_INSERT => Self::Insert,
165 lvgl::lv_event_code_t_LV_EVENT_REFRESH => Self::Refresh,
166 lvgl::lv_event_code_t_LV_EVENT_READY => Self::Ready,
167 lvgl::lv_event_code_t_LV_EVENT_CANCEL => Self::Cancel,
168 lvgl::lv_event_code_t_LV_EVENT_CREATE => Self::Create,
169 lvgl::lv_event_code_t_LV_EVENT_DELETE => Self::Delete,
170 lvgl::lv_event_code_t_LV_EVENT_CHILD_CHANGED => Self::ChildChanged,
171 lvgl::lv_event_code_t_LV_EVENT_CHILD_CREATED => Self::ChildCreated,
172 lvgl::lv_event_code_t_LV_EVENT_CHILD_DELETED => Self::ChildDeleted,
173 lvgl::lv_event_code_t_LV_EVENT_SCREEN_UNLOAD_START => Self::ScreenUnloadStart,
174 lvgl::lv_event_code_t_LV_EVENT_SCREEN_LOAD_START => Self::ScreenLoadStart,
175 lvgl::lv_event_code_t_LV_EVENT_SCREEN_LOADED => Self::ScreenLoaded,
176 lvgl::lv_event_code_t_LV_EVENT_SCREEN_UNLOADED => Self::ScreenUnloaded,
177 lvgl::lv_event_code_t_LV_EVENT_SIZE_CHANGED => Self::SizeChanged,
178 lvgl::lv_event_code_t_LV_EVENT_STYLE_CHANGED => Self::StyleChanged,
179 lvgl::lv_event_code_t_LV_EVENT_LAYOUT_CHANGED => Self::LayoutChanged,
180 lvgl::lv_event_code_t_LV_EVENT_GET_SELF_SIZE => Self::GetSelfSize,
181 lvgl::lv_event_code_t_LV_EVENT_INVALIDATE_AREA => Self::InvalidateArea,
182 lvgl::lv_event_code_t_LV_EVENT_RESOLUTION_CHANGED => Self::ResolutionChanged,
183 lvgl::lv_event_code_t_LV_EVENT_COLOR_FORMAT_CHANGED => Self::ColorFormatChanged,
184 lvgl::lv_event_code_t_LV_EVENT_REFR_REQUEST => Self::RefreshRequest,
185 lvgl::lv_event_code_t_LV_EVENT_REFR_START => Self::RefreshStart,
186 lvgl::lv_event_code_t_LV_EVENT_REFR_READY => Self::RefreshReady,
187 lvgl::lv_event_code_t_LV_EVENT_RENDER_START => Self::RenderStart,
188 lvgl::lv_event_code_t_LV_EVENT_RENDER_READY => Self::RenderReady,
189 lvgl::lv_event_code_t_LV_EVENT_FLUSH_START => Self::FlushStart,
190 lvgl::lv_event_code_t_LV_EVENT_FLUSH_FINISH => Self::FlushFinish,
191 lvgl::lv_event_code_t_LV_EVENT_FLUSH_WAIT_START => Self::FlushWaitStart,
192 lvgl::lv_event_code_t_LV_EVENT_FLUSH_WAIT_FINISH => Self::FlushWaitFinish,
193 lvgl::lv_event_code_t_LV_EVENT_VSYNC => Self::VerticalSynchronization,
194 lvgl::lv_event_code_t_LV_EVENT_LAST => Self::Last,
195 lvgl::lv_event_code_t_LV_EVENT_PREPROCESS => Self::Preprocess,
196 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 1 => Self::Custom1,
197 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 2 => Self::Custom2,
198 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 3 => Self::CloseRequested,
199 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 4 => Self::Custom4,
200 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 5 => Self::Custom5,
201 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 6 => Self::Custom6,
202 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 7 => Self::Custom7,
203 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 8 => Self::Custom8,
204 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 9 => Self::Custom9,
205 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 10 => Self::Custom10,
206 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 11 => Self::Custom11,
207 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 12 => Self::Custom12,
208 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 13 => Self::Custom13,
209 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 14 => Self::Custom14,
210 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 15 => Self::Custom15,
211 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 16 => Self::Custom16,
212 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 17 => Self::Custom17,
213 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 18 => Self::Custom18,
214 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 19 => Self::Custom19,
215 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 20 => Self::Custom20,
216 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 21 => Self::Custom21,
217 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 22 => Self::Custom22,
218 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 23 => Self::Custom23,
219 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 24 => Self::Custom24,
220 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 25 => Self::Custom25,
221 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 26 => Self::Custom26,
222 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 27 => Self::Custom27,
223 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 28 => Self::Custom28,
224 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 29 => Self::Custom29,
225 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 30 => Self::Custom30,
226 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 31 => Self::Custom31,
227 code if code == lvgl::lv_event_code_t_LV_EVENT_LAST + 32 => Self::Custom32,
228 _ => Self::Last,
229 }
230 }
231}
232
233impl From<EventKind> for lvgl::lv_event_code_t {
234 fn from(code: EventKind) -> Self {
235 code.into_lvgl_code()
236 }
237}
238
239impl From<lvgl::lv_event_code_t> for EventKind {
240 fn from(code: lvgl::lv_event_code_t) -> Self {
241 EventKind::from_lvgl_code(code)
242 }
243}