diff --git a/applications/app-loader/app-loader.c b/applications/app-loader/app-loader.c index c7ffd7847..c1b31339c 100644 --- a/applications/app-loader/app-loader.c +++ b/applications/app-loader/app-loader.c @@ -10,7 +10,7 @@ typedef struct { osThreadAttr_t app_thread_attr; osThreadId_t app_thread_id; - Widget* widget; + ViewPort* view_port; const FuriApplication* current_app; } AppLoaderState; @@ -38,7 +38,7 @@ static void input_callback(InputEvent* input_event, void* _ctx) { if(input_event->state && input_event->input == InputBack) { osThreadTerminate(ctx->app_thread_id); - widget_enabled_set(ctx->widget, false); + view_port_enabled_set(ctx->view_port, false); api_hal_timebase_insomnia_exit(); } } @@ -48,7 +48,7 @@ static void handle_menu(void* _ctx) { if(ctx->app->app == NULL) return; - widget_enabled_set(ctx->state->widget, true); + view_port_enabled_set(ctx->state->view_port, true); // TODO how to call this? // furiac_wait_libs(&FLIPPER_STARTUP[i].libs); @@ -100,16 +100,16 @@ void app_loader(void* p) { AppLoaderState state; state.app_thread_id = NULL; - state.widget = widget_alloc(); - widget_enabled_set(state.widget, false); - widget_draw_callback_set(state.widget, render_callback, &state); - widget_input_callback_set(state.widget, input_callback, &state); + state.view_port = view_port_alloc(); + view_port_enabled_set(state.view_port, false); + view_port_draw_callback_set(state.view_port, render_callback, &state); + view_port_input_callback_set(state.view_port, input_callback, &state); ValueMutex* menu_mutex = furi_record_open("menu"); Cli* cli = furi_record_open("cli"); Gui* gui = furi_record_open("gui"); - gui_add_widget(gui, state.widget, GuiLayerFullscreen); + gui_add_view_port(gui, state.view_port, GuiLayerFullscreen); // Main menu with_value_mutex( diff --git a/applications/applications.c b/applications/applications.c index b9eab9f70..70bf28d87 100644 --- a/applications/applications.c +++ b/applications/applications.c @@ -6,8 +6,6 @@ void flipper_test_app(void* p); void application_blink(void* p); void application_uart_write(void* p); -void application_ipc_display(void* p); -void application_ipc_widget(void* p); void application_input_dump(void* p); void display_u8g2(void* p); void u8g2_example(void* p); @@ -112,14 +110,6 @@ const FuriApplication FLIPPER_SERVICES[] = { {.app = flipper_test_app, .name = "test app", .stack_size = 1024, .icon = A_Plugins_14}, #endif -#ifdef APP_EXAMPLE_IPC - {.app = application_ipc_display, - .name = "ipc display", - .stack_size = 1024, - .icon = A_Plugins_14}, - {.app = application_ipc_widget, .name = "ipc widget", .stack_size = 1024, .icon = A_Plugins_14}, -#endif - #ifdef APP_EXAMPLE_QRCODE {.app = u8g2_qrcode, .name = "u8g2_qrcode", .stack_size = 1024, .icon = A_Plugins_14}, #endif diff --git a/applications/bt/bt.c b/applications/bt/bt.c index d3af0dfe3..1621331e1 100644 --- a/applications/bt/bt.c +++ b/applications/bt/bt.c @@ -9,11 +9,11 @@ Bt* bt_alloc() { bt->menu = furi_record_open("menu"); bt->statusbar_icon = assets_icons_get(I_Bluetooth_5x8); - bt->statusbar_widget = widget_alloc(); - widget_set_width(bt->statusbar_widget, icon_get_width(bt->statusbar_icon)); - widget_draw_callback_set(bt->statusbar_widget, bt_draw_statusbar_callback, bt); - widget_enabled_set(bt->statusbar_widget, false); - gui_add_widget(bt->gui, bt->statusbar_widget, GuiLayerStatusBarLeft); + bt->statusbar_view_port = view_port_alloc(); + view_port_set_width(bt->statusbar_view_port, icon_get_width(bt->statusbar_icon)); + view_port_draw_callback_set(bt->statusbar_view_port, bt_draw_statusbar_callback, bt); + view_port_enabled_set(bt->statusbar_view_port, false); + gui_add_view_port(bt->gui, bt->statusbar_view_port, GuiLayerStatusBarLeft); bt->menu_icon = assets_icons_get(A_Bluetooth_14); bt->menu_item = menu_item_alloc_menu("Bluetooth", bt->menu_icon); @@ -45,7 +45,7 @@ void bt_task() { api_hal_bt_init(); while(1) { - widget_enabled_set(bt->statusbar_widget, api_hal_bt_is_alive()); + view_port_enabled_set(bt->statusbar_view_port, api_hal_bt_is_alive()); osDelay(1000); } } diff --git a/applications/bt/bt_i.h b/applications/bt/bt_i.h index 01acfca8d..e843a7381 100644 --- a/applications/bt/bt_i.h +++ b/applications/bt/bt_i.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -18,7 +18,7 @@ typedef struct { ValueMutex* menu; // Status bar Icon* statusbar_icon; - Widget* statusbar_widget; + ViewPort* statusbar_view_port; // Menu Icon* menu_icon; MenuItem* menu_item; diff --git a/applications/cc1101-workaround/cc1101-workaround.cpp b/applications/cc1101-workaround/cc1101-workaround.cpp index fab6e76e3..30e90507e 100644 --- a/applications/cc1101-workaround/cc1101-workaround.cpp +++ b/applications/cc1101-workaround/cc1101-workaround.cpp @@ -363,18 +363,18 @@ extern "C" void cc1101_workaround(void* p) { furiac_exit(NULL); } - Widget* widget = widget_alloc(); + ViewPort* view_port = view_port_alloc(); - widget_draw_callback_set(widget, render_callback, &state_mutex); - widget_input_callback_set(widget, input_callback, event_queue); + view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_input_callback_set(view_port, input_callback, event_queue); - // Open GUI and register widget + // Open GUI and register view_port Gui* gui = (Gui*)furi_record_open("gui"); if(gui == NULL) { printf("[cc1101] gui is not available\r\n"); furiac_exit(NULL); } - gui_add_widget(gui, widget, GuiLayerFullscreen); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); gpio_init(&debug_0, GpioModeOutputPushPull); gpio_write((GpioPin*)&debug_0, false); @@ -433,8 +433,8 @@ extern "C" void cc1101_workaround(void* p) { printf("[cc1101] go to power down\r\n"); - // TODO remove all widgets create by app - widget_enabled_set(widget, false); + // TODO remove all view_ports create by app + view_port_enabled_set(view_port, false); furiac_exit(NULL); } @@ -582,6 +582,6 @@ extern "C" void cc1101_workaround(void* p) { } release_mutex(&state_mutex, state); - widget_update(widget); + view_port_update(view_port); } } \ No newline at end of file diff --git a/applications/examples/u8g2_qrcode.c b/applications/examples/u8g2_qrcode.c index 694617928..7cc0b8885 100644 --- a/applications/examples/u8g2_qrcode.c +++ b/applications/examples/u8g2_qrcode.c @@ -37,7 +37,7 @@ void u8g2_qrcode(void* p) { qrcode_initText(&qrcode, qrcodeBytes, qr_version, qr_error_correction, "HELLO FLIPPER"); if(fb_record == NULL) { - printf("[widget] cannot create fb record\r\n"); + printf("[view_port] cannot create fb record\r\n"); furiac_exit(NULL); } diff --git a/applications/floopper-bloopper b/applications/floopper-bloopper index 7ba50ef91..2d66001e8 160000 --- a/applications/floopper-bloopper +++ b/applications/floopper-bloopper @@ -1 +1 @@ -Subproject commit 7ba50ef912566c78d2ddd37ab5912a8cada5c35d +Subproject commit 2d66001e894d80995125fffc2e8ed17a970ee428 diff --git a/applications/gpio-tester/gpio-tester.c b/applications/gpio-tester/gpio-tester.c index bb8293a7d..92b6bd915 100644 --- a/applications/gpio-tester/gpio-tester.c +++ b/applications/gpio-tester/gpio-tester.c @@ -70,14 +70,14 @@ void app_gpio_test(void* p) { furiac_exit(NULL); } - Widget* widget = widget_alloc(); + ViewPort* view_port = view_port_alloc(); - widget_draw_callback_set(widget, render_callback, &state_mutex); - widget_input_callback_set(widget, input_callback, event_queue); + view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_input_callback_set(view_port, input_callback, event_queue); - // Open GUI and register widget + // Open GUI and register view_port Gui* gui = furi_record_open("gui"); - gui_add_widget(gui, widget, GuiLayerFullscreen); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); // configure pin for(uint8_t i = 0; i < sizeof(GPIO_PINS) / sizeof(GPIO_PINS[0]); i++) { @@ -95,8 +95,8 @@ void app_gpio_test(void* p) { if(event.type == EventTypeKey) { if(event.value.input.state && event.value.input.input == InputBack) { printf("[gpio-tester] bye!\r\n"); - // TODO remove all widgets create by app - widget_enabled_set(widget, false); + // TODO remove all view_ports create by app + view_port_enabled_set(view_port, false); furiac_exit(NULL); } @@ -121,6 +121,6 @@ void app_gpio_test(void* p) { } release_mutex(&state_mutex, state); - widget_update(widget); + view_port_update(view_port); } } diff --git a/applications/gui/gui.c b/applications/gui/gui.c index 38584ea12..719adc634 100644 --- a/applications/gui/gui.c +++ b/applications/gui/gui.c @@ -8,24 +8,24 @@ #include "gui_event.h" #include "canvas.h" #include "canvas_i.h" -#include "widget.h" -#include "widget_i.h" +#include "view_port.h" +#include "view_port_i.h" -ARRAY_DEF(WidgetArray, Widget*, M_PTR_OPLIST); +ARRAY_DEF(ViewPortArray, ViewPort*, M_PTR_OPLIST); struct Gui { GuiEvent* event; Canvas* canvas; - WidgetArray_t layers[GuiLayerMAX]; + ViewPortArray_t layers[GuiLayerMAX]; osMutexId_t mutex; }; -Widget* gui_widget_find_enabled(WidgetArray_t array) { - size_t widgets_count = WidgetArray_size(array); - for(size_t i = 0; i < widgets_count; i++) { - Widget* widget = *WidgetArray_get(array, widgets_count - i - 1); - if(widget_is_enabled(widget)) { - return widget; +ViewPort* gui_view_port_find_enabled(ViewPortArray_t array) { + size_t view_ports_count = ViewPortArray_size(array); + for(size_t i = 0; i < view_ports_count; i++) { + ViewPort* view_port = *ViewPortArray_get(array, view_ports_count - i - 1); + if(view_port_is_enabled(view_port)) { + return view_port; } } return NULL; @@ -40,9 +40,9 @@ void gui_update(Gui* gui) { bool gui_redraw_fs(Gui* gui) { canvas_frame_set(gui->canvas, 0, 0, GUI_DISPLAY_WIDTH, GUI_DISPLAY_HEIGHT); - Widget* widget = gui_widget_find_enabled(gui->layers[GuiLayerFullscreen]); - if(widget) { - widget_draw(widget, gui->canvas); + ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerFullscreen]); + if(view_port) { + view_port_draw(view_port, gui->canvas); return true; } else { return false; @@ -50,50 +50,50 @@ bool gui_redraw_fs(Gui* gui) { } void gui_redraw_status_bar(Gui* gui) { - WidgetArray_it_t it; + ViewPortArray_it_t it; uint8_t x; uint8_t x_used = 0; uint8_t width; - Widget* widget; + ViewPort* view_port; // Right side x = 128; - WidgetArray_it(it, gui->layers[GuiLayerStatusBarRight]); - while(!WidgetArray_end_p(it) && x_used < GUI_STATUS_BAR_WIDTH) { - // Render widget; - widget = *WidgetArray_ref(it); - if(widget_is_enabled(widget)) { - width = widget_get_width(widget); + ViewPortArray_it(it, gui->layers[GuiLayerStatusBarRight]); + while(!ViewPortArray_end_p(it) && x_used < GUI_STATUS_BAR_WIDTH) { + // Render view_port; + view_port = *ViewPortArray_ref(it); + if(view_port_is_enabled(view_port)) { + width = view_port_get_width(view_port); if(!width) width = 8; x_used += width; x -= (width + 2); canvas_frame_set(gui->canvas, x, GUI_STATUS_BAR_Y, width, GUI_STATUS_BAR_HEIGHT); - widget_draw(widget, gui->canvas); + view_port_draw(view_port, gui->canvas); } - WidgetArray_next(it); + ViewPortArray_next(it); } // Left side x = 0; - WidgetArray_it(it, gui->layers[GuiLayerStatusBarLeft]); - while(!WidgetArray_end_p(it) && x_used < GUI_STATUS_BAR_WIDTH) { - // Render widget; - widget = *WidgetArray_ref(it); - if(widget_is_enabled(widget)) { - width = widget_get_width(widget); + ViewPortArray_it(it, gui->layers[GuiLayerStatusBarLeft]); + while(!ViewPortArray_end_p(it) && x_used < GUI_STATUS_BAR_WIDTH) { + // Render view_port; + view_port = *ViewPortArray_ref(it); + if(view_port_is_enabled(view_port)) { + width = view_port_get_width(view_port); if(!width) width = 8; x_used += width; canvas_frame_set(gui->canvas, x, GUI_STATUS_BAR_Y, width, GUI_STATUS_BAR_HEIGHT); - widget_draw(widget, gui->canvas); + view_port_draw(view_port, gui->canvas); x += (width + 2); } - WidgetArray_next(it); + ViewPortArray_next(it); } } bool gui_redraw_normal(Gui* gui) { canvas_frame_set(gui->canvas, GUI_MAIN_X, GUI_MAIN_Y, GUI_MAIN_WIDTH, GUI_MAIN_HEIGHT); - Widget* widget = gui_widget_find_enabled(gui->layers[GuiLayerMain]); - if(widget) { - widget_draw(widget, gui->canvas); + ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerMain]); + if(view_port) { + view_port_draw(view_port, gui->canvas); return true; } return false; @@ -101,9 +101,9 @@ bool gui_redraw_normal(Gui* gui) { bool gui_redraw_none(Gui* gui) { canvas_frame_set(gui->canvas, GUI_MAIN_X, GUI_MAIN_Y, GUI_MAIN_WIDTH, GUI_MAIN_HEIGHT); - Widget* widget = gui_widget_find_enabled(gui->layers[GuiLayerNone]); - if(widget) { - widget_draw(widget, gui->canvas); + ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerNone]); + if(view_port) { + view_port_draw(view_port, gui->canvas); return true; } @@ -133,12 +133,12 @@ void gui_input(Gui* gui, InputEvent* input_event) { gui_lock(gui); - Widget* widget = gui_widget_find_enabled(gui->layers[GuiLayerFullscreen]); - if(!widget) widget = gui_widget_find_enabled(gui->layers[GuiLayerMain]); - if(!widget) widget = gui_widget_find_enabled(gui->layers[GuiLayerNone]); + ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerFullscreen]); + if(!view_port) view_port = gui_view_port_find_enabled(gui->layers[GuiLayerMain]); + if(!view_port) view_port = gui_view_port_find_enabled(gui->layers[GuiLayerNone]); - if(widget) { - widget_input(widget, input_event); + if(view_port) { + view_port_input(view_port, input_event); } gui_unlock(gui); @@ -154,33 +154,33 @@ void gui_unlock(Gui* gui) { furi_check(osMutexRelease(gui->mutex) == osOK); } -void gui_add_widget(Gui* gui, Widget* widget, GuiLayer layer) { +void gui_add_view_port(Gui* gui, ViewPort* view_port, GuiLayer layer) { furi_assert(gui); - furi_assert(widget); + furi_assert(view_port); furi_check(layer < GuiLayerMAX); gui_lock(gui); - WidgetArray_push_back(gui->layers[layer], widget); - widget_gui_set(widget, gui); + ViewPortArray_push_back(gui->layers[layer], view_port); + view_port_gui_set(view_port, gui); gui_unlock(gui); gui_update(gui); } -void gui_remove_widget(Gui* gui, Widget* widget) { +void gui_remove_view_port(Gui* gui, ViewPort* view_port) { furi_assert(gui); - furi_assert(widget); + furi_assert(view_port); gui_lock(gui); - widget_gui_set(widget, NULL); - WidgetArray_it_t it; + view_port_gui_set(view_port, NULL); + ViewPortArray_it_t it; for(size_t i = 0; i < GuiLayerMAX; i++) { - WidgetArray_it(it, gui->layers[i]); - while(!WidgetArray_end_p(it)) { - if(*WidgetArray_ref(it) == widget) { - WidgetArray_remove(gui->layers[i], it); + ViewPortArray_it(it, gui->layers[i]); + while(!ViewPortArray_end_p(it)) { + if(*ViewPortArray_ref(it) == view_port) { + ViewPortArray_remove(gui->layers[i], it); } - WidgetArray_next(it); + ViewPortArray_next(it); } } @@ -198,7 +198,7 @@ Gui* gui_alloc() { gui->canvas = canvas_init(); // Compose Layers for(size_t i = 0; i < GuiLayerMAX; i++) { - WidgetArray_init(gui->layers[i]); + ViewPortArray_init(gui->layers[i]); } return gui; diff --git a/applications/gui/gui.h b/applications/gui/gui.h index a314109d2..fd8ca26cc 100644 --- a/applications/gui/gui.h +++ b/applications/gui/gui.h @@ -1,6 +1,6 @@ #pragma once -#include "widget.h" +#include "view_port.h" #include "canvas.h" #ifdef __cplusplus @@ -23,10 +23,10 @@ extern "C" { typedef enum { GuiLayerNone, /* Special layer for internal use only */ - GuiLayerStatusBarLeft, /* Status bar left-side widget layer, auto-layout */ - GuiLayerStatusBarRight, /* Status bar right-side widget layer, auto-layout */ - GuiLayerMain, /* Main widget layer, status bar is shown */ - GuiLayerFullscreen, /* Fullscreen widget layer */ + GuiLayerStatusBarLeft, /* Status bar left-side view_port layer, auto-layout */ + GuiLayerStatusBarRight, /* Status bar right-side view_port layer, auto-layout */ + GuiLayerMain, /* Main view_port layer, status bar is shown */ + GuiLayerFullscreen, /* Fullscreen view_port layer */ GuiLayerMAX /* Don't use or move, special value */ } GuiLayer; @@ -34,16 +34,16 @@ typedef enum { typedef struct Gui Gui; /* - * Add widget to widget tree + * Add view_port to view_port tree * @remarks thread safe */ -void gui_add_widget(Gui* gui, Widget* widget, GuiLayer layer); +void gui_add_view_port(Gui* gui, ViewPort* view_port, GuiLayer layer); /* - * Remove widget from rendering tree + * Remove view_port from rendering tree * @remarks thread safe */ -void gui_remove_widget(Gui* gui, Widget* widget); +void gui_remove_view_port(Gui* gui, ViewPort* view_port); #ifdef __cplusplus } diff --git a/applications/gui/view.h b/applications/gui/view.h index 832a3ef90..f050f3025 100644 --- a/applications/gui/view.h +++ b/applications/gui/view.h @@ -7,7 +7,7 @@ extern "C" { #endif -/* Hides drawing widget */ +/* Hides drawing view_port */ #define VIEW_NONE 0xFFFFFFFF /* Ignore navigation event */ #define VIEW_IGNORE 0xFFFFFFFE diff --git a/applications/gui/view_dispatcher.c b/applications/gui/view_dispatcher.c index a095d17bd..b8ec50d2a 100644 --- a/applications/gui/view_dispatcher.c +++ b/applications/gui/view_dispatcher.c @@ -3,12 +3,12 @@ ViewDispatcher* view_dispatcher_alloc() { ViewDispatcher* view_dispatcher = furi_alloc(sizeof(ViewDispatcher)); - view_dispatcher->widget = widget_alloc(); - widget_draw_callback_set( - view_dispatcher->widget, view_dispatcher_draw_callback, view_dispatcher); - widget_input_callback_set( - view_dispatcher->widget, view_dispatcher_input_callback, view_dispatcher); - widget_enabled_set(view_dispatcher->widget, false); + view_dispatcher->view_port = view_port_alloc(); + view_port_draw_callback_set( + view_dispatcher->view_port, view_dispatcher_draw_callback, view_dispatcher); + view_port_input_callback_set( + view_dispatcher->view_port, view_dispatcher_input_callback, view_dispatcher); + view_port_enabled_set(view_dispatcher->view_port, false); ViewDict_init(view_dispatcher->views); @@ -18,7 +18,7 @@ ViewDispatcher* view_dispatcher_alloc() { void view_dispatcher_free(ViewDispatcher* view_dispatcher) { // Detach from gui if(view_dispatcher->gui) { - gui_remove_widget(view_dispatcher->gui, view_dispatcher->widget); + gui_remove_view_port(view_dispatcher->gui, view_dispatcher->view_port); } // Free views ViewDict_it_t it; @@ -46,7 +46,7 @@ void view_dispatcher_switch_to_view(ViewDispatcher* view_dispatcher, uint32_t vi furi_assert(view_dispatcher); if(view_id == VIEW_NONE) { view_dispatcher->current_view = NULL; - widget_enabled_set(view_dispatcher->widget, false); + view_port_enabled_set(view_dispatcher->view_port, false); } else if(view_id == VIEW_IGNORE) { } else if(view_id == VIEW_DESTROY) { view_dispatcher_free(view_dispatcher); @@ -54,8 +54,8 @@ void view_dispatcher_switch_to_view(ViewDispatcher* view_dispatcher, uint32_t vi View** view_pp = ViewDict_get(view_dispatcher->views, view_id); furi_check(view_pp != NULL); view_dispatcher->current_view = *view_pp; - widget_enabled_set(view_dispatcher->widget, true); - widget_update(view_dispatcher->widget); + view_port_enabled_set(view_dispatcher->view_port, true); + view_port_update(view_dispatcher->view_port); } } @@ -68,11 +68,11 @@ void view_dispatcher_attach_to_gui( furi_assert(gui); if(type == ViewDispatcherTypeNone) { - gui_add_widget(gui, view_dispatcher->widget, GuiLayerNone); + gui_add_view_port(gui, view_dispatcher->view_port, GuiLayerNone); } else if(type == ViewDispatcherTypeFullscreen) { - gui_add_widget(gui, view_dispatcher->widget, GuiLayerFullscreen); + gui_add_view_port(gui, view_dispatcher->view_port, GuiLayerFullscreen); } else if(type == ViewDispatcherTypeWindow) { - gui_add_widget(gui, view_dispatcher->widget, GuiLayerMain); + gui_add_view_port(gui, view_dispatcher->view_port, GuiLayerMain); } else { furi_check(NULL); } @@ -108,6 +108,6 @@ void view_dispatcher_update(ViewDispatcher* view_dispatcher, View* view) { furi_assert(view); if(view_dispatcher->current_view == view) { - widget_update(view_dispatcher->widget); + view_port_update(view_dispatcher->view_port); } } diff --git a/applications/gui/view_dispatcher.h b/applications/gui/view_dispatcher.h index 27c4abb93..5530922fe 100644 --- a/applications/gui/view_dispatcher.h +++ b/applications/gui/view_dispatcher.h @@ -7,11 +7,11 @@ extern "C" { #endif -/* ViewDispatcher widget placement */ +/* ViewDispatcher view_port placement */ typedef enum { ViewDispatcherTypeNone, /* Special layer for internal use only */ - ViewDispatcherTypeWindow, /* Main widget layer, status bar is shown */ - ViewDispatcherTypeFullscreen /* Fullscreen widget layer */ + ViewDispatcherTypeWindow, /* Main view_port layer, status bar is shown */ + ViewDispatcherTypeFullscreen /* Fullscreen view_port layer */ } ViewDispatcherType; typedef struct ViewDispatcher ViewDispatcher; diff --git a/applications/gui/view_dispatcher_i.h b/applications/gui/view_dispatcher_i.h index 58f1fd5f3..bc87048b1 100644 --- a/applications/gui/view_dispatcher_i.h +++ b/applications/gui/view_dispatcher_i.h @@ -9,15 +9,15 @@ DICT_DEF2(ViewDict, uint32_t, M_DEFAULT_OPLIST, View*, M_PTR_OPLIST) struct ViewDispatcher { Gui* gui; - Widget* widget; + ViewPort* view_port; ViewDict_t views; View* current_view; }; -/* Widget Draw Callback */ +/* ViewPort Draw Callback */ void view_dispatcher_draw_callback(Canvas* canvas, void* context); -/* Widget Input Callback */ +/* ViewPort Input Callback */ void view_dispatcher_input_callback(InputEvent* event, void* context); /* View to ViewDispatcher update event */ diff --git a/applications/gui/view_port.c b/applications/gui/view_port.c new file mode 100644 index 000000000..961ed0444 --- /dev/null +++ b/applications/gui/view_port.c @@ -0,0 +1,98 @@ +#include "view_port_i.h" + +#include + +#include "gui.h" +#include "gui_i.h" + +// TODO add mutex to view_port ops + +ViewPort* view_port_alloc(ViewPortDrawCallback callback, void* callback_context) { + ViewPort* view_port = furi_alloc(sizeof(ViewPort)); + view_port->is_enabled = true; + return view_port; +} + +void view_port_free(ViewPort* view_port) { + furi_assert(view_port); + furi_check(view_port->gui == NULL); + free(view_port); +} + +void view_port_set_width(ViewPort* view_port, uint8_t width) { + assert(view_port); + view_port->width = width; +} + +uint8_t view_port_get_width(ViewPort* view_port) { + assert(view_port); + return view_port->width; +} + +void view_port_set_height(ViewPort* view_port, uint8_t height) { + assert(view_port); + view_port->height = height; +} + +uint8_t view_port_get_height(ViewPort* view_port) { + assert(view_port); + return view_port->height; +} + +void view_port_enabled_set(ViewPort* view_port, bool enabled) { + furi_assert(view_port); + if(view_port->is_enabled != enabled) { + view_port->is_enabled = enabled; + view_port_update(view_port); + } +} + +bool view_port_is_enabled(ViewPort* view_port) { + furi_assert(view_port); + return view_port->is_enabled; +} + +void view_port_draw_callback_set(ViewPort* view_port, ViewPortDrawCallback callback, void* context) { + furi_assert(view_port); + view_port->draw_callback = callback; + view_port->draw_callback_context = context; +} + +void view_port_input_callback_set( + ViewPort* view_port, + ViewPortInputCallback callback, + void* context) { + furi_assert(view_port); + view_port->input_callback = callback; + view_port->input_callback_context = context; +} + +void view_port_update(ViewPort* view_port) { + furi_assert(view_port); + if(view_port->gui) gui_update(view_port->gui); +} + +void view_port_gui_set(ViewPort* view_port, Gui* gui) { + furi_assert(view_port); + view_port->gui = gui; +} + +void view_port_draw(ViewPort* view_port, Canvas* canvas) { + furi_assert(view_port); + furi_assert(canvas); + furi_check(view_port->gui); + + if(view_port->draw_callback) { + view_port->draw_callback(canvas, view_port->draw_callback_context); + } +} + +void view_port_input(ViewPort* view_port, InputEvent* event) { + furi_assert(view_port); + furi_assert(event); + furi_check(view_port->gui); + + if(view_port->input_callback) { + view_port->input_callback(event, view_port->input_callback_context); + } +} diff --git a/applications/gui/view_port.h b/applications/gui/view_port.h new file mode 100644 index 000000000..37e855cec --- /dev/null +++ b/applications/gui/view_port.h @@ -0,0 +1,78 @@ +#pragma once + +#include +#include "canvas.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ViewPort ViewPort; + +/* + * ViewPort Draw callback + * @warning called from GUI thread + */ +typedef void (*ViewPortDrawCallback)(Canvas* canvas, void* context); + +/* + * ViewPort Input callback + * @warning called from GUI thread + */ +typedef void (*ViewPortInputCallback)(InputEvent* event, void* context); + +/* + * ViewPort allocator + * always returns view_port or stops system if not enough memory. + */ +ViewPort* view_port_alloc(); + +/* + * ViewPort deallocator + * Ensure that view_port was unregistered in GUI system before use. + */ +void view_port_free(ViewPort* view_port); + +/* + * Set view_port width. + * Will be used to limit canvas drawing area and autolayout feature. + * @param width - wanted width, 0 - auto. + */ +void view_port_set_width(ViewPort* view_port, uint8_t width); +uint8_t view_port_get_width(ViewPort* view_port); + +/* + * Set view_port height. + * Will be used to limit canvas drawing area and autolayout feature. + * @param height - wanted height, 0 - auto. + */ +void view_port_set_height(ViewPort* view_port, uint8_t height); +uint8_t view_port_get_height(ViewPort* view_port); + +/* + * Enable or disable view_port rendering. + * @param enabled. + */ +void view_port_enabled_set(ViewPort* view_port, bool enabled); +bool view_port_is_enabled(ViewPort* view_port); + +/* + * ViewPort event callbacks + * @param callback - appropriate callback function + * @param context - context to pass to callback + */ +void view_port_draw_callback_set(ViewPort* view_port, ViewPortDrawCallback callback, void* context); +void view_port_input_callback_set( + ViewPort* view_port, + ViewPortInputCallback callback, + void* context); + +/* + * Emit update signal to GUI system. + * Rendering will happen later after GUI system process signal. + */ +void view_port_update(ViewPort* view_port); + +#ifdef __cplusplus +} +#endif diff --git a/applications/gui/widget_i.h b/applications/gui/view_port_i.h similarity index 59% rename from applications/gui/widget_i.h rename to applications/gui/view_port_i.h index 8de17a4cf..889775c8a 100644 --- a/applications/gui/widget_i.h +++ b/applications/gui/view_port_i.h @@ -1,39 +1,39 @@ #pragma once #include "gui_i.h" -#include "widget.h" +#include "view_port.h" -struct Widget { +struct ViewPort { Gui* gui; bool is_enabled; uint8_t width; uint8_t height; - WidgetDrawCallback draw_callback; + ViewPortDrawCallback draw_callback; void* draw_callback_context; - WidgetInputCallback input_callback; + ViewPortInputCallback input_callback; void* input_callback_context; }; /* * Set GUI reference. - * To be used by GUI, called upon widget tree insert + * To be used by GUI, called upon view_port tree insert * @param gui - gui instance pointer. */ -void widget_gui_set(Widget* widget, Gui* gui); +void view_port_gui_set(ViewPort* view_port, Gui* gui); /* * Process draw call. Calls draw callback. * To be used by GUI, called on tree redraw. * @param canvas - canvas to draw at. */ -void widget_draw(Widget* widget, Canvas* canvas); +void view_port_draw(ViewPort* view_port, Canvas* canvas); /* * Process input. Calls input callbac * To be used by GUI, called on input dispatch. * @param event - pointer to input event. */ -void widget_input(Widget* widget, InputEvent* event); +void view_port_input(ViewPort* view_port, InputEvent* event); diff --git a/applications/gui/widget.c b/applications/gui/widget.c deleted file mode 100644 index d4de1a65e..000000000 --- a/applications/gui/widget.c +++ /dev/null @@ -1,95 +0,0 @@ -#include "widget_i.h" - -#include - -#include "gui.h" -#include "gui_i.h" - -// TODO add mutex to widget ops - -Widget* widget_alloc(WidgetDrawCallback callback, void* callback_context) { - Widget* widget = furi_alloc(sizeof(Widget)); - widget->is_enabled = true; - return widget; -} - -void widget_free(Widget* widget) { - furi_assert(widget); - furi_check(widget->gui == NULL); - free(widget); -} - -void widget_set_width(Widget* widget, uint8_t width) { - assert(widget); - widget->width = width; -} - -uint8_t widget_get_width(Widget* widget) { - assert(widget); - return widget->width; -} - -void widget_set_height(Widget* widget, uint8_t height) { - assert(widget); - widget->height = height; -} - -uint8_t widget_get_height(Widget* widget) { - assert(widget); - return widget->height; -} - -void widget_enabled_set(Widget* widget, bool enabled) { - furi_assert(widget); - if(widget->is_enabled != enabled) { - widget->is_enabled = enabled; - widget_update(widget); - } -} - -bool widget_is_enabled(Widget* widget) { - furi_assert(widget); - return widget->is_enabled; -} - -void widget_draw_callback_set(Widget* widget, WidgetDrawCallback callback, void* context) { - furi_assert(widget); - widget->draw_callback = callback; - widget->draw_callback_context = context; -} - -void widget_input_callback_set(Widget* widget, WidgetInputCallback callback, void* context) { - furi_assert(widget); - widget->input_callback = callback; - widget->input_callback_context = context; -} - -void widget_update(Widget* widget) { - furi_assert(widget); - if(widget->gui) gui_update(widget->gui); -} - -void widget_gui_set(Widget* widget, Gui* gui) { - furi_assert(widget); - widget->gui = gui; -} - -void widget_draw(Widget* widget, Canvas* canvas) { - furi_assert(widget); - furi_assert(canvas); - furi_check(widget->gui); - - if(widget->draw_callback) { - widget->draw_callback(canvas, widget->draw_callback_context); - } -} - -void widget_input(Widget* widget, InputEvent* event) { - furi_assert(widget); - furi_assert(event); - furi_check(widget->gui); - - if(widget->input_callback) { - widget->input_callback(event, widget->input_callback_context); - } -} diff --git a/applications/gui/widget.h b/applications/gui/widget.h deleted file mode 100644 index e31bbc885..000000000 --- a/applications/gui/widget.h +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include -#include "canvas.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct Widget Widget; - -/* - * Widget Draw callback - * @warning called from GUI thread - */ -typedef void (*WidgetDrawCallback)(Canvas* canvas, void* context); - -/* - * Widget Input callback - * @warning called from GUI thread - */ -typedef void (*WidgetInputCallback)(InputEvent* event, void* context); - -/* - * Widget allocator - * always returns widget or stops system if not enough memory. - */ -Widget* widget_alloc(); - -/* - * Widget deallocator - * Ensure that widget was unregistered in GUI system before use. - */ -void widget_free(Widget* widget); - -/* - * Set widget width. - * Will be used to limit canvas drawing area and autolayout feature. - * @param width - wanted width, 0 - auto. - */ -void widget_set_width(Widget* widget, uint8_t width); -uint8_t widget_get_width(Widget* widget); - -/* - * Set widget height. - * Will be used to limit canvas drawing area and autolayout feature. - * @param height - wanted height, 0 - auto. - */ -void widget_set_height(Widget* widget, uint8_t height); -uint8_t widget_get_height(Widget* widget); - -/* - * Enable or disable widget rendering. - * @param enabled. - */ -void widget_enabled_set(Widget* widget, bool enabled); -bool widget_is_enabled(Widget* widget); - -/* - * Widget event callbacks - * @param callback - appropriate callback function - * @param context - context to pass to callback - */ -void widget_draw_callback_set(Widget* widget, WidgetDrawCallback callback, void* context); -void widget_input_callback_set(Widget* widget, WidgetInputCallback callback, void* context); - -/* - * Emit update signal to GUI system. - * Rendering will happen later after GUI system process signal. - */ -void widget_update(Widget* widget); - -#ifdef __cplusplus -} -#endif diff --git a/applications/ibutton/ibutton.cpp b/applications/ibutton/ibutton.cpp index 98424cada..06f76a385 100644 --- a/applications/ibutton/ibutton.cpp +++ b/applications/ibutton/ibutton.cpp @@ -32,8 +32,8 @@ void AppiButton::run() { if(event.type == AppiButtonEvent::EventTypeKey) { // press events if(event.value.input.state && event.value.input.input == InputBack) { - widget_enabled_set(widget, false); - gui_remove_widget(gui, widget); + view_port_enabled_set(view_port, false); + gui_remove_view_port(gui, view_port); api_hal_timebase_insomnia_exit(); osThreadExit(); @@ -55,7 +55,7 @@ void AppiButton::run() { mode[state.mode_index]->event(&event, &state); release_state(); - widget_update(widget); + view_port_update(view_port); }; } diff --git a/applications/irda/irda.c b/applications/irda/irda.c index a60d40185..22297d574 100644 --- a/applications/irda/irda.c +++ b/applications/irda/irda.c @@ -267,14 +267,14 @@ void irda(void* p) { furiac_exit(NULL); } - Widget* widget = widget_alloc(); + ViewPort* view_port = view_port_alloc(); - widget_draw_callback_set(widget, render_callback, &state_mutex); - widget_input_callback_set(widget, input_callback, event_queue); + view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_input_callback_set(view_port, input_callback, event_queue); - // Open GUI and register widget + // Open GUI and register view_port Gui* gui = furi_record_open("gui"); - gui_add_widget(gui, widget, GuiLayerFullscreen); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); // Red LED // TODO open record @@ -302,9 +302,9 @@ void irda(void* p) { if(event.type == EventTypeKey) { // press events if(event.value.input.state && event.value.input.input == InputBack) { - // remove all widgets create by app - widget_enabled_set(widget, false); - gui_remove_widget(gui, widget); + // remove all view_ports create by app + view_port_enabled_set(view_port, false); + gui_remove_view_port(gui, view_port); // free decoder free_decoder(decoder); @@ -372,6 +372,6 @@ void irda(void* p) { } release_mutex(&state_mutex, state); - widget_update(widget); + view_port_update(view_port); } } \ No newline at end of file diff --git a/applications/lf-rfid/lf-rfid.c b/applications/lf-rfid/lf-rfid.c index 1e913e882..2ce83f250 100644 --- a/applications/lf-rfid/lf-rfid.c +++ b/applications/lf-rfid/lf-rfid.c @@ -198,14 +198,14 @@ void lf_rfid_workaround(void* p) { furiac_exit(NULL); } - Widget* widget = widget_alloc(); + ViewPort* view_port = view_port_alloc(); - widget_draw_callback_set(widget, render_callback, &state_mutex); - widget_input_callback_set(widget, input_callback, event_queue); + view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_input_callback_set(view_port, input_callback, event_queue); - // Open GUI and register widget + // Open GUI and register view_port Gui* gui = furi_record_open("gui"); - gui_add_widget(gui, widget, GuiLayerFullscreen); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); AppEvent event; uint32_t prev_dwt; @@ -290,8 +290,8 @@ void lf_rfid_workaround(void* p) { gpio_init(pull_pin_record, GpioModeInput); gpio_init((GpioPin*)&ibutton_gpio, GpioModeInput); - // TODO remove all widgets create by app - widget_enabled_set(widget, false); + // TODO remove all view_ports create by app + view_port_enabled_set(view_port, false); furiac_exit(NULL); } @@ -345,7 +345,7 @@ void lf_rfid_workaround(void* p) { } // common code, for example, force update UI - widget_update(widget); + view_port_update(view_port); release_mutex(&state_mutex, state); } diff --git a/applications/menu/menu.c b/applications/menu/menu.c index 39dccdbcf..8ce2b8f0f 100644 --- a/applications/menu/menu.c +++ b/applications/menu/menu.c @@ -14,7 +14,7 @@ struct Menu { MenuEvent* event; // GUI - Widget* widget; + ViewPort* view_port; Icon* icon; // State @@ -23,7 +23,7 @@ struct Menu { MenuItem* current; }; -void menu_widget_callback(Canvas* canvas, void* context); +void menu_view_port_callback(Canvas* canvas, void* context); ValueMutex* menu_init() { Menu* menu = furi_alloc(sizeof(Menu)); @@ -37,16 +37,16 @@ ValueMutex* menu_init() { furiac_exit(NULL); } - // Allocate and configure widget - menu->widget = widget_alloc(); + // Allocate and configure view_port + menu->view_port = view_port_alloc(); - // Open GUI and register fullscreen widget + // Open GUI and register fullscreen view_port Gui* gui = furi_record_open("gui"); - gui_add_widget(gui, menu->widget, GuiLayerFullscreen); + gui_add_view_port(gui, menu->view_port, GuiLayerFullscreen); - widget_enabled_set(menu->widget, false); - widget_draw_callback_set(menu->widget, menu_widget_callback, menu_mutex); - widget_input_callback_set(menu->widget, menu_event_input_callback, menu->event); + view_port_enabled_set(menu->view_port, false); + view_port_draw_callback_set(menu->view_port, menu_view_port_callback, menu_mutex); + view_port_input_callback_set(menu->view_port, menu_event_input_callback, menu->event); return menu_mutex; } @@ -71,7 +71,7 @@ void menu_draw_primary(Menu* menu, Canvas* canvas) { void menu_draw_secondary(Menu* menu, Canvas* canvas) { } -void menu_widget_callback(Canvas* canvas, void* context) { +void menu_view_port_callback(Canvas* canvas, void* context) { furi_assert(canvas); furi_assert(context); @@ -148,7 +148,7 @@ void menu_update(Menu* menu) { } menu_event_activity_notify(menu->event); - widget_update(menu->widget); + view_port_update(menu->view_port); } void menu_up(Menu* menu) { @@ -176,7 +176,7 @@ void menu_ok(Menu* menu) { furi_assert(menu); if(!menu->current) { - widget_enabled_set(menu->widget, true); + view_port_enabled_set(menu->view_port, true); menu->current = menu->root; menu_item_set_position(menu->current, 0); menu_update(menu); @@ -214,7 +214,7 @@ void menu_back(Menu* menu) { void menu_exit(Menu* menu) { furi_assert(menu); - widget_enabled_set(menu->widget, false); + view_port_enabled_set(menu->view_port, false); menu->current = NULL; menu_update(menu); } diff --git a/applications/music-player/music-player.c b/applications/music-player/music-player.c index 5b96cb613..c12408f0e 100644 --- a/applications/music-player/music-player.c +++ b/applications/music-player/music-player.c @@ -272,14 +272,14 @@ static void render_callback(Canvas* canvas, void* ctx) { } } - // volume widget + // volume view_port x_pos = 124; y_pos = 0; const uint8_t volume_h = (64 / (state->volume_id_max - 1)) * state->volume_id; canvas_draw_frame(canvas, x_pos, y_pos, 4, 64); canvas_draw_box(canvas, x_pos, y_pos + (64 - volume_h), 4, volume_h); - // note stack widget + // note stack view_port x_pos = 73; y_pos = 0; canvas_set_color(canvas, ColorBlack); @@ -373,13 +373,13 @@ void music_player(void* p) { furiac_exit(NULL); } - Widget* widget = widget_alloc(); - widget_draw_callback_set(widget, render_callback, &state_mutex); - widget_input_callback_set(widget, input_callback, event_queue); + ViewPort* view_port = view_port_alloc(); + view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_input_callback_set(view_port, input_callback, event_queue); - // Open GUI and register widget + // Open GUI and register view_port Gui* gui = furi_record_open("gui"); - gui_add_widget(gui, widget, GuiLayerFullscreen); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); // open input record PubSub* input_events_record = furi_record_open("input_events"); @@ -441,7 +441,7 @@ void music_player(void* p) { // event timeout } - widget_update(widget); + view_port_update(view_port); release_mutex(&state_mutex, state); } } diff --git a/applications/power/power.c b/applications/power/power.c index 04c7ecd79..ab336cec9 100644 --- a/applications/power/power.c +++ b/applications/power/power.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include @@ -20,10 +20,10 @@ struct Power { View* info_view; Icon* usb_icon; - Widget* usb_widget; + ViewPort* usb_view_port; Icon* battery_icon; - Widget* battery_widget; + ViewPort* battery_view_port; Dialog* dialog; @@ -124,14 +124,14 @@ Power* power_alloc() { power->view_dispatcher, PowerViewDialog, dialog_get_view(power->dialog)); power->usb_icon = assets_icons_get(I_USBConnected_15x8); - power->usb_widget = widget_alloc(); - widget_set_width(power->usb_widget, icon_get_width(power->usb_icon)); - widget_draw_callback_set(power->usb_widget, power_draw_usb_callback, power); + power->usb_view_port = view_port_alloc(); + view_port_set_width(power->usb_view_port, icon_get_width(power->usb_icon)); + view_port_draw_callback_set(power->usb_view_port, power_draw_usb_callback, power); power->battery_icon = assets_icons_get(I_Battery_19x8); - power->battery_widget = widget_alloc(); - widget_set_width(power->battery_widget, icon_get_width(power->battery_icon)); - widget_draw_callback_set(power->battery_widget, power_draw_battery_callback, power); + power->battery_view_port = view_port_alloc(); + view_port_set_width(power->battery_view_port, icon_get_width(power->battery_icon)); + view_port_draw_callback_set(power->battery_view_port, power_draw_battery_callback, power); return power; } @@ -190,8 +190,8 @@ void power_task(void* p) { } Gui* gui = furi_record_open("gui"); - gui_add_widget(gui, power->usb_widget, GuiLayerStatusBarLeft); - gui_add_widget(gui, power->battery_widget, GuiLayerStatusBarRight); + gui_add_view_port(gui, power->usb_view_port, GuiLayerStatusBarLeft); + gui_add_view_port(gui, power->battery_view_port, GuiLayerStatusBarRight); view_dispatcher_attach_to_gui(power->view_dispatcher, gui, ViewDispatcherTypeFullscreen); with_value_mutex( @@ -217,8 +217,8 @@ void power_task(void* p) { api_hal_power_get_battery_temperature(ApiHalPowerICFuelGauge); }); - widget_update(power->battery_widget); - widget_enabled_set(power->usb_widget, api_hal_power_is_charging()); + view_port_update(power->battery_view_port); + view_port_enabled_set(power->usb_view_port, api_hal_power_is_charging()); osDelay(1000); } } diff --git a/applications/sd-filesystem/sd-filesystem.c b/applications/sd-filesystem/sd-filesystem.c index eafa20e11..4afa1165a 100644 --- a/applications/sd-filesystem/sd-filesystem.c +++ b/applications/sd-filesystem/sd-filesystem.c @@ -107,22 +107,22 @@ SdApp* sd_app_alloc() { sd_app->event_queue = osMessageQueueNew(1, sizeof(InputEvent), NULL); - // init widget - sd_app->widget = widget_alloc(); - widget_draw_callback_set(sd_app->widget, sd_app_draw_callback, sd_app); - widget_input_callback_set(sd_app->widget, sd_app_input_callback, sd_app); - widget_enabled_set(sd_app->widget, false); + // init view_port + sd_app->view_port = view_port_alloc(); + view_port_draw_callback_set(sd_app->view_port, sd_app_draw_callback, sd_app); + view_port_input_callback_set(sd_app->view_port, sd_app_input_callback, sd_app); + view_port_enabled_set(sd_app->view_port, false); // init lines sd_set_lines(sd_app, 0); - // init icon widget - sd_app->icon.widget = widget_alloc(); + // init icon view_port + sd_app->icon.view_port = view_port_alloc(); sd_app->icon.mounted = assets_icons_get(I_SDcardMounted_11x8); sd_app->icon.fail = assets_icons_get(I_SDcardFail_11x8); - widget_set_width(sd_app->icon.widget, icon_get_width(sd_app->icon.mounted)); - widget_draw_callback_set(sd_app->icon.widget, sd_icon_draw_callback, sd_app); - widget_enabled_set(sd_app->icon.widget, false); + view_port_set_width(sd_app->icon.view_port, icon_get_width(sd_app->icon.mounted)); + view_port_draw_callback_set(sd_app->icon.view_port, sd_icon_draw_callback, sd_app); + view_port_enabled_set(sd_app->icon.view_port, false); return sd_app; } @@ -153,7 +153,7 @@ bool app_sd_ask(SdApp* sd_app, Input input_true, Input input_false) { void app_sd_info_callback(void* context) { furi_assert(context); SdApp* sd_app = context; - widget_enabled_set(sd_app->widget, true); + view_port_enabled_set(sd_app->view_port, true); // dynamic strings const uint8_t str_buffer_size = 26; @@ -257,7 +257,7 @@ void app_sd_info_callback(void* context) { app_sd_ask(sd_app, InputBack, InputBack); sd_set_lines(sd_app, 0); - widget_enabled_set(sd_app->widget, false); + view_port_enabled_set(sd_app->view_port, false); for(uint8_t i = 0; i < str_count; i++) { free(str_buffer[i]); @@ -291,11 +291,11 @@ void app_sd_format_callback(void* context) { // ask to really format sd_set_lines(sd_app, 2, "Press UP to format", "or BACK to exit"); - widget_enabled_set(sd_app->widget, true); + view_port_enabled_set(sd_app->view_port, true); // wait for input if(!app_sd_ask(sd_app, InputUp, InputBack)) { - widget_enabled_set(sd_app->widget, false); + view_port_enabled_set(sd_app->view_port, false); return; } @@ -315,7 +315,7 @@ void app_sd_format_callback(void* context) { // wait for BACK app_sd_ask(sd_app, InputBack, InputBack); - widget_enabled_set(sd_app->widget, false); + view_port_enabled_set(sd_app->view_port, false); } void app_sd_unmount_card(SdApp* sd_app) { @@ -323,7 +323,7 @@ void app_sd_unmount_card(SdApp* sd_app) { // set status sd_app->info.status = SD_NO_CARD; - widget_enabled_set(sd_app->icon.widget, false); + view_port_enabled_set(sd_app->icon.view_port, false); // close files for(uint8_t index = 0; index < SD_FS_MAX_FILES; index++) { @@ -350,7 +350,7 @@ void app_sd_eject_callback(void* context) { SdApp* sd_app = context; sd_set_lines(sd_app, 1, "ejecting SD card"); - widget_enabled_set(sd_app->widget, true); + view_port_enabled_set(sd_app->view_port, true); app_sd_unmount_card(sd_app); @@ -359,7 +359,7 @@ void app_sd_eject_callback(void* context) { // wait for BACK app_sd_ask(sd_app, InputBack, InputBack); - widget_enabled_set(sd_app->widget, false); + view_port_enabled_set(sd_app->view_port, false); } static void cli_sd_status(string_t args, void* _ctx) { @@ -484,8 +484,8 @@ void sd_filesystem(void* p) { Cli* cli = furi_record_open("cli"); ValueMutex* menu_vm = furi_record_open("menu"); - gui_add_widget(gui, sd_app->widget, GuiLayerFullscreen); - gui_add_widget(gui, sd_app->icon.widget, GuiLayerStatusBarLeft); + gui_add_view_port(gui, sd_app->view_port, GuiLayerFullscreen); + gui_add_view_port(gui, sd_app->icon.view_port, GuiLayerStatusBarLeft); cli_add_command(cli, "sd_status", cli_sd_status, sd_app); cli_add_command(cli, "sd_format", cli_sd_format, sd_app); @@ -540,14 +540,14 @@ void sd_filesystem(void* p) { } } - widget_enabled_set(sd_app->icon.widget, true); + view_port_enabled_set(sd_app->icon.view_port, true); sd_was_present = false; } } else { if(!hal_gpio_read_sd_detect()) { printf("[sd_filesystem] card removed\r\n"); - widget_enabled_set(sd_app->icon.widget, false); + view_port_enabled_set(sd_app->icon.view_port, false); app_sd_unmount_card(sd_app); sd_was_present = true; } diff --git a/applications/sd-filesystem/sd-filesystem.h b/applications/sd-filesystem/sd-filesystem.h index 0ca0c3210..8fdbd3811 100644 --- a/applications/sd-filesystem/sd-filesystem.h +++ b/applications/sd-filesystem/sd-filesystem.h @@ -63,7 +63,7 @@ typedef struct { /* application data */ typedef struct { - Widget* widget; + ViewPort* view_port; Icon* mounted; Icon* fail; } SdFsIcon; @@ -80,7 +80,7 @@ typedef struct { SdFsInfo info; SdFsIcon icon; - Widget* widget; + ViewPort* view_port; const char* line[SD_STATE_LINES_COUNT]; osMessageQueueId_t event_queue; } SdApp; diff --git a/applications/template/template.c.example b/applications/template/template.c.example index ad3d3790f..d86805c9d 100644 --- a/applications/template/template.c.example +++ b/applications/template/template.c.example @@ -48,18 +48,18 @@ void template_app(void* p) { furiac_exit(NULL); } - Widget* widget = widget_alloc(); + ViewPort* view_port = view_port_alloc(); - widget_draw_callback_set(widget, render_callback, &state_mutex); - widget_input_callback_set(widget, input_callback, event_queue); + view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_input_callback_set(view_port, input_callback, event_queue); - // Open GUI and register widget + // Open GUI and register view_port Gui* gui = furi_record_open("gui"); if(gui == NULL) { printf("gui is not available\r\n"); furiac_exit(NULL); } - gui_add_widget(gui, widget, /* specify UI layer */); + gui_add_view_port(gui, view_port, /* specify UI layer */); Event event; while(1) { @@ -95,7 +95,7 @@ void template_app(void* p) { } // common code, for example, force update UI - // widget_update(widget); + // view_port_update(view_port); release_mutex(&state_mutex, state); } diff --git a/lib/app-template/app-template.h b/lib/app-template/app-template.h index 81f232e22..ff9b9f3d7 100644 --- a/lib/app-template/app-template.h +++ b/lib/app-template/app-template.h @@ -7,7 +7,7 @@ // simple app class with template variables template class AppTemplate { public: - Widget* widget; + ViewPort* view_port; osMessageQueueId_t event_queue; TState state; ValueMutex state_mutex; @@ -40,8 +40,8 @@ template AppTemplate::AppTemplate() // open gui gui = (Gui*)furi_record_open("gui"); - // allocate widget - widget = widget_alloc(); + // allocate view_port + view_port = view_port_alloc(); } template AppTemplate::~AppTemplate() { @@ -88,24 +88,24 @@ bool AppTemplate::get_event(TEvent* event, uint32_t timeout) { // signal that app is ready, and we can render something // also unblock dependent tasks template void AppTemplate::app_ready(void) { - // connect widget with input callback + // connect view_port with input callback auto input_cb_ref = cbc::obtain_connector(this, &AppTemplate::input_callback); - widget_input_callback_set(widget, input_cb_ref, this); + view_port_input_callback_set(view_port, input_cb_ref, this); - // connect widget with draw callback + // connect view_port with draw callback auto draw_cb_ref = cbc::obtain_connector(this, &AppTemplate::draw_callback); - widget_draw_callback_set(widget, draw_cb_ref, this); + view_port_draw_callback_set(view_port, draw_cb_ref, this); - // add widget - gui_add_widget(gui, widget, GuiLayerFullscreen); + // add view_port + gui_add_view_port(gui, view_port, GuiLayerFullscreen); } template void AppTemplate::exit(void) { - // TODO remove all widgets create by app - widget_enabled_set(widget, false); + // TODO remove all view_ports create by app + view_port_enabled_set(view_port, false); osThreadExit(); } template void AppTemplate::update_gui(void) { - widget_update(widget); + view_port_update(view_port); } \ No newline at end of file