diff options
Diffstat (limited to 'fw/fe310/eos/eve/widget/selectw.c')
-rw-r--r-- | fw/fe310/eos/eve/widget/selectw.c | 78 |
1 files changed, 58 insertions, 20 deletions
diff --git a/fw/fe310/eos/eve/widget/selectw.c b/fw/fe310/eos/eve/widget/selectw.c index f0dfed9..c0e2bfe 100644 --- a/fw/fe310/eos/eve/widget/selectw.c +++ b/fw/fe310/eos/eve/widget/selectw.c @@ -14,19 +14,26 @@ #define DIVC(x,y) ((x) / (y) + ((x) % (y) != 0)) -static int selectw_verify(utf8_t *option, uint16_t option_size) { +static int selectw_verify(utf8_t *option, uint16_t option_size, EVEFont *font, size_t *_o_len) { size_t o_len; uint16_t o_curr; int rv; o_curr = 0; while (o_curr < option_size) { - rv = utf8_verify(option + o_curr, option_size - o_curr, &o_len); - if (rv) return EVE_ERR; - if (o_len == 0) return EVE_OK; + rv = eve_font_verify(font, option + o_curr, option_size - o_curr, NULL, &o_len); + if (rv) { + if (_o_len) *_o_len = o_curr; + return rv; + } o_curr += o_len + 1; + if (o_len == 0) { + if (_o_len) *_o_len = o_curr; + return EVE_OK; + } } + if (_o_len) *_o_len = o_curr; return EVE_OK; } @@ -57,28 +64,32 @@ static void selectw_update_sz(EVESelectWidget *widget, int uievt) { if (uievt) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_UPDATE_G, _widget); } -void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi) { +int eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi) { EVEWidget *_widget = &widget->w; int rv; + rv = selectw_verify(option, option_size, font, NULL); + if (rv) return rv; + memset(widget, 0, sizeof(EVESelectWidget)); eve_widget_init(_widget, EVE_WIDGET_TYPE_SELECT, g, page, eve_selectw_draw, eve_selectw_touch, NULL); + widget->font = font; - rv = selectw_verify(option, option_size); - if (rv == EVE_OK) { - widget->option = option; - widget->option_size = option_size; - widget->option_count = selectw_count(widget); - selectw_update_sz(widget, 0); - } + widget->option = option; + widget->option_size = option_size; + widget->option_count = selectw_count(widget); + selectw_update_sz(widget, 0); + widget->multi = multi; widget->select = widget->multi ? 0 : SELECTW_NOSELECT; + + return EVE_OK; } int eve_selectw_update(EVESelectWidget *widget) { int rv, i; - rv = selectw_verify(widget->option, widget->option_size); + rv = selectw_verify(widget->option, widget->option_size, widget->font, NULL); if (rv) return rv; widget->option_count = selectw_count(widget); @@ -92,6 +103,7 @@ int eve_selectw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { EVESelectSpec *tspec = &spec->tspec.select; EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); utf8_t *option; + int rv; option = eve_malloc(tspec->option_size); if (option == NULL) { @@ -99,9 +111,8 @@ int eve_selectw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { } memset(option, 0, tspec->option_size); - eve_selectw_init(widget, &spec->g, page, font, option, tspec->option_size, tspec->multi); - - return EVE_OK; + rv = eve_selectw_init(widget, &spec->g, page, font, option, tspec->option_size, tspec->multi); + return rv; } void eve_selectw_destroy(EVEWidget *_widget) { @@ -172,6 +183,10 @@ uint8_t eve_selectw_draw(EVEWidget *_widget, uint8_t tag0) { int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { EVESelectWidget *widget = (EVESelectWidget *)_widget; + EVEPage *page = _widget->page; + + /* widget received non-touch event, always return 0 */ + if (evt & EVE_TOUCH_ETYPE_EXT) return 0; if (evt & EVE_TOUCH_ETYPE_TAG_UP) { int i = touch->tag0 - _widget->tag0 + widget->line0; @@ -192,6 +207,8 @@ int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { } } + eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_UPDATE, _widget); + return 1; } @@ -226,8 +243,8 @@ int eve_selectw_add_option(EVESelectWidget *widget, utf8_t *option) { int o_curr; int rv, i; - rv = utf8_verify(option, strlen(option) + 1, NULL); - if (rv) return EVE_ERR; + rv = eve_font_verify(widget->font, option, 0, NULL, NULL); + if (rv) return rv; o_curr = 0; i = 0; @@ -252,10 +269,11 @@ int eve_selectw_add_option(EVESelectWidget *widget, utf8_t *option) { int eve_selectw_set_option(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) { int rv, i; - rv = selectw_verify(option, option_size); - if (rv) return rv; if (option_size > widget->option_size) return EVE_ERR_FULL; + rv = selectw_verify(option, option_size, widget->font, NULL); + if (rv) return rv; + memcpy(widget->option, option, option_size); memset(widget->option + option_size, 0, widget->option_size - option_size); @@ -264,3 +282,23 @@ int eve_selectw_set_option(EVESelectWidget *widget, utf8_t *option, uint16_t opt return EVE_OK; } + +void eve_selectw_fix_option(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) { + size_t good_l, bad_l; + int rv; + + do { + rv = selectw_verify(option, option_size, widget->font, &good_l); + if (rv == EVE_OK) return; + + option += good_l; + option_size -= good_l; + + bad_l = strnlen(option, option_size); + if (bad_l != option_size) { + bad_l++; + } + memmove(option, option + bad_l, option_size - bad_l); + memset(option + option_size - bad_l, 0, bad_l); + } while (bad_l != option_size); +} |