1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#include "widget_element_i.h"
#include <m-string.h>
#include <gui/elements.h>
typedef struct {
uint8_t x;
uint8_t y;
uint8_t width;
uint8_t height;
Align horizontal;
Align vertical;
string_t text;
} GuiTextBoxModel;
static void gui_text_box_draw(Canvas* canvas, WidgetElement* element) {
furi_assert(canvas);
furi_assert(element);
GuiTextBoxModel* model = element->model;
if(string_size(model->text)) {
elements_text_box(
canvas,
model->x,
model->y,
model->width,
model->height,
model->horizontal,
model->vertical,
string_get_cstr(model->text));
}
}
static void gui_text_box_free(WidgetElement* gui_string) {
furi_assert(gui_string);
GuiTextBoxModel* model = gui_string->model;
string_clear(model->text);
free(gui_string->model);
free(gui_string);
}
WidgetElement* widget_element_text_box_create(
uint8_t x,
uint8_t y,
uint8_t width,
uint8_t height,
Align horizontal,
Align vertical,
const char* text) {
furi_assert(text);
// Allocate and init model
GuiTextBoxModel* model = malloc(sizeof(GuiTextBoxModel));
model->x = x;
model->y = y;
model->width = width;
model->height = height;
model->horizontal = horizontal;
model->vertical = vertical;
string_init_set_str(model->text, text);
// Allocate and init Element
WidgetElement* gui_string = malloc(sizeof(WidgetElement));
gui_string->parent = NULL;
gui_string->input = NULL;
gui_string->draw = gui_text_box_draw;
gui_string->free = gui_text_box_free;
gui_string->model = model;
return gui_string;
}
|