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