view_dispatcher: add custom events (#526)
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
30
applications/gui/view_dispatcher.c
Normal file → Executable file
30
applications/gui/view_dispatcher.c
Normal file → Executable file
@@ -51,6 +51,8 @@ void view_dispatcher_run(ViewDispatcher* view_dispatcher) {
|
||||
break;
|
||||
} else if(message.type == ViewDispatcherMessageTypeInput) {
|
||||
view_dispatcher_handle_input(view_dispatcher, &message.input);
|
||||
} else if(message.type == ViewDispatcherMessageTypeCustomEvent) {
|
||||
view_dispatcher_handle_custom_event(view_dispatcher, message.custom_event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,6 +181,34 @@ void view_dispatcher_handle_input(ViewDispatcher* view_dispatcher, InputEvent* e
|
||||
}
|
||||
}
|
||||
|
||||
void view_dispatcher_set_custom_callback(
|
||||
ViewDispatcher* view_dispatcher,
|
||||
CustomEventCallback callback,
|
||||
void* context) {
|
||||
furi_assert(view_dispatcher);
|
||||
furi_assert(callback);
|
||||
|
||||
view_dispatcher->custom_event_cb = callback;
|
||||
view_dispatcher->custom_event_ctx = context;
|
||||
}
|
||||
|
||||
void view_dispatcher_handle_custom_event(ViewDispatcher* view_dispatcher, uint32_t event) {
|
||||
if(view_dispatcher->custom_event_cb) {
|
||||
view_dispatcher->custom_event_cb(event, view_dispatcher->custom_event_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void view_dispatcher_send_custom_event(ViewDispatcher* view_dispatcher, uint32_t event) {
|
||||
furi_assert(view_dispatcher);
|
||||
furi_assert(view_dispatcher->queue);
|
||||
|
||||
ViewDispatcherMessage message;
|
||||
message.type = ViewDispatcherMessageTypeCustomEvent;
|
||||
message.custom_event = event;
|
||||
|
||||
furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK);
|
||||
}
|
||||
|
||||
void view_dispatcher_set_current_view(ViewDispatcher* view_dispatcher, View* view) {
|
||||
furi_assert(view_dispatcher);
|
||||
// Dispatch view exit event
|
||||
|
Reference in New Issue
Block a user