diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-08-23 22:37:16 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-08-23 22:37:16 +0200 |
commit | 1e5eb7cb910e6f23c69c2c986b6373e9f9abb980 (patch) | |
tree | 5e8ed0ad6b2fcba747c626c1c51afebbf76b3b9d /fw/fe310/eos/eve/widget/strw.c | |
parent | 57c1824affca858023c65c84e188ea7dc6c0a5f2 (diff) |
dynamic memory alloc for gui added; page navigation added
Diffstat (limited to 'fw/fe310/eos/eve/widget/strw.c')
-rw-r--r-- | fw/fe310/eos/eve/widget/strw.c | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c index 2a80a28..e973575 100644 --- a/fw/fe310/eos/eve/widget/strw.c +++ b/fw/fe310/eos/eve/widget/strw.c @@ -8,9 +8,9 @@ #include "screen/screen.h" #include "screen/window.h" #include "screen/page.h" -#include "screen/font.h" #include "clipb.h" +#include "font.h" #include "label.h" #include "widget.h" #include "strw.h" @@ -29,22 +29,47 @@ #define CHAR_VALID_INPUT(c) ((c >= 0x20) && (c < 0x7f)) +int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEStrSpec *spec) { + utf8_t *str; + uint16_t *line; + + str = eve_malloc(spec->str_size); + if (str == NULL) return EVE_ERR_NOMEM; + str[0] = '\0'; + + eve_strw_init(widget, g, spec->font, str, spec->str_size); + + return EVE_OK; +} + +void eve_strw_destroy(EVEStrWidget *widget) { + eve_free(widget->str); +} + void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEFont *font, utf8_t *str, uint16_t str_size) { - int rv, str_len; EVEWidget *_widget = &widget->w; memset(widget, 0, sizeof(EVEStrWidget)); eve_widget_init(_widget, EVE_WIDGET_TYPE_STR, g, eve_strw_touch, eve_strw_draw, eve_strw_putc); - widget->font = font; - widget->str = str; - widget->str_size = str_size; - rv = utf8_verify(str, str_size, &str_len); - if (rv != UTF_OK) { - if (str_len >= str_size) str_len = 0; - widget->str[str_len] = '\0'; + eve_strw_update(widget, font, str, str_size); +} + +void eve_strw_update(EVEStrWidget *widget, EVEFont *font, utf8_t *str, uint16_t str_size) { + int rv, str_len; + EVEWidget *_widget = &widget->w; + + if (font) widget->font = font; + if (str) { + widget->str = str; + widget->str_size = str_size; + rv = utf8_verify(str, str_size, &str_len); + if (rv != UTF_OK) { + if (str_len >= str_size) str_len = 0; + widget->str[str_len] = '\0'; + } + widget->str_len = str_len; + widget->str_g.w = eve_font_str_w(font, str); } - widget->str_len = str_len; - widget->str_g.w = eve_font_str_w(font, str); if (_widget->g.h == 0) _widget->g.h = eve_font_h(font); } |