diff options
Diffstat (limited to 'fw/fe310/eos/eve/widget/textw.c')
-rw-r--r-- | fw/fe310/eos/eve/widget/textw.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c index d77e245..f85d1e0 100644 --- a/fw/fe310/eos/eve/widget/textw.c +++ b/fw/fe310/eos/eve/widget/textw.c @@ -38,11 +38,13 @@ void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *f memset(widget, 0, sizeof(EVETextWidget)); eve_widget_init(_widget, EVE_WIDGET_TYPE_TEXT, g, page, eve_textw_draw, eve_textw_touch, eve_textw_putc); widget->font = font; + rv = utf8_verify(text, text_size, &text_len); - if (rv != UTF_OK) { - if (text_len >= text_size) text_len = 0; - text[text_len] = '\0'; - } + if (rv) text[text_len] = '\0'; + + rv = eve_font_str_w(font, text, NULL, &text_len); + if (rv) text[text_len] = '\0'; + widget->text = text; widget->text_size = text_size; widget->text_len = text_len; @@ -52,6 +54,20 @@ void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *f eve_textw_text_update(widget, 0, 0); } +int eve_textw_update(EVETextWidget *widget) { + size_t text_len; + int rv; + + rv = utf8_verify(widget->text, widget->text_size, &text_len); + if (rv != UTF_OK) widget->text[text_len] = '\0'; + + rv = eve_font_str_w(widget->font, widget->text, NULL, &text_len); + if (rv != UTF_OK) widget->text[text_len] = '\0'; + + memset(widget->line, 0xff, widget->line_size * sizeof(uint16_t)); + eve_textw_text_update(widget, 0, 0); +} + int eve_textw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { EVETextWidget *widget = (EVETextWidget *)_widget; EVETextSpec *tspec = &spec->tspec.text; @@ -360,6 +376,10 @@ void eve_textw_putc(void *w, int c) { } else { c1 = cursor2; } + } + text = widget->text + c1->ch; + + if (cursor2->on) { del_c = c2->ch - c1->ch; if ((c == CH_CTRLX) || (c == CH_CTRLC)) { eve_clipb_push(text, del_c); @@ -367,10 +387,11 @@ void eve_textw_putc(void *w, int c) { } } - text = widget->text + c1->ch; if (CHAR_VALID_INPUT(c)) { ins_c = utf8_enc(c, utf8_buf); + if (ins_c < 0) return; ch_w = eve_font_ch_w(widget->font, c); + if (ch_w < 0) return; } else if (c == CH_CTRLV) { size_t clipb_len = 0; int rv; @@ -378,13 +399,14 @@ void eve_textw_putc(void *w, int c) { clipb = eve_clipb_get(); if (clipb) { rv = utf8_verify(clipb, EVE_CLIPB_SIZE_BUF, &clipb_len); - if (rv != UTF_OK) { + if (!rv) rv = eve_font_str_w(widget->font, clipb, &ch_w, NULL); + if (rv) { clipb = NULL; clipb_len = 0; + ch_w = 0; } } ins_c = clipb_len; - ch_w = eve_font_str_w(widget->font, clipb); } if (widget->text_len + ins_c >= widget->text_size + del_c) { ins_c = 0; @@ -434,8 +456,8 @@ void eve_textw_putc(void *w, int c) { uint16_t eve_textw_text_update(EVETextWidget *widget, uint16_t line, int uievt) { int i; ucp_t ch; - uint8_t ch_w; - uint8_t ch_l; + int ch_w; + int ch_l; uint16_t word_w, line_w, line_b; uint16_t new_h; EVEWidget *_widget = &widget->w; @@ -498,7 +520,7 @@ void eve_textw_cursor_update(EVETextWidget *widget, EVETextCursor *cursor) { int i = LINE_START(widget, cursor->line); uint16_t x = 0; ucp_t ch; - uint8_t ch_l; + int ch_l; EVEWidget *_widget = &widget->w; while ((i < cursor->ch) && (i < LINE_END(widget, cursor->line))) { @@ -515,8 +537,8 @@ void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t int16_t _x, _d; uint16_t c_line = LINE_EMPTY; ucp_t ch; - uint8_t ch_w; - uint8_t ch_l; + int ch_w; + int ch_l; EVEWidget *_widget = &widget->w; if ((_widget->tag0 == EVE_NOTAG) && (_widget->tagN == EVE_NOTAG)) { |