[FL-1549] Gui Widget module (#598)
* 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: あく <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									ad421a81bc
								
							
						
					
					
						commit
						3f640e8f1c
					
				
							
								
								
									
										152
									
								
								applications/gui/modules/widget.c
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										152
									
								
								applications/gui/modules/widget.c
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,152 @@
 | 
				
			|||||||
 | 
					#include <furi.h>
 | 
				
			||||||
 | 
					#include "widget.h"
 | 
				
			||||||
 | 
					#include <m-array.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										66
									
								
								applications/gui/modules/widget.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										66
									
								
								applications/gui/modules/widget.h
									
									
									
									
									
										Executable file
									
								
							@ -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);
 | 
				
			||||||
@ -1,6 +1,4 @@
 | 
				
			|||||||
#include "gui_element_i.h"
 | 
					#include "widget_element_i.h"
 | 
				
			||||||
#include "gui_element_button.h"
 | 
					 | 
				
			||||||
#include "gui_widget.h"
 | 
					 | 
				
			||||||
#include <gui/elements.h>
 | 
					#include <gui/elements.h>
 | 
				
			||||||
#include <m-string.h>
 | 
					#include <m-string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -11,7 +9,7 @@ typedef struct {
 | 
				
			|||||||
    void* context;
 | 
					    void* context;
 | 
				
			||||||
} GuiButtonModel;
 | 
					} GuiButtonModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gui_button_draw(Canvas* canvas, GuiElement* element) {
 | 
					static void gui_button_draw(Canvas* canvas, WidgetElement* element) {
 | 
				
			||||||
    furi_assert(canvas);
 | 
					    furi_assert(canvas);
 | 
				
			||||||
    furi_assert(element);
 | 
					    furi_assert(element);
 | 
				
			||||||
    GuiButtonModel* model = element->model;
 | 
					    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;
 | 
					    GuiButtonModel* model = element->model;
 | 
				
			||||||
    bool consumed = false;
 | 
					    bool consumed = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -48,19 +46,16 @@ static bool gui_button_input(InputEvent* event, GuiElement* element) {
 | 
				
			|||||||
    return consumed;
 | 
					    return consumed;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gui_button_free(GuiElement* gui_button) {
 | 
					static void gui_button_free(WidgetElement* gui_button) {
 | 
				
			||||||
    furi_assert(gui_button);
 | 
					    furi_assert(gui_button);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    GuiButtonModel* model = gui_button->model;
 | 
					    GuiButtonModel* model = gui_button->model;
 | 
				
			||||||
    if(gui_button->parent != NULL) {
 | 
					 | 
				
			||||||
        // TODO deattach element
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    string_clear(model->text);
 | 
					    string_clear(model->text);
 | 
				
			||||||
    free(gui_button->model);
 | 
					    free(gui_button->model);
 | 
				
			||||||
    free(gui_button);
 | 
					    free(gui_button);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GuiElement* gui_button_create(
 | 
					WidgetElement* widget_element_button_create(
 | 
				
			||||||
    GuiButtonType button_type,
 | 
					    GuiButtonType button_type,
 | 
				
			||||||
    const char* text,
 | 
					    const char* text,
 | 
				
			||||||
    ButtonCallback callback,
 | 
					    ButtonCallback callback,
 | 
				
			||||||
@ -73,7 +68,7 @@ GuiElement* gui_button_create(
 | 
				
			|||||||
    string_init_set_str(model->text, text);
 | 
					    string_init_set_str(model->text, text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Allocate and init Element
 | 
					    // Allocate and init Element
 | 
				
			||||||
    GuiElement* gui_button = furi_alloc(sizeof(GuiElement));
 | 
					    WidgetElement* gui_button = furi_alloc(sizeof(WidgetElement));
 | 
				
			||||||
    gui_button->parent = NULL;
 | 
					    gui_button->parent = NULL;
 | 
				
			||||||
    gui_button->input = gui_button_input;
 | 
					    gui_button->input = gui_button_input;
 | 
				
			||||||
    gui_button->draw = gui_button_draw;
 | 
					    gui_button->draw = gui_button_draw;
 | 
				
			||||||
							
								
								
									
										48
									
								
								applications/gui/modules/widget_elements/widget_element_i.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										48
									
								
								applications/gui/modules/widget_elements/widget_element_i.h
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					#include <furi.h>
 | 
				
			||||||
 | 
					#include <gui/view.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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);
 | 
				
			||||||
@ -1,7 +1,4 @@
 | 
				
			|||||||
#include "gui_element_i.h"
 | 
					#include "widget_element_i.h"
 | 
				
			||||||
#include "gui_element_icon.h"
 | 
					 | 
				
			||||||
#include "gui_widget.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <m-string.h>
 | 
					#include <m-string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
@ -10,7 +7,7 @@ typedef struct {
 | 
				
			|||||||
    const Icon* icon;
 | 
					    const Icon* icon;
 | 
				
			||||||
} GuiIconModel;
 | 
					} GuiIconModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gui_icon_draw(Canvas* canvas, GuiElement* element) {
 | 
					static void gui_icon_draw(Canvas* canvas, WidgetElement* element) {
 | 
				
			||||||
    furi_assert(canvas);
 | 
					    furi_assert(canvas);
 | 
				
			||||||
    furi_assert(element);
 | 
					    furi_assert(element);
 | 
				
			||||||
    GuiIconModel* model = element->model;
 | 
					    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);
 | 
					    furi_assert(gui_icon);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(gui_icon->parent != NULL) {
 | 
					 | 
				
			||||||
        // TODO deattach element
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    free(gui_icon->model);
 | 
					    free(gui_icon->model);
 | 
				
			||||||
    free(gui_icon);
 | 
					    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);
 | 
					    furi_assert(icon);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Allocate and init model
 | 
					    // Allocate and init model
 | 
				
			||||||
@ -40,7 +34,7 @@ GuiElement* gui_icon_create(uint8_t x, uint8_t y, const Icon* icon) {
 | 
				
			|||||||
    model->icon = icon;
 | 
					    model->icon = icon;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Allocate and init Element
 | 
					    // Allocate and init Element
 | 
				
			||||||
    GuiElement* gui_icon = furi_alloc(sizeof(GuiElement));
 | 
					    WidgetElement* gui_icon = furi_alloc(sizeof(WidgetElement));
 | 
				
			||||||
    gui_icon->parent = NULL;
 | 
					    gui_icon->parent = NULL;
 | 
				
			||||||
    gui_icon->input = NULL;
 | 
					    gui_icon->input = NULL;
 | 
				
			||||||
    gui_icon->draw = gui_icon_draw;
 | 
					    gui_icon->draw = gui_icon_draw;
 | 
				
			||||||
@ -1,7 +1,4 @@
 | 
				
			|||||||
#include "gui_element_i.h"
 | 
					#include "widget_element_i.h"
 | 
				
			||||||
#include "gui_element_string.h"
 | 
					 | 
				
			||||||
#include "gui_widget.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <m-string.h>
 | 
					#include <m-string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
@ -13,7 +10,7 @@ typedef struct {
 | 
				
			|||||||
    string_t text;
 | 
					    string_t text;
 | 
				
			||||||
} GuiStringModel;
 | 
					} GuiStringModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gui_string_draw(Canvas* canvas, GuiElement* element) {
 | 
					static void gui_string_draw(Canvas* canvas, WidgetElement* element) {
 | 
				
			||||||
    furi_assert(canvas);
 | 
					    furi_assert(canvas);
 | 
				
			||||||
    furi_assert(element);
 | 
					    furi_assert(element);
 | 
				
			||||||
    GuiStringModel* model = element->model;
 | 
					    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);
 | 
					    furi_assert(gui_string);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    GuiStringModel* model = gui_string->model;
 | 
					    GuiStringModel* model = gui_string->model;
 | 
				
			||||||
    if(gui_string->parent != NULL) {
 | 
					 | 
				
			||||||
        // TODO deattach element
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    string_clear(model->text);
 | 
					    string_clear(model->text);
 | 
				
			||||||
    free(gui_string->model);
 | 
					    free(gui_string->model);
 | 
				
			||||||
    free(gui_string);
 | 
					    free(gui_string);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GuiElement* gui_string_create(
 | 
					WidgetElement* widget_element_string_create(
 | 
				
			||||||
    uint8_t x,
 | 
					    uint8_t x,
 | 
				
			||||||
    uint8_t y,
 | 
					    uint8_t y,
 | 
				
			||||||
    Align horizontal,
 | 
					    Align horizontal,
 | 
				
			||||||
@ -61,7 +55,7 @@ GuiElement* gui_string_create(
 | 
				
			|||||||
    string_init_set_str(model->text, text);
 | 
					    string_init_set_str(model->text, text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Allocate and init Element
 | 
					    // Allocate and init Element
 | 
				
			||||||
    GuiElement* gui_string = furi_alloc(sizeof(GuiElement));
 | 
					    WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
 | 
				
			||||||
    gui_string->parent = NULL;
 | 
					    gui_string->parent = NULL;
 | 
				
			||||||
    gui_string->input = NULL;
 | 
					    gui_string->input = NULL;
 | 
				
			||||||
    gui_string->draw = gui_string_draw;
 | 
					    gui_string->draw = gui_string_draw;
 | 
				
			||||||
@ -1,24 +0,0 @@
 | 
				
			|||||||
#pragma once
 | 
					 | 
				
			||||||
#include <stdint.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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);
 | 
					 | 
				
			||||||
@ -1,21 +0,0 @@
 | 
				
			|||||||
#pragma once
 | 
					 | 
				
			||||||
#include <furi.h>
 | 
					 | 
				
			||||||
#include <gui/view.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
@ -1,13 +0,0 @@
 | 
				
			|||||||
#pragma once
 | 
					 | 
				
			||||||
#include <stdint.h>
 | 
					 | 
				
			||||||
#include <gui/canvas.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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);
 | 
					 | 
				
			||||||
@ -1,21 +0,0 @@
 | 
				
			|||||||
#pragma once
 | 
					 | 
				
			||||||
#include <stdint.h>
 | 
					 | 
				
			||||||
#include <gui/canvas.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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);
 | 
					 | 
				
			||||||
@ -1,141 +0,0 @@
 | 
				
			|||||||
#include <furi.h>
 | 
					 | 
				
			||||||
#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);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,76 +0,0 @@
 | 
				
			|||||||
#pragma once
 | 
					 | 
				
			||||||
#include <gui/view.h>
 | 
					 | 
				
			||||||
#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);
 | 
					 | 
				
			||||||
							
								
								
									
										7
									
								
								applications/nfc/nfc.c
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										7
									
								
								applications/nfc/nfc.c
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							@ -69,9 +69,8 @@ Nfc* nfc_alloc() {
 | 
				
			|||||||
    string_init(nfc->text_box_store);
 | 
					    string_init(nfc->text_box_store);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Custom Widget
 | 
					    // Custom Widget
 | 
				
			||||||
    nfc->widget = gui_widget_alloc();
 | 
					    nfc->widget = widget_alloc();
 | 
				
			||||||
    view_dispatcher_add_view(
 | 
					    view_dispatcher_add_view(nfc->view_dispatcher, NfcViewWidget, widget_get_view(nfc->widget));
 | 
				
			||||||
        nfc->view_dispatcher, NfcViewWidget, gui_widget_get_view(nfc->widget));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Bank Card
 | 
					    // Bank Card
 | 
				
			||||||
    nfc->bank_card = bank_card_alloc();
 | 
					    nfc->bank_card = bank_card_alloc();
 | 
				
			||||||
@ -111,7 +110,7 @@ void nfc_free(Nfc* nfc) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Custom Widget
 | 
					    // Custom Widget
 | 
				
			||||||
    view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewWidget);
 | 
					    view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewWidget);
 | 
				
			||||||
    gui_widget_free(nfc->widget);
 | 
					    widget_free(nfc->widget);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Bank Card
 | 
					    // Bank Card
 | 
				
			||||||
    view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewBankCard);
 | 
					    view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewBankCard);
 | 
				
			||||||
 | 
				
			|||||||
@ -20,13 +20,10 @@
 | 
				
			|||||||
#include <gui/modules/text_input.h>
 | 
					#include <gui/modules/text_input.h>
 | 
				
			||||||
#include <gui/modules/byte_input.h>
 | 
					#include <gui/modules/byte_input.h>
 | 
				
			||||||
#include <gui/modules/text_box.h>
 | 
					#include <gui/modules/text_box.h>
 | 
				
			||||||
 | 
					#include <gui/modules/widget.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "views/bank_card.h"
 | 
					#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 <nfc/scenes/nfc_scene.h>
 | 
					#include <nfc/scenes/nfc_scene.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define NFC_TEXT_STORE_SIZE 128
 | 
					#define NFC_TEXT_STORE_SIZE 128
 | 
				
			||||||
@ -49,7 +46,7 @@ struct Nfc {
 | 
				
			|||||||
    TextInput* text_input;
 | 
					    TextInput* text_input;
 | 
				
			||||||
    ByteInput* byte_input;
 | 
					    ByteInput* byte_input;
 | 
				
			||||||
    TextBox* text_box;
 | 
					    TextBox* text_box;
 | 
				
			||||||
    GuiWidget* widget;
 | 
					    Widget* widget;
 | 
				
			||||||
    BankCard* bank_card;
 | 
					    BankCard* bank_card;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -12,11 +12,10 @@ void nfc_scene_delete_on_enter(void* context) {
 | 
				
			|||||||
    // Setup Custom Widget view
 | 
					    // Setup Custom Widget view
 | 
				
			||||||
    char delete_str[64];
 | 
					    char delete_str[64];
 | 
				
			||||||
    snprintf(delete_str, sizeof(delete_str), "Delete %s", nfc->dev.dev_name);
 | 
					    snprintf(delete_str, sizeof(delete_str), "Delete %s", nfc->dev.dev_name);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 64, 6, AlignCenter, AlignTop, FontPrimary, delete_str);
 | 
				
			||||||
        nfc->widget, 64, 6, AlignCenter, AlignTop, FontPrimary, delete_str);
 | 
					    widget_add_button_element(
 | 
				
			||||||
    gui_widget_add_button_element(
 | 
					 | 
				
			||||||
        nfc->widget, GuiButtonTypeLeft, "Back", nfc_scene_delete_widget_callback, nfc);
 | 
					        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);
 | 
					        nfc->widget, GuiButtonTypeRight, "Delete", nfc_scene_delete_widget_callback, nfc);
 | 
				
			||||||
    char uid_str[32];
 | 
					    char uid_str[32];
 | 
				
			||||||
    NfcDeviceCommomData* data = &nfc->dev.dev_data.nfc_data;
 | 
					    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[5],
 | 
				
			||||||
            data->uid[6]);
 | 
					            data->uid[6]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str);
 | 
				
			||||||
        nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(data->protocol > NfcDeviceProtocolUnknown) {
 | 
					    if(data->protocol > NfcDeviceProtocolUnknown) {
 | 
				
			||||||
        gui_widget_add_string_element(
 | 
					        widget_add_string_element(
 | 
				
			||||||
            nfc->widget,
 | 
					            nfc->widget,
 | 
				
			||||||
            10,
 | 
					            10,
 | 
				
			||||||
            32,
 | 
					            32,
 | 
				
			||||||
@ -56,16 +54,13 @@ void nfc_scene_delete_on_enter(void* context) {
 | 
				
			|||||||
            nfc_get_protocol(data->protocol));
 | 
					            nfc_get_protocol(data->protocol));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // TODO change dinamically
 | 
					    // TODO change dinamically
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A");
 | 
				
			||||||
        nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A");
 | 
					 | 
				
			||||||
    char sak_str[16];
 | 
					    char sak_str[16];
 | 
				
			||||||
    snprintf(sak_str, sizeof(sak_str), "SAK: %02X", data->sak);
 | 
					    snprintf(sak_str, sizeof(sak_str), "SAK: %02X", data->sak);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, sak_str);
 | 
				
			||||||
        nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, sak_str);
 | 
					 | 
				
			||||||
    char atqa_str[16];
 | 
					    char atqa_str[16];
 | 
				
			||||||
    snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", data->atqa[0], data->atqa[1]);
 | 
					    snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", data->atqa[0], data->atqa[1]);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, atqa_str);
 | 
				
			||||||
        nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, atqa_str);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
 | 
					    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) {
 | 
					const void nfc_scene_delete_on_exit(void* context) {
 | 
				
			||||||
    Nfc* nfc = (Nfc*)context;
 | 
					    Nfc* nfc = (Nfc*)context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gui_widget_clear(nfc->widget);
 | 
					    widget_clear(nfc->widget);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										22
									
								
								applications/nfc/scenes/nfc_scene_device_info.c
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										22
									
								
								applications/nfc/scenes/nfc_scene_device_info.c
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							@ -30,11 +30,11 @@ void nfc_scene_device_info_on_enter(void* context) {
 | 
				
			|||||||
    Nfc* nfc = (Nfc*)context;
 | 
					    Nfc* nfc = (Nfc*)context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Setup Custom Widget view
 | 
					    // Setup Custom Widget view
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(
 | 
				
			||||||
        nfc->widget, 64, 6, AlignCenter, AlignTop, FontSecondary, nfc->dev.dev_name);
 | 
					        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);
 | 
					        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);
 | 
					        nfc->widget, GuiButtonTypeRight, "Data", nfc_scene_device_info_widget_callback, nfc);
 | 
				
			||||||
    char uid_str[32];
 | 
					    char uid_str[32];
 | 
				
			||||||
    NfcDeviceCommomData* data = &nfc->dev.dev_data.nfc_data;
 | 
					    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[5],
 | 
				
			||||||
            data->uid[6]);
 | 
					            data->uid[6]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str);
 | 
				
			||||||
        nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(data->protocol > NfcDeviceProtocolUnknown) {
 | 
					    if(data->protocol > NfcDeviceProtocolUnknown) {
 | 
				
			||||||
        gui_widget_add_string_element(
 | 
					        widget_add_string_element(
 | 
				
			||||||
            nfc->widget,
 | 
					            nfc->widget,
 | 
				
			||||||
            10,
 | 
					            10,
 | 
				
			||||||
            32,
 | 
					            32,
 | 
				
			||||||
@ -74,16 +73,13 @@ void nfc_scene_device_info_on_enter(void* context) {
 | 
				
			|||||||
            nfc_get_protocol(data->protocol));
 | 
					            nfc_get_protocol(data->protocol));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // TODO change dinamically
 | 
					    // TODO change dinamically
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A");
 | 
				
			||||||
        nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A");
 | 
					 | 
				
			||||||
    char sak_str[16];
 | 
					    char sak_str[16];
 | 
				
			||||||
    snprintf(sak_str, sizeof(sak_str), "SAK: %02X", data->sak);
 | 
					    snprintf(sak_str, sizeof(sak_str), "SAK: %02X", data->sak);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, sak_str);
 | 
				
			||||||
        nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, sak_str);
 | 
					 | 
				
			||||||
    char atqa_str[16];
 | 
					    char atqa_str[16];
 | 
				
			||||||
    snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", data->atqa[0], data->atqa[1]);
 | 
					    snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", data->atqa[0], data->atqa[1]);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, atqa_str);
 | 
				
			||||||
        nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, atqa_str);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Setup Data View
 | 
					    // Setup Data View
 | 
				
			||||||
    if(nfc->dev.format == NfcDeviceSaveFormatUid) {
 | 
					    if(nfc->dev.format == NfcDeviceSaveFormatUid) {
 | 
				
			||||||
@ -161,7 +157,7 @@ const void nfc_scene_device_info_on_exit(void* context) {
 | 
				
			|||||||
    Nfc* nfc = (Nfc*)context;
 | 
					    Nfc* nfc = (Nfc*)context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Clear Custom Widget
 | 
					    // Clear Custom Widget
 | 
				
			||||||
    gui_widget_clear(nfc->widget);
 | 
					    widget_clear(nfc->widget);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(nfc->dev.format == NfcDeviceSaveFormatUid) {
 | 
					    if(nfc->dev.format == NfcDeviceSaveFormatUid) {
 | 
				
			||||||
        // Clear Dialog
 | 
					        // Clear Dialog
 | 
				
			||||||
 | 
				
			|||||||
@ -15,19 +15,19 @@ void nfc_scene_read_emv_data_success_on_enter(void* context) {
 | 
				
			|||||||
    nfc_device_set_name(&nfc->dev, "");
 | 
					    nfc_device_set_name(&nfc->dev, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Setup Custom Widget view
 | 
					    // Setup Custom Widget view
 | 
				
			||||||
    gui_widget_add_button_element(
 | 
					    widget_add_button_element(
 | 
				
			||||||
        nfc->widget,
 | 
					        nfc->widget,
 | 
				
			||||||
        GuiButtonTypeLeft,
 | 
					        GuiButtonTypeLeft,
 | 
				
			||||||
        "Back",
 | 
					        "Back",
 | 
				
			||||||
        nfc_scene_read_emv_data_success_widget_callback,
 | 
					        nfc_scene_read_emv_data_success_widget_callback,
 | 
				
			||||||
        nfc);
 | 
					        nfc);
 | 
				
			||||||
    gui_widget_add_button_element(
 | 
					    widget_add_button_element(
 | 
				
			||||||
        nfc->widget,
 | 
					        nfc->widget,
 | 
				
			||||||
        GuiButtonTypeRight,
 | 
					        GuiButtonTypeRight,
 | 
				
			||||||
        "Save",
 | 
					        "Save",
 | 
				
			||||||
        nfc_scene_read_emv_data_success_widget_callback,
 | 
					        nfc_scene_read_emv_data_success_widget_callback,
 | 
				
			||||||
        nfc);
 | 
					        nfc);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(
 | 
				
			||||||
        nfc->widget, 64, 3, AlignCenter, AlignTop, FontSecondary, nfc->dev.dev_data.emv_data.name);
 | 
					        nfc->widget, 64, 3, AlignCenter, AlignTop, FontSecondary, nfc->dev.dev_data.emv_data.name);
 | 
				
			||||||
    char pan_str[32];
 | 
					    char pan_str[32];
 | 
				
			||||||
    snprintf(
 | 
					    snprintf(
 | 
				
			||||||
@ -42,12 +42,10 @@ void nfc_scene_read_emv_data_success_on_enter(void* context) {
 | 
				
			|||||||
        emv_data->number[5],
 | 
					        emv_data->number[5],
 | 
				
			||||||
        emv_data->number[6],
 | 
					        emv_data->number[6],
 | 
				
			||||||
        emv_data->number[7]);
 | 
					        emv_data->number[7]);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 64, 13, AlignCenter, AlignTop, FontSecondary, pan_str);
 | 
				
			||||||
        nfc->widget, 64, 13, AlignCenter, AlignTop, FontSecondary, pan_str);
 | 
					 | 
				
			||||||
    char atqa_str[16];
 | 
					    char atqa_str[16];
 | 
				
			||||||
    snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", nfc_data->atqa[0], nfc_data->atqa[1]);
 | 
					    snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", nfc_data->atqa[0], nfc_data->atqa[1]);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 121, 32, AlignRight, AlignTop, FontSecondary, atqa_str);
 | 
				
			||||||
        nfc->widget, 121, 32, AlignRight, AlignTop, FontSecondary, atqa_str);
 | 
					 | 
				
			||||||
    char uid_str[32];
 | 
					    char uid_str[32];
 | 
				
			||||||
    snprintf(
 | 
					    snprintf(
 | 
				
			||||||
        uid_str,
 | 
					        uid_str,
 | 
				
			||||||
@ -57,11 +55,10 @@ void nfc_scene_read_emv_data_success_on_enter(void* context) {
 | 
				
			|||||||
        nfc_data->uid[1],
 | 
					        nfc_data->uid[1],
 | 
				
			||||||
        nfc_data->uid[2],
 | 
					        nfc_data->uid[2],
 | 
				
			||||||
        nfc_data->uid[3]);
 | 
					        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];
 | 
					    char sak_str[16];
 | 
				
			||||||
    snprintf(sak_str, sizeof(sak_str), "SAK: %02X", nfc_data->sak);
 | 
					    snprintf(sak_str, sizeof(sak_str), "SAK: %02X", nfc_data->sak);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(nfc->widget, 121, 42, AlignRight, AlignTop, FontSecondary, sak_str);
 | 
				
			||||||
        nfc->widget, 121, 42, AlignRight, AlignTop, FontSecondary, sak_str);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
 | 
					    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);
 | 
					            scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    } else if(event.type == SceneManagerEventTypeNavigation) {
 | 
				
			||||||
 | 
					        return scene_manager_search_previous_scene(nfc->scene_manager, NfcSceneReadEmvAppSuccess);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return false;
 | 
					    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) {
 | 
					const void nfc_scene_read_emv_data_success_on_exit(void* context) {
 | 
				
			||||||
    Nfc* nfc = (Nfc*)context;
 | 
					    Nfc* nfc = (Nfc*)context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gui_widget_clear(nfc->widget);
 | 
					    widget_clear(nfc->widget);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,37 +1,37 @@
 | 
				
			|||||||
#include "bank_card.h"
 | 
					#include "bank_card.h"
 | 
				
			||||||
#include "../gui_widget/gui_widget.h"
 | 
					#include <gui/modules/widget.h>
 | 
				
			||||||
#include <m-string.h>
 | 
					#include <m-string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct BankCard {
 | 
					struct BankCard {
 | 
				
			||||||
    GuiWidget* widget;
 | 
					    Widget* widget;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BankCard* bank_card_alloc() {
 | 
					BankCard* bank_card_alloc() {
 | 
				
			||||||
    BankCard* bank_card = furi_alloc(sizeof(BankCard));
 | 
					    BankCard* bank_card = furi_alloc(sizeof(BankCard));
 | 
				
			||||||
    bank_card->widget = gui_widget_alloc();
 | 
					    bank_card->widget = widget_alloc();
 | 
				
			||||||
    return bank_card;
 | 
					    return bank_card;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void bank_card_free(BankCard* bank_card) {
 | 
					void bank_card_free(BankCard* bank_card) {
 | 
				
			||||||
    furi_assert(bank_card);
 | 
					    furi_assert(bank_card);
 | 
				
			||||||
    gui_widget_free(bank_card->widget);
 | 
					    widget_free(bank_card->widget);
 | 
				
			||||||
    free(bank_card);
 | 
					    free(bank_card);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
View* bank_card_get_view(BankCard* bank_card) {
 | 
					View* bank_card_get_view(BankCard* bank_card) {
 | 
				
			||||||
    furi_assert(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) {
 | 
					void bank_card_clear(BankCard* bank_card) {
 | 
				
			||||||
    furi_assert(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) {
 | 
					void bank_card_set_name(BankCard* bank_card, char* name) {
 | 
				
			||||||
    furi_assert(bank_card);
 | 
					    furi_assert(bank_card);
 | 
				
			||||||
    furi_assert(name);
 | 
					    furi_assert(name);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(
 | 
				
			||||||
        bank_card->widget, 64, 6, AlignCenter, AlignTop, FontSecondary, name);
 | 
					        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) {
 | 
					    for(uint8_t i = 0; i < 8; i += 2) {
 | 
				
			||||||
        string_cat_printf(num_str, "%02X%02X ", number[i], number[i + 1]);
 | 
					        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));
 | 
					        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);
 | 
					    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);
 | 
					    furi_assert(bank_card);
 | 
				
			||||||
    char exp_date_str[16];
 | 
					    char exp_date_str[16];
 | 
				
			||||||
    snprintf(exp_date_str, sizeof(exp_date_str), "Exp: %02d/%02d", mon, year % 100);
 | 
					    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);
 | 
					        bank_card->widget, 122, 54, AlignRight, AlignBottom, FontSecondary, exp_date_str);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void bank_card_set_cardholder_name(BankCard* bank_card, char* name) {
 | 
					void bank_card_set_cardholder_name(BankCard* bank_card, char* name) {
 | 
				
			||||||
    furi_assert(bank_card);
 | 
					    furi_assert(bank_card);
 | 
				
			||||||
    furi_assert(name);
 | 
					    furi_assert(name);
 | 
				
			||||||
    gui_widget_add_string_element(
 | 
					    widget_add_string_element(bank_card->widget, 6, 37, AlignLeft, AlignTop, FontSecondary, name);
 | 
				
			||||||
        bank_card->widget, 6, 37, AlignLeft, AlignTop, FontSecondary, name);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user