summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve/widget/selectw.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos/eve/widget/selectw.c')
-rw-r--r--fw/fe310/eos/eve/widget/selectw.c138
1 files changed, 89 insertions, 49 deletions
diff --git a/fw/fe310/eos/eve/widget/selectw.c b/fw/fe310/eos/eve/widget/selectw.c
index 35192a4..d1d1959 100644
--- a/fw/fe310/eos/eve/widget/selectw.c
+++ b/fw/fe310/eos/eve/widget/selectw.c
@@ -1,8 +1,6 @@
#include <stdlib.h>
#include <string.h>
-#include "unicode.h"
-
#include "eve.h"
#include "eve_kbd.h"
#include "eve_font.h"
@@ -16,7 +14,7 @@
#define SELECTW_NOSELECT 0xffffffff
-static int selectw_option_verify(utf8_t *opt, uint16_t size) {
+static int _selectw_verify(utf8_t *opt, uint16_t size) {
int o_len;
uint16_t o_curr;
int rv;
@@ -32,7 +30,35 @@ static int selectw_option_verify(utf8_t *opt, uint16_t size) {
return EVE_OK;
}
-int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEFont *font, EVESelectSpec *spec) {
+static int _selectw_count(EVESelectWidget *widget) {
+ int o_len;
+ int o_curr;
+ int i;
+
+ o_curr = 0;
+ i = 0;
+ do {
+ o_len = strnlen(widget->option + o_curr, widget->option_size - o_curr);
+ if (o_len == widget->option_size - o_curr) return i;
+ if (o_len) {
+ o_curr += o_len + 1;
+ i++;
+ }
+ } while (o_len);
+
+ return i;
+}
+
+static void _selectw_update_sz(EVESelectWidget *widget, int i) {
+ EVEWidget *_widget = &widget->w;
+ EVEPage *page = _widget->page;
+
+ _widget->g.h = i * widget->font->h;
+ eve_widget_uievt_push(_widget, EVE_UIEVT_WIDGET_UPDATE_G, NULL);
+}
+
+int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVESelectSpec *spec) {
+ EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);
utf8_t *option;
option = eve_malloc(spec->option_size);
@@ -41,63 +67,45 @@ int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEFont *font, EVESe
}
memset(option, 0, spec->option_size);
- eve_selectw_init(widget, g, font, option, spec->option_size, spec->multi);
+ eve_selectw_init(widget, g, page, font, option, spec->option_size, spec->multi);
return EVE_OK;
}
-void eve_selectw_destroy(EVESelectWidget *widget) {
- eve_free(widget->option);
-}
-
-void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi) {
+void 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;
memset(widget, 0, sizeof(EVESelectWidget));
- eve_widget_init(_widget, EVE_WIDGET_TYPE_SELECT, g, font, eve_selectw_touch, eve_selectw_draw, NULL);
- eve_selectw_update(widget, option, option_size);
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_SELECT, g, page, eve_selectw_draw, eve_selectw_touch, NULL);
+ eve_selectw_update(widget, font, option, option_size);
widget->multi = multi;
}
-void eve_selectw_update(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) {
+void eve_selectw_update(EVESelectWidget *widget, EVEFont *font, utf8_t *option, uint16_t option_size) {
int rv, text_len;
+ if (font) widget->font = font;
if (option) {
- int rv = selectw_option_verify(option, option_size);
+ int rv = _selectw_verify(option, option_size);
if (rv == EVE_OK) {
+ int i;
+
widget->option = option;
widget->option_size = option_size;
widget->select = widget->multi ? 0 : SELECTW_NOSELECT;
+
+ i = _selectw_count(widget);
+ _selectw_update_sz(widget, i);
}
}
}
-int eve_selectw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
- EVESelectWidget *widget = (EVESelectWidget *)_widget;
-
- if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
- int i = t->tag0 - _widget->tag0;
- if (widget->multi) {
- uint32_t f = (0x1 << i);
-
- if (widget->select & f) {
- widget->select &= ~f;
- } else {
- widget->select |= f;
- }
- } else {
- if (widget->select == i) {
- widget->select = SELECTW_NOSELECT;
- } else {
- widget->select = i;
- }
- }
- return 1;
- }
- return 0;
+void eve_selectw_destroy(EVESelectWidget *widget) {
+ eve_free(widget->option);
}
-uint8_t eve_selectw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
+uint8_t eve_selectw_draw(EVEWidget *_widget, uint8_t tag0) {
+ EVEPage *page = _widget->page;
EVESelectWidget *widget = (EVESelectWidget *)_widget;
int o_len;
int o_curr;
@@ -119,8 +127,8 @@ uint8_t eve_selectw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
s = widget->multi ? widget->select & (0x1 << i) : widget->select == i;
x1 = _widget->g.x;
x2 = x1 + _widget->g.w;
- y1 = _widget->g.y + i * _widget->font->h;
- y2 = y1 + _widget->font->h;
+ y1 = _widget->g.y + i * widget->font->h;
+ y2 = y1 + widget->font->h;
eve_cmd_dl(BEGIN(EVE_RECTS));
if (!s) eve_cmd_dl(COLOR_MASK(0 ,0 ,0 ,0));
eve_cmd_dl(VERTEX2F(x1, y1));
@@ -133,29 +141,52 @@ uint8_t eve_selectw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
}
eve_cmd_dl(END());
if (s) eve_cmd_dl(COLOR_RGBC(page->v.color_bg));
- eve_cmd(CMD_TEXT, "hhhhs", x1, y1, _widget->font->id, 0, widget->option + o_curr);
+ eve_cmd(CMD_TEXT, "hhhhs", x1, y1, widget->font->id, 0, widget->option + o_curr);
if (s) eve_cmd_dl(COLOR_RGBC(page->v.color_fg));
o_curr += o_len + 1;
i++;
} while (o_len);
- _widget->g.h = i * _widget->font->h;
-
return _widget->tagN;
}
+int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
+ EVESelectWidget *widget = (EVESelectWidget *)_widget;
+
+ if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
+ int i = touch->tag0 - _widget->tag0;
+ if (widget->multi) {
+ uint32_t f = (0x1 << i);
+
+ if (widget->select & f) {
+ widget->select &= ~f;
+ } else {
+ widget->select |= f;
+ }
+ } else {
+ if (widget->select == i) {
+ widget->select = SELECTW_NOSELECT;
+ } else {
+ widget->select = i;
+ }
+ }
+ return 1;
+ }
+ return 0;
+}
+
utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) {
int o_len;
int o_curr;
- int i = 0;
+ int i;
o_curr = 0;
+ i = 0;
do {
o_len = strnlen(widget->option + o_curr, widget->option_size - o_curr);
if (o_len == widget->option_size - o_curr) return NULL;
if (o_len && (i == idx)) return widget->option + o_curr;
-
o_curr += o_len + 1;
i++;
} while (o_len);
@@ -170,33 +201,42 @@ utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget) {
int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *opt) {
int o_len;
int o_curr;
- int rv;
+ int rv, i;
rv = utf8_verify(opt, strlen(opt) + 1, NULL);
if (rv) return EVE_ERR;
o_curr = 0;
+ i = 0;
do {
o_len = strnlen(widget->option + o_curr, widget->option_size - o_curr);
if (o_len == widget->option_size - o_curr) return EVE_ERR_FULL;
- if (o_len) o_curr += o_len + 1;
+ if (o_len) {
+ o_curr += o_len + 1;
+ i++;
+ }
} while (o_len);
if (o_curr + strlen(opt) + 1 > widget->option_size) return EVE_ERR_FULL;
strcpy(widget->option + o_curr, opt);
+ _selectw_update_sz(widget, i + 1);
+
return EVE_OK;
}
int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *opt, uint16_t size) {
- int rv;
+ int rv, i;
- rv = selectw_option_verify(opt, size);
+ rv = _selectw_verify(opt, size);
if (rv) return rv;
if (size > widget->option_size) return EVE_ERR_FULL;
memcpy(widget->option, opt, size);
memset(widget->option + size, 0, widget->option_size - size);
+ i = _selectw_count(widget);
+ _selectw_update_sz(widget, i);
+
return EVE_OK;
}