From 3f640e8f1c38ed33dc36b17476957f6b332b3856 Mon Sep 17 00:00:00 2001 From: gornekich Date: Fri, 23 Jul 2021 16:09:34 +0300 Subject: [PATCH] [FL-1549] Gui Widget module (#598) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gui_widget: rework with mlib container * widget: rename gui_widget-> widget; gui_element->widget_element * gui: move widget from nfc to gui/modules * nfc: rework widget usage * nfc: return to ReadEmvAppSuccess scene after ReadEmvDataSuccess exit Co-authored-by: あく --- applications/gui/modules/widget.c | 152 ++++++++++++++++++ applications/gui/modules/widget.h | 66 ++++++++ .../widget_elements/widget_element_button.c} | 17 +- .../widget_elements/widget_element_i.h | 48 ++++++ .../widget_elements/widget_element_icon.c} | 16 +- .../widget_elements/widget_element_string.c} | 16 +- .../nfc/gui_widget/gui_element_button.h | 24 --- applications/nfc/gui_widget/gui_element_i.h | 21 --- .../nfc/gui_widget/gui_element_icon.h | 13 -- .../nfc/gui_widget/gui_element_string.h | 21 --- applications/nfc/gui_widget/gui_widget.c | 141 ---------------- applications/nfc/gui_widget/gui_widget.h | 76 --------- applications/nfc/nfc.c | 7 +- applications/nfc/nfc_i.h | 7 +- applications/nfc/scenes/nfc_scene_delete.c | 23 ++- .../nfc/scenes/nfc_scene_device_info.c | 22 ++- .../scenes/nfc_scene_read_emv_data_success.c | 21 ++- applications/nfc/views/bank_card.c | 23 ++- 18 files changed, 326 insertions(+), 388 deletions(-) create mode 100755 applications/gui/modules/widget.c create mode 100755 applications/gui/modules/widget.h rename applications/{nfc/gui_widget/gui_element_button.c => gui/modules/widget_elements/widget_element_button.c} (83%) create mode 100755 applications/gui/modules/widget_elements/widget_element_i.h rename applications/{nfc/gui_widget/gui_element_icon.c => gui/modules/widget_elements/widget_element_icon.c} (65%) rename applications/{nfc/gui_widget/gui_element_string.c => gui/modules/widget_elements/widget_element_string.c} (78%) delete mode 100644 applications/nfc/gui_widget/gui_element_button.h delete mode 100644 applications/nfc/gui_widget/gui_element_i.h delete mode 100644 applications/nfc/gui_widget/gui_element_icon.h delete mode 100755 applications/nfc/gui_widget/gui_element_string.h delete mode 100755 applications/nfc/gui_widget/gui_widget.c delete mode 100755 applications/nfc/gui_widget/gui_widget.h mode change 100755 => 100644 applications/nfc/nfc.c mode change 100755 => 100644 applications/nfc/scenes/nfc_scene_device_info.c diff --git a/applications/gui/modules/widget.c b/applications/gui/modules/widget.c new file mode 100755 index 00000000..87ec54fe --- /dev/null +++ b/applications/gui/modules/widget.c @@ -0,0 +1,152 @@ +#include +#include "widget.h" +#include + +ARRAY_DEF(ElementArray, WidgetElement*, M_PTR_OPLIST); + +struct Widget { + View* view; + void* context; +}; + +typedef struct { + ElementArray_t element; +} GuiWidgetModel; + +static void gui_widget_view_draw_callback(Canvas* canvas, void* _model) { + GuiWidgetModel* model = _model; + canvas_clear(canvas); + + // Draw all elements + ElementArray_it_t it; + ElementArray_it(it, model->element); + while(!ElementArray_end_p(it)) { + WidgetElement* element = *ElementArray_ref(it); + if(element->draw != NULL) { + element->draw(canvas, element); + } + ElementArray_next(it); + } +} + +static bool gui_widget_view_input_callback(InputEvent* event, void* context) { + Widget* widget = context; + bool consumed = false; + + // Call all Widget Elements input handlers + with_view_model( + widget->view, (GuiWidgetModel * model) { + ElementArray_it_t it; + ElementArray_it(it, model->element); + while(!ElementArray_end_p(it)) { + WidgetElement* element = *ElementArray_ref(it); + if(element->input != NULL) { + consumed |= element->input(event, element); + } + ElementArray_next(it); + } + return true; + }); + + return consumed; +} + +Widget* widget_alloc() { + Widget* widget = furi_alloc(sizeof(Widget)); + widget->view = view_alloc(); + view_set_context(widget->view, widget); + view_allocate_model(widget->view, ViewModelTypeLocking, sizeof(GuiWidgetModel)); + view_set_draw_callback(widget->view, gui_widget_view_draw_callback); + view_set_input_callback(widget->view, gui_widget_view_input_callback); + + with_view_model( + widget->view, (GuiWidgetModel * model) { + ElementArray_init(model->element); + return true; + }); + + return widget; +} + +void widget_clear(Widget* widget) { + furi_assert(widget); + + with_view_model( + widget->view, (GuiWidgetModel * model) { + ElementArray_it_t it; + ElementArray_it(it, model->element); + while(!ElementArray_end_p(it)) { + WidgetElement* element = *ElementArray_ref(it); + furi_assert(element->free); + element->free(element); + ElementArray_next(it); + } + ElementArray_clean(model->element); + return true; + }); +} + +void widget_free(Widget* widget) { + furi_assert(widget); + // Free all elements + widget_clear(widget); + // Free elements container + with_view_model( + widget->view, (GuiWidgetModel * model) { + ElementArray_clear(model->element); + return true; + }); + + view_free(widget->view); + free(widget); +} + +View* widget_get_view(Widget* widget) { + furi_assert(widget); + return widget->view; +} + +static void widget_add_element(Widget* widget, WidgetElement* element) { + furi_assert(widget); + furi_assert(element); + + with_view_model( + widget->view, (GuiWidgetModel * model) { + element->parent = widget; + ElementArray_push_back(model->element, element); + return true; + }); +} + +void widget_add_string_element( + Widget* widget, + uint8_t x, + uint8_t y, + Align horizontal, + Align vertical, + Font font, + const char* text) { + furi_assert(widget); + WidgetElement* string_element = + widget_element_string_create(x, y, horizontal, vertical, font, text); + widget_add_element(widget, string_element); +} + +void widget_add_button_element( + Widget* widget, + GuiButtonType button_type, + const char* text, + ButtonCallback callback, + void* context) { + furi_assert(widget); + WidgetElement* button_element = + widget_element_button_create(button_type, text, callback, context); + widget_add_element(widget, button_element); +} + +void widget_add_icon_element(Widget* widget, uint8_t x, uint8_t y, const Icon* icon) { + furi_assert(widget); + furi_assert(icon); + WidgetElement* icon_element = widget_element_icon_create(x, y, icon); + widget_add_element(widget, icon_element); +} diff --git a/applications/gui/modules/widget.h b/applications/gui/modules/widget.h new file mode 100755 index 00000000..e1280023 --- /dev/null +++ b/applications/gui/modules/widget.h @@ -0,0 +1,66 @@ +#pragma once +#include "widget_elements/widget_element_i.h" + +typedef struct Widget Widget; +typedef struct WidgetElement WidgetElement; + +/** Allocate Widget that holds Widget Elements + * @return Widget instance + */ +Widget* widget_alloc(); + +/** Free Widget + * @note this function free allocated Widget Elements + * @param widget Widget instance + */ +void widget_free(Widget* widget); + +/** Clear Widget + * @param widget Widget instance + */ +void widget_clear(Widget* widget); + +/** Get Widget view + * @param widget Widget instance + * @return View instance + */ +View* widget_get_view(Widget* widget); + +/** Add String Element + * @param widget Widget instance + * @param x - x coordinate + * @param y - y coordinate + * @param horizontal - Align instance + * @param vertical - Align instance + * @param font Font instance + */ +void widget_add_string_element( + Widget* widget, + uint8_t x, + uint8_t y, + Align horizontal, + Align vertical, + Font font, + const char* text); + +/** Add Button Element + * @param widget Widget instance + * @param button_type GuiButtonType instance + * @param text text on allocated button + * @param callback ButtonCallback instance + * @param context pointer to context + */ +void widget_add_button_element( + Widget* widget, + GuiButtonType button_type, + const char* text, + ButtonCallback callback, + void* context); + +/** Add Icon Element + * @param widget Widget instance + * @param x - x coordinate + * @param y - y coordinate + * @param icon Icon instance + */ +void widget_add_icon_element(Widget* widget, uint8_t x, uint8_t y, const Icon* icon); diff --git a/applications/nfc/gui_widget/gui_element_button.c b/applications/gui/modules/widget_elements/widget_element_button.c similarity index 83% rename from applications/nfc/gui_widget/gui_element_button.c rename to applications/gui/modules/widget_elements/widget_element_button.c index e671d7dd..c9eab8d1 100644 --- a/applications/nfc/gui_widget/gui_element_button.c +++ b/applications/gui/modules/widget_elements/widget_element_button.c @@ -1,6 +1,4 @@ -#include "gui_element_i.h" -#include "gui_element_button.h" -#include "gui_widget.h" +#include "widget_element_i.h" #include #include @@ -11,7 +9,7 @@ typedef struct { void* context; } GuiButtonModel; -static void gui_button_draw(Canvas* canvas, GuiElement* element) { +static void gui_button_draw(Canvas* canvas, WidgetElement* element) { furi_assert(canvas); furi_assert(element); GuiButtonModel* model = element->model; @@ -28,7 +26,7 @@ static void gui_button_draw(Canvas* canvas, GuiElement* element) { } } -static bool gui_button_input(InputEvent* event, GuiElement* element) { +static bool gui_button_input(InputEvent* event, WidgetElement* element) { GuiButtonModel* model = element->model; bool consumed = false; @@ -48,19 +46,16 @@ static bool gui_button_input(InputEvent* event, GuiElement* element) { return consumed; } -static void gui_button_free(GuiElement* gui_button) { +static void gui_button_free(WidgetElement* gui_button) { furi_assert(gui_button); GuiButtonModel* model = gui_button->model; - if(gui_button->parent != NULL) { - // TODO deattach element - } string_clear(model->text); free(gui_button->model); free(gui_button); } -GuiElement* gui_button_create( +WidgetElement* widget_element_button_create( GuiButtonType button_type, const char* text, ButtonCallback callback, @@ -73,7 +68,7 @@ GuiElement* gui_button_create( string_init_set_str(model->text, text); // Allocate and init Element - GuiElement* gui_button = furi_alloc(sizeof(GuiElement)); + WidgetElement* gui_button = furi_alloc(sizeof(WidgetElement)); gui_button->parent = NULL; gui_button->input = gui_button_input; gui_button->draw = gui_button_draw; diff --git a/applications/gui/modules/widget_elements/widget_element_i.h b/applications/gui/modules/widget_elements/widget_element_i.h new file mode 100755 index 00000000..e7243b89 --- /dev/null +++ b/applications/gui/modules/widget_elements/widget_element_i.h @@ -0,0 +1,48 @@ +#pragma once +#include +#include + +typedef enum { + GuiButtonTypeLeft, + GuiButtonTypeCenter, + GuiButtonTypeRight, +} GuiButtonType; + +typedef void (*ButtonCallback)(GuiButtonType result, void* context); + +typedef struct WidgetElement WidgetElement; +typedef struct Widget Widget; + +struct WidgetElement { + // generic draw and input callbacks + void (*draw)(Canvas* canvas, WidgetElement* element); + bool (*input)(InputEvent* event, WidgetElement* element); + + // free callback + void (*free)(WidgetElement* element); + + // generic model holder + void* model; + + // pointer to widget that hold our element + Widget* parent; +}; + +/* Create string element */ +WidgetElement* widget_element_string_create( + uint8_t x, + uint8_t y, + Align horizontal, + Align vertical, + Font font, + const char* text); + +/* Create button element */ +WidgetElement* widget_element_button_create( + GuiButtonType button_type, + const char* text, + ButtonCallback callback, + void* context); + +/* Create icon element element */ +WidgetElement* widget_element_icon_create(uint8_t x, uint8_t y, const Icon* icon); diff --git a/applications/nfc/gui_widget/gui_element_icon.c b/applications/gui/modules/widget_elements/widget_element_icon.c similarity index 65% rename from applications/nfc/gui_widget/gui_element_icon.c rename to applications/gui/modules/widget_elements/widget_element_icon.c index f9ca4b60..5ad1302a 100644 --- a/applications/nfc/gui_widget/gui_element_icon.c +++ b/applications/gui/modules/widget_elements/widget_element_icon.c @@ -1,7 +1,4 @@ -#include "gui_element_i.h" -#include "gui_element_icon.h" -#include "gui_widget.h" - +#include "widget_element_i.h" #include typedef struct { @@ -10,7 +7,7 @@ typedef struct { const Icon* icon; } GuiIconModel; -static void gui_icon_draw(Canvas* canvas, GuiElement* element) { +static void gui_icon_draw(Canvas* canvas, WidgetElement* element) { furi_assert(canvas); furi_assert(element); GuiIconModel* model = element->model; @@ -20,17 +17,14 @@ static void gui_icon_draw(Canvas* canvas, GuiElement* element) { } } -static void gui_icon_free(GuiElement* gui_icon) { +static void gui_icon_free(WidgetElement* gui_icon) { furi_assert(gui_icon); - if(gui_icon->parent != NULL) { - // TODO deattach element - } free(gui_icon->model); free(gui_icon); } -GuiElement* gui_icon_create(uint8_t x, uint8_t y, const Icon* icon) { +WidgetElement* widget_element_icon_create(uint8_t x, uint8_t y, const Icon* icon) { furi_assert(icon); // Allocate and init model @@ -40,7 +34,7 @@ GuiElement* gui_icon_create(uint8_t x, uint8_t y, const Icon* icon) { model->icon = icon; // Allocate and init Element - GuiElement* gui_icon = furi_alloc(sizeof(GuiElement)); + WidgetElement* gui_icon = furi_alloc(sizeof(WidgetElement)); gui_icon->parent = NULL; gui_icon->input = NULL; gui_icon->draw = gui_icon_draw; diff --git a/applications/nfc/gui_widget/gui_element_string.c b/applications/gui/modules/widget_elements/widget_element_string.c similarity index 78% rename from applications/nfc/gui_widget/gui_element_string.c rename to applications/gui/modules/widget_elements/widget_element_string.c index dc9e271c..e81cd439 100755 --- a/applications/nfc/gui_widget/gui_element_string.c +++ b/applications/gui/modules/widget_elements/widget_element_string.c @@ -1,7 +1,4 @@ -#include "gui_element_i.h" -#include "gui_element_string.h" -#include "gui_widget.h" - +#include "widget_element_i.h" #include typedef struct { @@ -13,7 +10,7 @@ typedef struct { string_t text; } GuiStringModel; -static void gui_string_draw(Canvas* canvas, GuiElement* element) { +static void gui_string_draw(Canvas* canvas, WidgetElement* element) { furi_assert(canvas); furi_assert(element); GuiStringModel* model = element->model; @@ -30,19 +27,16 @@ static void gui_string_draw(Canvas* canvas, GuiElement* element) { } } -static void gui_string_free(GuiElement* gui_string) { +static void gui_string_free(WidgetElement* gui_string) { furi_assert(gui_string); GuiStringModel* model = gui_string->model; - if(gui_string->parent != NULL) { - // TODO deattach element - } string_clear(model->text); free(gui_string->model); free(gui_string); } -GuiElement* gui_string_create( +WidgetElement* widget_element_string_create( uint8_t x, uint8_t y, Align horizontal, @@ -61,7 +55,7 @@ GuiElement* gui_string_create( string_init_set_str(model->text, text); // Allocate and init Element - GuiElement* gui_string = furi_alloc(sizeof(GuiElement)); + WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement)); gui_string->parent = NULL; gui_string->input = NULL; gui_string->draw = gui_string_draw; diff --git a/applications/nfc/gui_widget/gui_element_button.h b/applications/nfc/gui_widget/gui_element_button.h deleted file mode 100644 index 804c0a4e..00000000 --- a/applications/nfc/gui_widget/gui_element_button.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include - -typedef struct GuiElement GuiElement; - -typedef enum { - GuiButtonTypeLeft, - GuiButtonTypeCenter, - GuiButtonTypeRight, -} GuiButtonType; - -typedef void (*ButtonCallback)(GuiButtonType button, void* context); - -/** Allocate Button Element - * @param button_type GuiButtonType instance - * @param text text on allocated button - * @param callback ButtonCallback instance - * @param context pointer to context - */ -GuiElement* gui_button_create( - GuiButtonType button_type, - const char* text, - ButtonCallback callback, - void* context); diff --git a/applications/nfc/gui_widget/gui_element_i.h b/applications/nfc/gui_widget/gui_element_i.h deleted file mode 100644 index ee06e1c7..00000000 --- a/applications/nfc/gui_widget/gui_element_i.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include -#include - -typedef struct GuiElement GuiElement; -typedef struct GuiWidget GuiWidget; - -struct GuiElement { - // generic draw and input callbacks - void (*draw)(Canvas* canvas, GuiElement* element); - bool (*input)(InputEvent* event, GuiElement* element); - - // free callback - void (*free)(GuiElement* element); - - // generic model holder - void* model; - - // pointer to widget that hold our element - GuiWidget* parent; -}; \ No newline at end of file diff --git a/applications/nfc/gui_widget/gui_element_icon.h b/applications/nfc/gui_widget/gui_element_icon.h deleted file mode 100644 index 2c983858..00000000 --- a/applications/nfc/gui_widget/gui_element_icon.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include -#include - -typedef struct GuiElement GuiElement; - -/** Allocate GuiElement element - * @param x - x coordinate - * @param y - y coordinate - * @param icon Icon instance - * @return GuiElement instance - */ -GuiElement* gui_icon_create(uint8_t x, uint8_t y, const Icon* icon); diff --git a/applications/nfc/gui_widget/gui_element_string.h b/applications/nfc/gui_widget/gui_element_string.h deleted file mode 100755 index 5be2ae40..00000000 --- a/applications/nfc/gui_widget/gui_element_string.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include -#include - -typedef struct GuiElement GuiElement; - -/** Allocate GuiElement element - * @param x - x coordinate - * @param y - y coordinate - * @param horizontal - Align instance - * @param vertical - Align instance - * @param font Font instance - * @return GuiElement instance - */ -GuiElement* gui_string_create( - uint8_t x, - uint8_t y, - Align horizontal, - Align vertical, - Font font, - const char* text); diff --git a/applications/nfc/gui_widget/gui_widget.c b/applications/nfc/gui_widget/gui_widget.c deleted file mode 100755 index c5b21d95..00000000 --- a/applications/nfc/gui_widget/gui_widget.c +++ /dev/null @@ -1,141 +0,0 @@ -#include -#include "gui_element_i.h" -#include "gui_widget.h" - -#define MAX_GUI_ELEMENTS 8 - -struct GuiWidget { - View* view; - void* context; -}; - -// TODO rework with M-LIB container -typedef struct { - GuiElement* element[MAX_GUI_ELEMENTS]; -} GuiWidgetModel; - -static void gui_widget_view_draw_callback(Canvas* canvas, void* _model) { - GuiWidgetModel* model = _model; - canvas_clear(canvas); - - for(uint8_t i = 0; i < MAX_GUI_ELEMENTS; i++) { - if(model->element[i] != NULL) { - if(model->element[i]->draw != NULL) { - model->element[i]->draw(canvas, model->element[i]); - } - } - }; -} - -static bool gui_widget_view_input_callback(InputEvent* event, void* context) { - GuiWidget* gui_widget = context; - bool consumed = false; - - with_view_model( - gui_widget->view, (GuiWidgetModel * model) { - for(uint8_t i = 0; i < MAX_GUI_ELEMENTS; i++) { - if(model->element[i] != NULL) { - if(model->element[i]->input != NULL) { - consumed = model->element[i]->input(event, model->element[i]); - } - } - }; - return true; - }); - - return consumed; -} - -GuiWidget* gui_widget_alloc() { - GuiWidget* gui_widget = furi_alloc(sizeof(GuiWidget)); - gui_widget->view = view_alloc(); - view_set_context(gui_widget->view, gui_widget); - view_allocate_model(gui_widget->view, ViewModelTypeLocking, sizeof(GuiWidgetModel)); - view_set_draw_callback(gui_widget->view, gui_widget_view_draw_callback); - view_set_input_callback(gui_widget->view, gui_widget_view_input_callback); - - with_view_model( - gui_widget->view, (GuiWidgetModel * model) { - for(uint8_t i = 0; i < MAX_GUI_ELEMENTS; i++) { - model->element[i] = NULL; - }; - return true; - }); - - return gui_widget; -} - -void gui_widget_free(GuiWidget* gui_widget) { - furi_assert(gui_widget); - gui_widget_clear(gui_widget); - view_free(gui_widget->view); - free(gui_widget); -} - -void gui_widget_clear(GuiWidget* gui_widget) { - furi_assert(gui_widget); - - with_view_model( - gui_widget->view, (GuiWidgetModel * model) { - for(uint8_t i = 0; i < MAX_GUI_ELEMENTS; i++) { - if(model->element[i]) { - furi_assert(model->element[i]->free); - model->element[i]->free(model->element[i]); - model->element[i] = NULL; - } - }; - return true; - }); -} - -View* gui_widget_get_view(GuiWidget* gui_widget) { - furi_assert(gui_widget); - return gui_widget->view; -} - -void gui_widget_add_element(GuiWidget* gui_widget, GuiElement* element) { - furi_assert(gui_widget); - with_view_model( - gui_widget->view, (GuiWidgetModel * model) { - // add element to first null position - for(uint8_t i = 0; i < MAX_GUI_ELEMENTS; i++) { - if(model->element[i] == NULL) { - model->element[i] = element; - element->parent = gui_widget; - break; - } - }; - return true; - }); -} - -void gui_widget_add_string_element( - GuiWidget* gui_widget, - uint8_t x, - uint8_t y, - Align horizontal, - Align vertical, - Font font, - const char* text) { - furi_assert(gui_widget); - GuiElement* string_element = gui_string_create(x, y, horizontal, vertical, font, text); - gui_widget_add_element(gui_widget, string_element); -} - -void gui_widget_add_button_element( - GuiWidget* gui_widget, - GuiButtonType button_type, - const char* text, - ButtonCallback callback, - void* context) { - furi_assert(gui_widget); - GuiElement* button_element = gui_button_create(button_type, text, callback, context); - gui_widget_add_element(gui_widget, button_element); -} - -void gui_widget_add_icon_element(GuiWidget* gui_widget, uint8_t x, uint8_t y, const Icon* icon) { - furi_assert(gui_widget); - furi_assert(icon); - GuiElement* icon_element = gui_icon_create(x, y, icon); - gui_widget_add_element(gui_widget, icon_element); -} diff --git a/applications/nfc/gui_widget/gui_widget.h b/applications/nfc/gui_widget/gui_widget.h deleted file mode 100755 index 6b34b1f9..00000000 --- a/applications/nfc/gui_widget/gui_widget.h +++ /dev/null @@ -1,76 +0,0 @@ -#pragma once -#include -#include "gui_element_string.h" -#include "gui_element_button.h" -#include "gui_element_icon.h" - -typedef struct GuiWidget GuiWidget; -typedef struct GuiElement GuiElement; - -/** Allocate Gui Widget that holds Gui Elements - * @return GuiWidget instance - */ -GuiWidget* gui_widget_alloc(); - -/** Free Gui Widget - * @note this function free Gui Elements - * @param gui_widget GuiWidget instance - */ -void gui_widget_free(GuiWidget* gui_widget); - -/** Clear Gui Widget - * @param gui_widget GuiWidget instance - */ -void gui_widget_clear(GuiWidget* gui_widget); - -/** Get Gui Widget view - * @param gui_widget GuiWidget instance - * @return View instance - */ -View* gui_widget_get_view(GuiWidget* gui_widget); - -/** Add generic Gui Elements to Gui Widget - * @param gui_widget GuiWidget instance - * @param element GuiElement element - */ -void gui_widget_add_element(GuiWidget* gui_widget, GuiElement* element); - -/** Add String Element - * @param gui_widget GuiWidget instance - * @param x - x coordinate - * @param y - y coordinate - * @param horizontal - Align instance - * @param vertical - Align instance - * @param font Font instance - * @return GuiElement instance - */ -void gui_widget_add_string_element( - GuiWidget* gui_widget, - uint8_t x, - uint8_t y, - Align horizontal, - Align vertical, - Font font, - const char* text); - -/** Add Button Element - * @param gui_widget GuiWidget instance - * @param button_type GuiButtonType instance - * @param text text on allocated button - * @param callback ButtonCallback instance - * @param context pointer to context - */ -void gui_widget_add_button_element( - GuiWidget* gui_widget, - GuiButtonType button_type, - const char* text, - ButtonCallback callback, - void* context); - -/** Add Icon Element - * @param gui_widget GuiWidget instance - * @param x - x coordinate - * @param y - y coordinate - * @param icon Icon instance - */ -void gui_widget_add_icon_element(GuiWidget* gui_widget, uint8_t x, uint8_t y, const Icon* icon); diff --git a/applications/nfc/nfc.c b/applications/nfc/nfc.c old mode 100755 new mode 100644 index 68fcf358..8815211c --- a/applications/nfc/nfc.c +++ b/applications/nfc/nfc.c @@ -69,9 +69,8 @@ Nfc* nfc_alloc() { string_init(nfc->text_box_store); // Custom Widget - nfc->widget = gui_widget_alloc(); - view_dispatcher_add_view( - nfc->view_dispatcher, NfcViewWidget, gui_widget_get_view(nfc->widget)); + nfc->widget = widget_alloc(); + view_dispatcher_add_view(nfc->view_dispatcher, NfcViewWidget, widget_get_view(nfc->widget)); // Bank Card nfc->bank_card = bank_card_alloc(); @@ -111,7 +110,7 @@ void nfc_free(Nfc* nfc) { // Custom Widget view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewWidget); - gui_widget_free(nfc->widget); + widget_free(nfc->widget); // Bank Card view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewBankCard); diff --git a/applications/nfc/nfc_i.h b/applications/nfc/nfc_i.h index 5c89e782..54b68231 100755 --- a/applications/nfc/nfc_i.h +++ b/applications/nfc/nfc_i.h @@ -20,13 +20,10 @@ #include #include #include +#include #include "views/bank_card.h" -#include "gui_widget/gui_widget.h" -#include "gui_widget/gui_element_string.h" -#include "gui_widget/gui_element_button.h" - #include #define NFC_TEXT_STORE_SIZE 128 @@ -49,7 +46,7 @@ struct Nfc { TextInput* text_input; ByteInput* byte_input; TextBox* text_box; - GuiWidget* widget; + Widget* widget; BankCard* bank_card; }; diff --git a/applications/nfc/scenes/nfc_scene_delete.c b/applications/nfc/scenes/nfc_scene_delete.c index 0517a8fa..84646e05 100644 --- a/applications/nfc/scenes/nfc_scene_delete.c +++ b/applications/nfc/scenes/nfc_scene_delete.c @@ -12,11 +12,10 @@ void nfc_scene_delete_on_enter(void* context) { // Setup Custom Widget view char delete_str[64]; snprintf(delete_str, sizeof(delete_str), "Delete %s", nfc->dev.dev_name); - gui_widget_add_string_element( - nfc->widget, 64, 6, AlignCenter, AlignTop, FontPrimary, delete_str); - gui_widget_add_button_element( + widget_add_string_element(nfc->widget, 64, 6, AlignCenter, AlignTop, FontPrimary, delete_str); + widget_add_button_element( nfc->widget, GuiButtonTypeLeft, "Back", nfc_scene_delete_widget_callback, nfc); - gui_widget_add_button_element( + widget_add_button_element( nfc->widget, GuiButtonTypeRight, "Delete", nfc_scene_delete_widget_callback, nfc); char uid_str[32]; NfcDeviceCommomData* data = &nfc->dev.dev_data.nfc_data; @@ -42,11 +41,10 @@ void nfc_scene_delete_on_enter(void* context) { data->uid[5], data->uid[6]); } - gui_widget_add_string_element( - nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str); + widget_add_string_element(nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str); if(data->protocol > NfcDeviceProtocolUnknown) { - gui_widget_add_string_element( + widget_add_string_element( nfc->widget, 10, 32, @@ -56,16 +54,13 @@ void nfc_scene_delete_on_enter(void* context) { nfc_get_protocol(data->protocol)); } // TODO change dinamically - gui_widget_add_string_element( - nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A"); + widget_add_string_element(nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A"); char sak_str[16]; snprintf(sak_str, sizeof(sak_str), "SAK: %02X", data->sak); - gui_widget_add_string_element( - nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, sak_str); + widget_add_string_element(nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, sak_str); char atqa_str[16]; snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", data->atqa[0], data->atqa[1]); - gui_widget_add_string_element( - nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, atqa_str); + widget_add_string_element(nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, atqa_str); view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget); } @@ -91,5 +86,5 @@ const bool nfc_scene_delete_on_event(void* context, SceneManagerEvent event) { const void nfc_scene_delete_on_exit(void* context) { Nfc* nfc = (Nfc*)context; - gui_widget_clear(nfc->widget); + widget_clear(nfc->widget); } diff --git a/applications/nfc/scenes/nfc_scene_device_info.c b/applications/nfc/scenes/nfc_scene_device_info.c old mode 100755 new mode 100644 index afb65ea1..6bd097d3 --- a/applications/nfc/scenes/nfc_scene_device_info.c +++ b/applications/nfc/scenes/nfc_scene_device_info.c @@ -30,11 +30,11 @@ void nfc_scene_device_info_on_enter(void* context) { Nfc* nfc = (Nfc*)context; // Setup Custom Widget view - gui_widget_add_string_element( + widget_add_string_element( nfc->widget, 64, 6, AlignCenter, AlignTop, FontSecondary, nfc->dev.dev_name); - gui_widget_add_button_element( + widget_add_button_element( nfc->widget, GuiButtonTypeLeft, "Back", nfc_scene_device_info_widget_callback, nfc); - gui_widget_add_button_element( + widget_add_button_element( nfc->widget, GuiButtonTypeRight, "Data", nfc_scene_device_info_widget_callback, nfc); char uid_str[32]; NfcDeviceCommomData* data = &nfc->dev.dev_data.nfc_data; @@ -60,11 +60,10 @@ void nfc_scene_device_info_on_enter(void* context) { data->uid[5], data->uid[6]); } - gui_widget_add_string_element( - nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str); + widget_add_string_element(nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str); if(data->protocol > NfcDeviceProtocolUnknown) { - gui_widget_add_string_element( + widget_add_string_element( nfc->widget, 10, 32, @@ -74,16 +73,13 @@ void nfc_scene_device_info_on_enter(void* context) { nfc_get_protocol(data->protocol)); } // TODO change dinamically - gui_widget_add_string_element( - nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A"); + widget_add_string_element(nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A"); char sak_str[16]; snprintf(sak_str, sizeof(sak_str), "SAK: %02X", data->sak); - gui_widget_add_string_element( - nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, sak_str); + widget_add_string_element(nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, sak_str); char atqa_str[16]; snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", data->atqa[0], data->atqa[1]); - gui_widget_add_string_element( - nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, atqa_str); + widget_add_string_element(nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, atqa_str); // Setup Data View if(nfc->dev.format == NfcDeviceSaveFormatUid) { @@ -161,7 +157,7 @@ const void nfc_scene_device_info_on_exit(void* context) { Nfc* nfc = (Nfc*)context; // Clear Custom Widget - gui_widget_clear(nfc->widget); + widget_clear(nfc->widget); if(nfc->dev.format == NfcDeviceSaveFormatUid) { // Clear Dialog diff --git a/applications/nfc/scenes/nfc_scene_read_emv_data_success.c b/applications/nfc/scenes/nfc_scene_read_emv_data_success.c index f8f37f7a..fbfca822 100755 --- a/applications/nfc/scenes/nfc_scene_read_emv_data_success.c +++ b/applications/nfc/scenes/nfc_scene_read_emv_data_success.c @@ -15,19 +15,19 @@ void nfc_scene_read_emv_data_success_on_enter(void* context) { nfc_device_set_name(&nfc->dev, ""); // Setup Custom Widget view - gui_widget_add_button_element( + widget_add_button_element( nfc->widget, GuiButtonTypeLeft, "Back", nfc_scene_read_emv_data_success_widget_callback, nfc); - gui_widget_add_button_element( + widget_add_button_element( nfc->widget, GuiButtonTypeRight, "Save", nfc_scene_read_emv_data_success_widget_callback, nfc); - gui_widget_add_string_element( + widget_add_string_element( nfc->widget, 64, 3, AlignCenter, AlignTop, FontSecondary, nfc->dev.dev_data.emv_data.name); char pan_str[32]; snprintf( @@ -42,12 +42,10 @@ void nfc_scene_read_emv_data_success_on_enter(void* context) { emv_data->number[5], emv_data->number[6], emv_data->number[7]); - gui_widget_add_string_element( - nfc->widget, 64, 13, AlignCenter, AlignTop, FontSecondary, pan_str); + widget_add_string_element(nfc->widget, 64, 13, AlignCenter, AlignTop, FontSecondary, pan_str); char atqa_str[16]; snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", nfc_data->atqa[0], nfc_data->atqa[1]); - gui_widget_add_string_element( - nfc->widget, 121, 32, AlignRight, AlignTop, FontSecondary, atqa_str); + widget_add_string_element(nfc->widget, 121, 32, AlignRight, AlignTop, FontSecondary, atqa_str); char uid_str[32]; snprintf( uid_str, @@ -57,11 +55,10 @@ void nfc_scene_read_emv_data_success_on_enter(void* context) { nfc_data->uid[1], nfc_data->uid[2], nfc_data->uid[3]); - gui_widget_add_string_element(nfc->widget, 7, 42, AlignLeft, AlignTop, FontSecondary, uid_str); + widget_add_string_element(nfc->widget, 7, 42, AlignLeft, AlignTop, FontSecondary, uid_str); char sak_str[16]; snprintf(sak_str, sizeof(sak_str), "SAK: %02X", nfc_data->sak); - gui_widget_add_string_element( - nfc->widget, 121, 42, AlignRight, AlignTop, FontSecondary, sak_str); + widget_add_string_element(nfc->widget, 121, 42, AlignRight, AlignTop, FontSecondary, sak_str); view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget); } @@ -78,6 +75,8 @@ const bool nfc_scene_read_emv_data_success_on_event(void* context, SceneManagerE scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName); return true; } + } else if(event.type == SceneManagerEventTypeNavigation) { + return scene_manager_search_previous_scene(nfc->scene_manager, NfcSceneReadEmvAppSuccess); } return false; } @@ -85,5 +84,5 @@ const bool nfc_scene_read_emv_data_success_on_event(void* context, SceneManagerE const void nfc_scene_read_emv_data_success_on_exit(void* context) { Nfc* nfc = (Nfc*)context; - gui_widget_clear(nfc->widget); + widget_clear(nfc->widget); } diff --git a/applications/nfc/views/bank_card.c b/applications/nfc/views/bank_card.c index 3d78da26..a483fcff 100755 --- a/applications/nfc/views/bank_card.c +++ b/applications/nfc/views/bank_card.c @@ -1,37 +1,37 @@ #include "bank_card.h" -#include "../gui_widget/gui_widget.h" +#include #include struct BankCard { - GuiWidget* widget; + Widget* widget; }; BankCard* bank_card_alloc() { BankCard* bank_card = furi_alloc(sizeof(BankCard)); - bank_card->widget = gui_widget_alloc(); + bank_card->widget = widget_alloc(); return bank_card; } void bank_card_free(BankCard* bank_card) { furi_assert(bank_card); - gui_widget_free(bank_card->widget); + widget_free(bank_card->widget); free(bank_card); } View* bank_card_get_view(BankCard* bank_card) { furi_assert(bank_card); - return gui_widget_get_view(bank_card->widget); + return widget_get_view(bank_card->widget); } void bank_card_clear(BankCard* bank_card) { furi_assert(bank_card); - gui_widget_clear(bank_card->widget); + widget_clear(bank_card->widget); } void bank_card_set_name(BankCard* bank_card, char* name) { furi_assert(bank_card); furi_assert(name); - gui_widget_add_string_element( + widget_add_string_element( bank_card->widget, 64, 6, AlignCenter, AlignTop, FontSecondary, name); } @@ -43,9 +43,9 @@ void bank_card_set_number(BankCard* bank_card, uint8_t* number) { for(uint8_t i = 0; i < 8; i += 2) { string_cat_printf(num_str, "%02X%02X ", number[i], number[i + 1]); } - gui_widget_add_string_element( + widget_add_string_element( bank_card->widget, 25, 22, AlignLeft, AlignTop, FontSecondary, string_get_cstr(num_str)); - gui_widget_add_icon_element(bank_card->widget, 6, 20, &I_EMV_Chip_14x11); + widget_add_icon_element(bank_card->widget, 6, 20, &I_EMV_Chip_14x11); string_clear(num_str); } @@ -53,13 +53,12 @@ void bank_card_set_exp_date(BankCard* bank_card, uint8_t mon, uint16_t year) { furi_assert(bank_card); char exp_date_str[16]; snprintf(exp_date_str, sizeof(exp_date_str), "Exp: %02d/%02d", mon, year % 100); - gui_widget_add_string_element( + widget_add_string_element( bank_card->widget, 122, 54, AlignRight, AlignBottom, FontSecondary, exp_date_str); } void bank_card_set_cardholder_name(BankCard* bank_card, char* name) { furi_assert(bank_card); furi_assert(name); - gui_widget_add_string_element( - bank_card->widget, 6, 37, AlignLeft, AlignTop, FontSecondary, name); + widget_add_string_element(bank_card->widget, 6, 37, AlignLeft, AlignTop, FontSecondary, name); }