2021-07-23 13:09:34 +00:00
|
|
|
#include "widget_element_i.h"
|
2021-07-22 06:05:07 +00:00
|
|
|
#include <m-string.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t x;
|
|
|
|
uint8_t y;
|
|
|
|
const Icon* icon;
|
|
|
|
} GuiIconModel;
|
|
|
|
|
2021-07-23 13:09:34 +00:00
|
|
|
static void gui_icon_draw(Canvas* canvas, WidgetElement* element) {
|
2021-07-22 06:05:07 +00:00
|
|
|
furi_assert(canvas);
|
|
|
|
furi_assert(element);
|
|
|
|
GuiIconModel* model = element->model;
|
|
|
|
|
|
|
|
if(model->icon) {
|
|
|
|
canvas_draw_icon(canvas, model->x, model->y, model->icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 13:09:34 +00:00
|
|
|
static void gui_icon_free(WidgetElement* gui_icon) {
|
2021-07-22 06:05:07 +00:00
|
|
|
furi_assert(gui_icon);
|
|
|
|
|
|
|
|
free(gui_icon->model);
|
|
|
|
free(gui_icon);
|
|
|
|
}
|
|
|
|
|
2021-07-23 13:09:34 +00:00
|
|
|
WidgetElement* widget_element_icon_create(uint8_t x, uint8_t y, const Icon* icon) {
|
2021-07-22 06:05:07 +00:00
|
|
|
furi_assert(icon);
|
|
|
|
|
|
|
|
// Allocate and init model
|
|
|
|
GuiIconModel* model = furi_alloc(sizeof(GuiIconModel));
|
|
|
|
model->x = x;
|
|
|
|
model->y = y;
|
|
|
|
model->icon = icon;
|
|
|
|
|
|
|
|
// Allocate and init Element
|
2021-07-23 13:09:34 +00:00
|
|
|
WidgetElement* gui_icon = furi_alloc(sizeof(WidgetElement));
|
2021-07-22 06:05:07 +00:00
|
|
|
gui_icon->parent = NULL;
|
|
|
|
gui_icon->input = NULL;
|
|
|
|
gui_icon->draw = gui_icon_draw;
|
|
|
|
gui_icon->free = gui_icon_free;
|
|
|
|
gui_icon->model = model;
|
|
|
|
|
|
|
|
return gui_icon;
|
|
|
|
}
|