Skip to content

Commit

Permalink
Using view_holder instead of view_dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
nminaylov committed Apr 19, 2024
1 parent ef77790 commit 137a31f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
1 change: 1 addition & 0 deletions applications/services/gui/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ App(
"elements.h",
"view_dispatcher.h",
"view_stack.h",
"view_holder.h",
"modules/button_menu.h",
"modules/byte_input.h",
"modules/popup.h",
Expand Down
38 changes: 19 additions & 19 deletions applications/system/js_app/modules/js_submenu.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <gui/modules/submenu.h>
#include <gui/view_dispatcher.h>
#include <gui/view_holder.h>
#include <gui/view.h>
#include <toolbox/api_lock.h>
#include "../js_modules.h"

typedef struct {
Submenu* submenu;
ViewDispatcher* view_dispatcher;
ViewHolder* view_holder;
FuriApiLock lock;
uint32_t result;
bool accepted;
} JsSubmenuInst;
Expand Down Expand Up @@ -35,15 +37,14 @@ static void submenu_callback(void* context, uint32_t id) {
JsSubmenuInst* submenu = context;
submenu->result = id;
submenu->accepted = true;
view_dispatcher_stop(submenu->view_dispatcher);
api_lock_unlock(submenu->lock);
}

static bool submenu_exit(void* context) {
static void submenu_exit(void* context) {
JsSubmenuInst* submenu = context;
submenu->result = 0;
submenu->accepted = false;
view_dispatcher_stop(submenu->view_dispatcher);
return true;
api_lock_unlock(submenu->lock);
}

static void js_submenu_add_item(struct mjs* mjs) {
Expand Down Expand Up @@ -89,21 +90,20 @@ static void js_submenu_show(struct mjs* mjs) {
JsSubmenuInst* submenu = get_this_ctx(mjs);
if(!check_arg_count(mjs, 0)) return;

submenu->lock = api_lock_alloc_locked();
Gui* gui = furi_record_open(RECORD_GUI);
submenu->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(submenu->view_dispatcher);
view_dispatcher_add_view(submenu->view_dispatcher, 0, submenu_get_view(submenu->submenu));
view_dispatcher_set_event_callback_context(submenu->view_dispatcher, submenu);
view_dispatcher_set_navigation_event_callback(submenu->view_dispatcher, submenu_exit);
view_dispatcher_attach_to_gui(submenu->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
view_dispatcher_switch_to_view(submenu->view_dispatcher, 0);

view_dispatcher_run(submenu->view_dispatcher);

view_dispatcher_remove_view(submenu->view_dispatcher, 0);
view_dispatcher_free(submenu->view_dispatcher);
submenu->view_dispatcher = NULL;
submenu->view_holder = view_holder_alloc();
view_holder_attach_to_gui(submenu->view_holder, gui);
view_holder_set_back_callback(submenu->view_holder, submenu_exit, submenu);

view_holder_set_view(submenu->view_holder, submenu_get_view(submenu->submenu));
view_holder_start(submenu->view_holder);
api_lock_wait_unlock(submenu->lock);

view_holder_stop(submenu->view_holder);
view_holder_free(submenu->view_holder);
furi_record_close(RECORD_GUI);
api_lock_free(submenu->lock);

submenu_reset(submenu->submenu);
if(submenu->accepted) {
Expand Down
13 changes: 12 additions & 1 deletion targets/f18/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,61.1,,
Version,+,61.2,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down Expand Up @@ -27,6 +27,7 @@ Header,+,applications/services/gui/modules/variable_item_list.h,,
Header,+,applications/services/gui/modules/widget.h,,
Header,+,applications/services/gui/modules/widget_elements/widget_element.h,,
Header,+,applications/services/gui/view_dispatcher.h,,
Header,+,applications/services/gui/view_holder.h,,
Header,+,applications/services/gui/view_stack.h,,
Header,+,applications/services/input/input.h,,
Header,+,applications/services/loader/firmware_api/firmware_api.h,,
Expand Down Expand Up @@ -2680,6 +2681,16 @@ Function,+,view_dispatcher_switch_to_view,void,"ViewDispatcher*, uint32_t"
Function,+,view_free,void,View*
Function,+,view_free_model,void,View*
Function,+,view_get_model,void*,View*
Function,+,view_holder_alloc,ViewHolder*,
Function,+,view_holder_attach_to_gui,void,"ViewHolder*, Gui*"
Function,+,view_holder_free,void,ViewHolder*
Function,+,view_holder_get_free_context,void*,ViewHolder*
Function,+,view_holder_set_back_callback,void,"ViewHolder*, BackCallback, void*"
Function,+,view_holder_set_free_callback,void,"ViewHolder*, FreeCallback, void*"
Function,+,view_holder_set_view,void,"ViewHolder*, View*"
Function,+,view_holder_start,void,ViewHolder*
Function,+,view_holder_stop,void,ViewHolder*
Function,+,view_holder_update,void,"View*, void*"
Function,+,view_port_alloc,ViewPort*,
Function,+,view_port_draw_callback_set,void,"ViewPort*, ViewPortDrawCallback, void*"
Function,+,view_port_enabled_set,void,"ViewPort*, _Bool"
Expand Down
13 changes: 12 additions & 1 deletion targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,61.1,,
Version,+,61.2,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Expand Down Expand Up @@ -28,6 +28,7 @@ Header,+,applications/services/gui/modules/variable_item_list.h,,
Header,+,applications/services/gui/modules/widget.h,,
Header,+,applications/services/gui/modules/widget_elements/widget_element.h,,
Header,+,applications/services/gui/view_dispatcher.h,,
Header,+,applications/services/gui/view_holder.h,,
Header,+,applications/services/gui/view_stack.h,,
Header,+,applications/services/input/input.h,,
Header,+,applications/services/loader/firmware_api/firmware_api.h,,
Expand Down Expand Up @@ -3480,6 +3481,16 @@ Function,+,view_dispatcher_switch_to_view,void,"ViewDispatcher*, uint32_t"
Function,+,view_free,void,View*
Function,+,view_free_model,void,View*
Function,+,view_get_model,void*,View*
Function,+,view_holder_alloc,ViewHolder*,
Function,+,view_holder_attach_to_gui,void,"ViewHolder*, Gui*"
Function,+,view_holder_free,void,ViewHolder*
Function,+,view_holder_get_free_context,void*,ViewHolder*
Function,+,view_holder_set_back_callback,void,"ViewHolder*, BackCallback, void*"
Function,+,view_holder_set_free_callback,void,"ViewHolder*, FreeCallback, void*"
Function,+,view_holder_set_view,void,"ViewHolder*, View*"
Function,+,view_holder_start,void,ViewHolder*
Function,+,view_holder_stop,void,ViewHolder*
Function,+,view_holder_update,void,"View*, void*"
Function,+,view_port_alloc,ViewPort*,
Function,+,view_port_draw_callback_set,void,"ViewPort*, ViewPortDrawCallback, void*"
Function,+,view_port_enabled_set,void,"ViewPort*, _Bool"
Expand Down

0 comments on commit 137a31f

Please sign in to comment.