summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve/widget
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos/eve/widget')
-rw-r--r--fw/fe310/eos/eve/widget/Makefile2
-rw-r--r--fw/fe310/eos/eve/widget/freew.c35
-rw-r--r--fw/fe310/eos/eve/widget/freew.h6
-rw-r--r--fw/fe310/eos/eve/widget/label.c7
-rw-r--r--fw/fe310/eos/eve/widget/label.h11
-rw-r--r--fw/fe310/eos/eve/widget/pagew.c21
-rw-r--r--fw/fe310/eos/eve/widget/pagew.h4
-rw-r--r--fw/fe310/eos/eve/widget/selectw.c54
-rw-r--r--fw/fe310/eos/eve/widget/selectw.h14
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.c16
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.h11
-rw-r--r--fw/fe310/eos/eve/widget/strw.c43
-rw-r--r--fw/fe310/eos/eve/widget/strw.h7
-rw-r--r--fw/fe310/eos/eve/widget/textw.c57
-rw-r--r--fw/fe310/eos/eve/widget/textw.h6
-rw-r--r--fw/fe310/eos/eve/widget/togglew.c58
-rw-r--r--fw/fe310/eos/eve/widget/togglew.h21
-rw-r--r--fw/fe310/eos/eve/widget/widget.c63
-rw-r--r--fw/fe310/eos/eve/widget/widget.h32
-rw-r--r--fw/fe310/eos/eve/widget/widgets.c43
-rw-r--r--fw/fe310/eos/eve/widget/widgets.h35
21 files changed, 347 insertions, 199 deletions
diff --git a/fw/fe310/eos/eve/widget/Makefile b/fw/fe310/eos/eve/widget/Makefile
index 31349a8..0bb1533 100644
--- a/fw/fe310/eos/eve/widget/Makefile
+++ b/fw/fe310/eos/eve/widget/Makefile
@@ -1,7 +1,7 @@
include ../../../common.mk
CFLAGS += -I..
-obj = label.o widget.o freew.o spacerw.o pagew.o strw.o textw.o selectw.o
+obj = label.o widget.o widgets.o freew.o spacerw.o pagew.o strw.o textw.o selectw.o togglew.o
%.o: %.c %.h
diff --git a/fw/fe310/eos/eve/widget/freew.c b/fw/fe310/eos/eve/widget/freew.c
index 86c2686..e7591da 100644
--- a/fw/fe310/eos/eve/widget/freew.c
+++ b/fw/fe310/eos/eve/widget/freew.c
@@ -8,15 +8,7 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "freew.h"
-
-int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEPage *page, EVEFreeSpec *spec) {
- eve_freew_init(widget, g, page, spec->draw, spec->touch, spec->putc);
-
- return EVE_OK;
-}
void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_draw_t draw, eve_freew_touch_t touch, eve_kbd_input_handler_t putc) {
EVEWidget *_widget = &widget->w;
@@ -25,16 +17,15 @@ void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_
eve_widget_init(_widget, EVE_WIDGET_TYPE_FREE, g, page, eve_freew_draw, eve_freew_touch, putc);
widget->_draw = draw;
widget->_touch = touch;
- widget->w.putc = putc;
}
-void eve_freew_tag(EVEFreeWidget *widget) {
- EVEWidget *_widget = &widget->w;
+int eve_freew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
+ EVEFreeSpec *tspec = &spec->tspec.free;
- if (_widget->tagN != EVE_NOTAG) {
- eve_cmd_dl(TAG(_widget->tagN));
- _widget->tagN++;
- }
+ eve_freew_init(widget, &spec->g, page, tspec->draw, tspec->touch, tspec->putc);
+
+ return EVE_OK;
}
uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0) {
@@ -49,6 +40,18 @@ uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0) {
int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
+ int ret;
+
+ ret = widget->_touch(widget, touch, evt);
+ if (ret) eve_widget_set_focus(_widget, NULL);
+ return ret;
+}
- return widget->_touch(widget, touch, evt);
+void eve_freew_tag(EVEFreeWidget *widget) {
+ EVEWidget *_widget = &widget->w;
+
+ if (_widget->tagN != EVE_NOTAG) {
+ eve_cmd_dl(TAG(_widget->tagN));
+ _widget->tagN++;
+ }
}
diff --git a/fw/fe310/eos/eve/widget/freew.h b/fw/fe310/eos/eve/widget/freew.h
index 7eda8c1..324e98d 100644
--- a/fw/fe310/eos/eve/widget/freew.h
+++ b/fw/fe310/eos/eve/widget/freew.h
@@ -1,6 +1,7 @@
#include <stdint.h>
struct EVEFreeWidget;
+struct EVEWidgetSpec;
typedef void (*eve_freew_draw_t) (struct EVEFreeWidget *);
typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVETouch *, uint16_t);
@@ -17,9 +18,10 @@ typedef struct EVEFreeSpec {
eve_kbd_input_handler_t putc;
} EVEFreeSpec;
-int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEPage *page, EVEFreeSpec *spec);
void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_draw_t draw, eve_freew_touch_t touch, eve_kbd_input_handler_t putc);
-void eve_freew_tag(EVEFreeWidget *widget);
+int eve_freew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0);
int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
+
+void eve_freew_tag(EVEFreeWidget *widget);
diff --git a/fw/fe310/eos/eve/widget/label.c b/fw/fe310/eos/eve/widget/label.c
index f2d2e8e..43d555d 100644
--- a/fw/fe310/eos/eve/widget/label.c
+++ b/fw/fe310/eos/eve/widget/label.c
@@ -16,6 +16,13 @@ void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title) {
label->font = font;
label->title = title;
if (label->g.h == 0) label->g.h = eve_font_h(font);
+ if (label->g.w == 0) label->g.w = eve_font_str_w(font, label->title) + EVE_LABEL_MARGIN;
+}
+
+void eve_label_create(EVELabel *label, EVELabelSpec *spec, EVEPage *page) {
+ EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);
+
+ eve_label_init(label, &spec->g, font, spec->title);
}
void eve_label_draw(EVELabel *label) {
diff --git a/fw/fe310/eos/eve/widget/label.h b/fw/fe310/eos/eve/widget/label.h
index 659c057..9992f8c 100644
--- a/fw/fe310/eos/eve/widget/label.h
+++ b/fw/fe310/eos/eve/widget/label.h
@@ -1,10 +1,21 @@
#include <stdint.h>
+#define EVE_LABEL_MARGIN 10
+
typedef struct EVELabel {
EVERect g;
EVEFont *font;
char *title;
} EVELabel;
+typedef struct EVELabelSpec {
+ EVERect g;
+ EVEFont *font;
+ char *title;
+ int16_t margin;
+} EVELabelSpec;
+
void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title);
+
+void eve_label_create(EVELabel *label, EVELabelSpec *spec, EVEPage *page);
void eve_label_draw(EVELabel *label); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/pagew.c b/fw/fe310/eos/eve/widget/pagew.c
index bd7819f..c926892 100644
--- a/fw/fe310/eos/eve/widget/pagew.c
+++ b/fw/fe310/eos/eve/widget/pagew.c
@@ -8,17 +8,7 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "pagew.h"
-
-int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEPageSpec *spec) {
- EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);
-
- eve_pagew_init(widget, g, page, font, spec->title, spec->constructor);
-
- return EVE_OK;
-}
void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *title, eve_view_constructor_t constructor) {
EVEWidget *_widget = &widget->w;
@@ -31,6 +21,16 @@ void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *f
if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font);
}
+int eve_pagew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVEPageWidget *widget = (EVEPageWidget *)_widget;
+ EVEPageSpec *tspec = &spec->tspec.page;
+ EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window);
+
+ eve_pagew_init(widget, &spec->g, page, font, tspec->title, tspec->constructor);
+
+ return EVE_OK;
+}
+
uint8_t eve_pagew_draw(EVEWidget *_widget, uint8_t tag0) {
EVEPageWidget *widget = (EVEPageWidget *)_widget;
@@ -51,6 +51,7 @@ int eve_pagew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
EVEPageWidget *widget = (EVEPageWidget *)_widget;
if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
+ eve_widget_set_focus(_widget, NULL);
eve_page_open(parent, widget->constructor);
return 1;
}
diff --git a/fw/fe310/eos/eve/widget/pagew.h b/fw/fe310/eos/eve/widget/pagew.h
index 76ac0d2..b1a91b2 100644
--- a/fw/fe310/eos/eve/widget/pagew.h
+++ b/fw/fe310/eos/eve/widget/pagew.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+struct EVEWidgetSpec;
+
typedef struct EVEPageWidget {
EVEWidget w;
EVEFont *font;
@@ -13,8 +15,8 @@ typedef struct EVEPageSpec {
eve_view_constructor_t constructor;
} EVEPageSpec;
-int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEPageSpec *spec);
void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *title, eve_view_constructor_t constructor);
+int eve_pagew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
uint8_t eve_pagew_draw(EVEWidget *_widget, uint8_t tag0);
int eve_pagew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
diff --git a/fw/fe310/eos/eve/widget/selectw.c b/fw/fe310/eos/eve/widget/selectw.c
index 46ed3d1..5acf998 100644
--- a/fw/fe310/eos/eve/widget/selectw.c
+++ b/fw/fe310/eos/eve/widget/selectw.c
@@ -8,9 +8,7 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "selectw.h"
#define SELECTW_NOSELECT 0xffffffff
@@ -59,21 +57,6 @@ static void selectw_update_sz(EVESelectWidget *widget, int uievt) {
if (uievt) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_UPDATE_G, _widget);
}
-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);
- if (option == NULL) {
- return EVE_ERR_NOMEM;
- }
- memset(option, 0, spec->option_size);
-
- eve_selectw_init(widget, g, page, font, option, spec->option_size, spec->multi);
-
- return EVE_OK;
-}
-
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;
int rv;
@@ -92,13 +75,32 @@ void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFon
widget->select = widget->multi ? 0 : SELECTW_NOSELECT;
}
-void eve_selectw_destroy(EVESelectWidget *widget) {
+int eve_selectw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVESelectWidget *widget = (EVESelectWidget *)_widget;
+ EVESelectSpec *tspec = &spec->tspec.select;
+ EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window);
+ utf8_t *option;
+
+ option = eve_malloc(tspec->option_size);
+ if (option == NULL) {
+ return EVE_ERR_NOMEM;
+ }
+ memset(option, 0, tspec->option_size);
+
+ eve_selectw_init(widget, &spec->g, page, font, option, tspec->option_size, tspec->multi);
+
+ return EVE_OK;
+}
+
+void eve_selectw_destroy(EVEWidget *_widget) {
+ EVESelectWidget *widget = (EVESelectWidget *)_widget;
+
eve_free(widget->option);
}
uint8_t eve_selectw_draw(EVEWidget *_widget, uint8_t tag0) {
- EVEPage *page = _widget->page;
EVESelectWidget *widget = (EVESelectWidget *)_widget;
+ EVEPage *page = _widget->page;
int o_len;
int o_curr;
int i, s;
@@ -161,6 +163,7 @@ int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
int i = touch->tag0 - _widget->tag0 + widget->line0;
+
if (widget->multi) {
uint32_t f = (0x1 << i);
@@ -176,12 +179,15 @@ int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
widget->select = i;
}
}
+
+ eve_widget_set_focus(_widget, NULL);
return 1;
}
+
return 0;
}
-utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) {
+utf8_t *eve_selectw_option(EVESelectWidget *widget, int idx) {
int o_len;
int o_curr;
int i;
@@ -199,11 +205,11 @@ utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) {
return NULL;
}
-utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget) {
- return eve_selectw_option_get(widget, widget->select);
+utf8_t *eve_selectw_option_selected(EVESelectWidget *widget) {
+ return eve_selectw_option(widget, widget->select);
}
-int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option) {
+int eve_selectw_add_option(EVESelectWidget *widget, utf8_t *option) {
int o_len;
int o_curr;
int rv, i;
@@ -231,7 +237,7 @@ int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option) {
return EVE_OK;
}
-int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) {
+int eve_selectw_set_option(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) {
int rv, i;
rv = selectw_verify(option, option_size);
diff --git a/fw/fe310/eos/eve/widget/selectw.h b/fw/fe310/eos/eve/widget/selectw.h
index 939e362..f1b7071 100644
--- a/fw/fe310/eos/eve/widget/selectw.h
+++ b/fw/fe310/eos/eve/widget/selectw.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+struct EVEWidgetSpec;
+
typedef struct EVESelectWidget {
EVEWidget w;
EVEFont *font;
@@ -17,14 +19,14 @@ typedef struct EVESelectSpec {
uint8_t multi;
} EVESelectSpec;
-int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVESelectSpec *spec);
void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi);
-void eve_selectw_destroy(EVESelectWidget *widget);
+int eve_selectw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
+void eve_selectw_destroy(EVEWidget *_widget);
uint8_t eve_selectw_draw(EVEWidget *_widget, uint8_t tag0);
int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
-utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx);
-utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget);
-int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option);
-int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *option, uint16_t option_size);
+utf8_t *eve_selectw_option(EVESelectWidget *widget, int idx);
+utf8_t *eve_selectw_option_selected(EVESelectWidget *widget);
+int eve_selectw_add_option(EVESelectWidget *widget, utf8_t *option);
+int eve_selectw_set_option(EVESelectWidget *widget, utf8_t *option, uint16_t option_size);
diff --git a/fw/fe310/eos/eve/widget/spacerw.c b/fw/fe310/eos/eve/widget/spacerw.c
index d9f9104..aa5bec1 100644
--- a/fw/fe310/eos/eve/widget/spacerw.c
+++ b/fw/fe310/eos/eve/widget/spacerw.c
@@ -8,21 +8,17 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "spacerw.h"
-int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEPage *page, EVESpacerSpec *spec) {
- eve_spacerw_init(widget, g, page);
-
- return EVE_OK;
+void eve_spacerw_init(EVEWidget *widget, EVERect *g, EVEPage *page) {
+ memset(widget, 0, sizeof(EVEWidget));
+ eve_widget_init(widget, EVE_WIDGET_TYPE_SPACER, g, page, eve_spacerw_draw, eve_spacerw_touch, NULL);
}
-void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g, EVEPage *page) {
- EVEWidget *_widget = &widget->w;
+int eve_spacerw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ eve_spacerw_init(_widget, &spec->g, page);
- memset(widget, 0, sizeof(EVESpacerWidget));
- eve_widget_init(_widget, EVE_WIDGET_TYPE_SPACER, g, page, eve_spacerw_draw, eve_spacerw_touch, NULL);
+ return EVE_OK;
}
uint8_t eve_spacerw_draw(EVEWidget *_widget, uint8_t tag0) {
diff --git a/fw/fe310/eos/eve/widget/spacerw.h b/fw/fe310/eos/eve/widget/spacerw.h
index 9dafa8b..621b45b 100644
--- a/fw/fe310/eos/eve/widget/spacerw.h
+++ b/fw/fe310/eos/eve/widget/spacerw.h
@@ -1,14 +1,9 @@
#include <stdint.h>
-typedef struct EVESpacerWidget {
- EVEWidget w;
-} EVESpacerWidget;
+struct EVEWidgetSpec;
-typedef struct EVESpacerSpec {
-} EVESpacerSpec;
-
-int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEPage *page, EVESpacerSpec *spec);
-void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g, EVEPage *page);
+void eve_spacerw_init(EVEWidget *widget, EVERect *g, EVEPage *page);
+int eve_spacerw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
uint8_t eve_spacerw_draw(EVEWidget *_widget, uint8_t tag0);
int eve_spacerw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c
index e78cf46..ae9ccab 100644
--- a/fw/fe310/eos/eve/widget/strw.c
+++ b/fw/fe310/eos/eve/widget/strw.c
@@ -10,9 +10,7 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "strw.h"
#define STRW_TOUCH_OPT EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_X | EVE_TOUCH_OPT_TRACK_EXT_X | EVE_TOUCH_OPT_LPRESS
@@ -29,20 +27,6 @@
#define CHAR_VALID_INPUT(c) ((c >= 0x20) && (c < 0x7f))
-int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEStrSpec *spec) {
- EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);
- 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, page, font, str, spec->str_size);
-
- return EVE_OK;
-}
-
void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *str, uint16_t str_size) {
EVEWidget *_widget = &widget->w;
int rv, str_len;
@@ -71,10 +55,29 @@ int eve_strw_update(EVEStrWidget *widget) {
widget->str[str_len] = '\0';
}
widget->str_len = str_len;
+ widget->str_g.w = eve_font_str_w(widget->font, widget->str);
return (rv == UTF_OK) ? EVE_OK : EVE_ERR;
}
-void eve_strw_destroy(EVEStrWidget *widget) {
+int eve_strw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVEStrWidget *widget = (EVEStrWidget *)_widget;
+ EVEStrSpec *tspec = &spec->tspec.str;
+ EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window);
+ utf8_t *str;
+ uint16_t *line;
+
+ str = eve_malloc(tspec->str_size);
+ if (str == NULL) return EVE_ERR_NOMEM;
+ str[0] = '\0';
+
+ eve_strw_init(widget, &spec->g, page, font, str, tspec->str_size);
+
+ return EVE_OK;
+}
+
+void eve_strw_destroy(EVEWidget *_widget) {
+ EVEStrWidget *widget = (EVEStrWidget *)_widget;
+
eve_free(widget->str);
}
@@ -86,7 +89,7 @@ static void set_focus(EVEStrWidget *widget) {
focus.y = _widget->g.y;
focus.w = _widget->g.w;
focus.h = 2 * widget->font->h;
- eve_widget_focus(_widget, &focus);
+ eve_widget_set_focus(_widget, &focus);
}
static EVEStrCursor *cursor_prox(EVEStrWidget *widget, EVEStrCursor *cursor, EVETouch *touch, short *dx) {
@@ -215,8 +218,8 @@ uint8_t eve_strw_draw(EVEWidget *_widget, uint8_t tag0) {
}
int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
- EVEPage *page = _widget->page;
EVEStrWidget *widget = (EVEStrWidget *)_widget;
+ EVEPage *page = _widget->page;
EVEStrCursor *t_cursor = NULL;
short dx;
int ret = 0;
@@ -290,6 +293,7 @@ int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
widget->track.dx = 0;
}
+ if (ret) eve_widget_set_focus(_widget, NULL);
return ret;
}
@@ -305,7 +309,6 @@ void eve_strw_putc(void *w, int c) {
int ins_c = 0, del_c = 0;
int ins_w = 0, del_w = 0;
-
if (c == EVE_PAGE_KBDCH_CLOSE) {
if (cursor1->on) eve_strw_cursor_clear(widget, cursor1);
if (cursor2->on) eve_strw_cursor_clear(widget, cursor2);
diff --git a/fw/fe310/eos/eve/widget/strw.h b/fw/fe310/eos/eve/widget/strw.h
index 44e5e2d..acfd74b 100644
--- a/fw/fe310/eos/eve/widget/strw.h
+++ b/fw/fe310/eos/eve/widget/strw.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+struct EVEWidgetSpec;
+
typedef struct EVEStrCursor {
char on;
uint16_t x;
@@ -31,13 +33,14 @@ typedef struct EVEStrSpec {
uint16_t str_size;
} EVEStrSpec;
-int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEStrSpec *spec);
void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *str, uint16_t str_size);
-void eve_strw_destroy(EVEStrWidget *widget);
int eve_strw_update(EVEStrWidget *widget);
+int eve_strw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
+void eve_strw_destroy(EVEWidget *_widget);
uint8_t eve_strw_draw(EVEWidget *_widget, uint8_t tag0);
int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
+
void eve_strw_putc(void *_page, int c);
void eve_strw_cursor_set(EVEStrWidget *widget, EVEStrCursor *cursor, int16_t x);
void eve_strw_cursor_clear(EVEStrWidget *widget, EVEStrCursor *cursor); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c
index e994c0e..70a1e06 100644
--- a/fw/fe310/eos/eve/widget/textw.c
+++ b/fw/fe310/eos/eve/widget/textw.c
@@ -10,9 +10,7 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "textw.h"
#define TEXTW_TOUCH_OPT EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_TRACK_EXT_XY | EVE_TOUCH_OPT_LPRESS
@@ -32,27 +30,6 @@
#define DIVC(x,y) ((x) / (y) + ((x) % (y) != 0))
-int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEPage *page, EVETextSpec *spec) {
- EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);
- utf8_t *text;
- uint16_t *line;
-
- text = eve_malloc(spec->text_size);
- if (text == NULL) {
- return EVE_ERR_NOMEM;
- }
- text[0] = '\0';
- line = eve_malloc(sizeof(uint16_t) * spec->line_size);
- if (line == NULL) {
- free(text);
- return EVE_ERR_NOMEM;
- }
-
- eve_textw_init(widget, g, page, font, text, spec->text_size, line, spec->line_size);
-
- return EVE_OK;
-}
-
void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size) {
EVEWidget *_widget = &widget->w;
int rv, text_len;
@@ -74,7 +51,32 @@ void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *f
eve_textw_text_update(widget, 0, 0);
}
-void eve_textw_destroy(EVETextWidget *widget) {
+int eve_textw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVETextWidget *widget = (EVETextWidget *)_widget;
+ EVETextSpec *tspec = &spec->tspec.text;
+ EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window);
+ utf8_t *text;
+ uint16_t *line;
+
+ text = eve_malloc(tspec->text_size);
+ if (text == NULL) {
+ return EVE_ERR_NOMEM;
+ }
+ text[0] = '\0';
+ line = eve_malloc(sizeof(uint16_t) * tspec->line_size);
+ if (line == NULL) {
+ free(text);
+ return EVE_ERR_NOMEM;
+ }
+
+ eve_textw_init(widget, &spec->g, page, font, text, tspec->text_size, line, tspec->line_size);
+
+ return EVE_OK;
+}
+
+void eve_textw_destroy(EVEWidget *_widget) {
+ EVETextWidget *widget = (EVETextWidget *)_widget;
+
eve_free(widget->line);
eve_free(widget->text);
}
@@ -87,7 +89,7 @@ static void set_focus(EVETextWidget *widget, EVETextCursor *cursor) {
focus.y = _widget->g.y + cursor->line * widget->font->h;
focus.w = _widget->g.w;
focus.h = 2 * widget->font->h;
- eve_widget_focus(_widget, &focus);
+ eve_widget_set_focus(_widget, &focus);
}
static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, EVETouch *touch, short *dx, short *dl) {
@@ -144,8 +146,8 @@ static void draw_cursor(EVETextWidget *widget, EVETextCursor *cursor) {
}
uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) {
- EVEPage *page = _widget->page;
EVETextWidget *widget = (EVETextWidget *)_widget;
+ EVEPage *page = _widget->page;
int line0, lineN;
int _line0, _lineN;
char lineNvisible;
@@ -237,8 +239,8 @@ uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) {
}
int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
- EVEPage *page = _widget->page;
EVETextWidget *widget = (EVETextWidget *)_widget;
+ EVEPage *page = _widget->page;
EVETextCursor *t_cursor = NULL;
short dx, dl;
int ret = 0;
@@ -289,6 +291,7 @@ int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
widget->track.dl = 0;
}
+ if (ret) eve_widget_set_focus(_widget, NULL);
return ret;
}
diff --git a/fw/fe310/eos/eve/widget/textw.h b/fw/fe310/eos/eve/widget/textw.h
index 570bba8..1c33733 100644
--- a/fw/fe310/eos/eve/widget/textw.h
+++ b/fw/fe310/eos/eve/widget/textw.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+struct EVEWidgetSpec;
+
typedef struct EVETextCursor {
char on;
uint16_t x;
@@ -32,10 +34,10 @@ typedef struct EVETextSpec {
uint16_t line_size;
} EVETextSpec;
-int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEPage *page, EVETextSpec *spec);
void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size);
-void eve_textw_destroy(EVETextWidget *widget);
+int eve_textw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
+void eve_textw_destroy(EVEWidget *_widget);
uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0);
int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
void eve_textw_putc(void *_w, int c);
diff --git a/fw/fe310/eos/eve/widget/togglew.c b/fw/fe310/eos/eve/widget/togglew.c
new file mode 100644
index 0000000..fbebacb
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/togglew.c
@@ -0,0 +1,58 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+#include "eve_font.h"
+
+#include "screen/window.h"
+#include "screen/page.h"
+
+#include "widget.h"
+
+void eve_togglew_init(EVEToggleWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *labels) {
+ EVEWidget *_widget = &widget->w;
+
+ memset(widget, 0, sizeof(EVEPageWidget));
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_TOGGLE, g, page, eve_togglew_draw, eve_togglew_touch, NULL);
+ widget->font = font;
+ widget->labels = labels;
+ if (_widget->g.w == 0) _widget->g.w = 3 * eve_font_h(widget->font);
+ if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font);
+}
+
+int eve_togglew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVEToggleWidget *widget = (EVEToggleWidget *)_widget;
+ EVEToggleSpec *tspec = &spec->tspec.toggle;
+ EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window);
+
+ eve_togglew_init(widget, &spec->g, page, font, tspec->labels);
+
+ return EVE_OK;
+}
+
+uint8_t eve_togglew_draw(EVEWidget *_widget, uint8_t tag0) {
+ EVEToggleWidget *widget = (EVEToggleWidget *)_widget;
+
+ _widget->tag0 = tag0;
+ if (tag0 != EVE_NOTAG) {
+ eve_cmd_dl(TAG(tag0));
+ tag0++;
+ }
+ _widget->tagN = tag0;
+
+ eve_cmd(CMD_TOGGLE, "hhhhhhs", _widget->g.x, _widget->g.y, _widget->g.w, widget->font->id, 0, widget->state ? 65535 : 0, widget->labels);
+
+ return _widget->tagN;
+}
+
+int eve_togglew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
+ EVEToggleWidget *widget = (EVEToggleWidget *)_widget;
+
+ if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
+ widget->state = !widget->state;
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/fw/fe310/eos/eve/widget/togglew.h b/fw/fe310/eos/eve/widget/togglew.h
new file mode 100644
index 0000000..26ff77c
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/togglew.h
@@ -0,0 +1,21 @@
+#include <stdint.h>
+
+struct EVEWidgetSpec;
+
+typedef struct EVEToggleWidget {
+ EVEWidget w;
+ EVEFont *font;
+ char *labels;
+ uint8_t state;
+} EVEToggleWidget;
+
+typedef struct EVEToggleSpec {
+ EVEFont *font;
+ char *labels;
+} EVEToggleSpec;
+
+void eve_togglew_init(EVEToggleWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *labels);
+
+int eve_togglew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
+uint8_t eve_togglew_draw(EVEWidget *_widget, uint8_t tag0);
+int eve_togglew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
diff --git a/fw/fe310/eos/eve/widget/widget.c b/fw/fe310/eos/eve/widget/widget.c
index 96d2ddf..a157301 100644
--- a/fw/fe310/eos/eve/widget/widget.c
+++ b/fw/fe310/eos/eve/widget/widget.c
@@ -8,37 +8,11 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "widgets.h"
-
-static const size_t _widget_size[] = {
- 0,
- sizeof(EVEFreeWidget),
- sizeof(EVESpacerWidget),
- sizeof(EVEPageWidget),
- sizeof(EVEStrWidget),
- sizeof(EVETextWidget),
- sizeof(EVESelectWidget),
-};
-
-static const eve_widget_create_t _widget_create[] = {
- NULL,
- (eve_widget_create_t)eve_freew_create,
- (eve_widget_create_t)eve_spacerw_create,
- (eve_widget_create_t)eve_pagew_create,
- (eve_widget_create_t)eve_strw_create,
- (eve_widget_create_t)eve_textw_create,
- (eve_widget_create_t)eve_selectw_create,
-};
-
-static const eve_widget_destroy_t _widget_destroy[] = {
- NULL,
- NULL,
- NULL,
- NULL,
- (eve_widget_destroy_t)eve_strw_destroy,
- (eve_widget_destroy_t)eve_textw_destroy,
- (eve_widget_destroy_t)eve_selectw_destroy,
-};
+#include "widget.h"
+
+extern const size_t _eve_widget_size[];
+extern const eve_widget_create_t _eve_widget_create[];
+extern const eve_widget_destroy_t _eve_widget_destroy[];
void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, eve_widget_draw_t draw, eve_widget_touch_t touch, eve_kbd_input_handler_t putc) {
if (g) widget->g = *g;
@@ -50,7 +24,7 @@ void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page,
}
size_t eve_widget_size(uint8_t type) {
- return _widget_size[type];
+ return _eve_widget_size[type];
}
void eve_widget_set_label(EVEWidget *widget, EVELabel *label) {
@@ -59,19 +33,32 @@ void eve_widget_set_label(EVEWidget *widget, EVELabel *label) {
EVEWidget *eve_widget_next(EVEWidget *widget) {
char *_w = (char *)widget;
- return (EVEWidget *)(_w + _widget_size[widget->type]);
+ return (EVEWidget *)(_w + _eve_widget_size[widget->type]);
}
-int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, EVEWidgetSpecT *spec) {
- return _widget_create[type](widget, g, page, spec);
+int eve_widget_create(EVEWidget *widget, EVEWidgetSpec *spec, EVEPage *page) {
+ int rv;
+
+ rv = _eve_widget_create[spec->type](widget, spec, page);
+ if (!rv) eve_widget_set_flags(widget, spec->flags);
+
+ return rv;
}
void eve_widget_destroy(EVEWidget *widget) {
- if (_widget_destroy[widget->type]) _widget_destroy[widget->type](widget);
+ if (_eve_widget_destroy[widget->type]) _eve_widget_destroy[widget->type](widget);
}
-void eve_widget_focus(EVEWidget *widget, EVERect *rect) {
+void eve_widget_set_focus(EVEWidget *widget, EVERect *rect) {
EVEPage *page = widget->page;
- eve_page_focus_widget(page, widget, rect);
+ eve_page_set_focus(page, widget, rect);
+}
+
+void eve_widget_set_flags(EVEWidget *widget, uint8_t flags) {
+ widget->flags |= flags;
+}
+
+void eve_widget_clr_flags(EVEWidget *widget, uint8_t flags) {
+ widget->flags &= ~flags;
}
diff --git a/fw/fe310/eos/eve/widget/widget.h b/fw/fe310/eos/eve/widget/widget.h
index f081b4c..0bef06e 100644
--- a/fw/fe310/eos/eve/widget/widget.h
+++ b/fw/fe310/eos/eve/widget/widget.h
@@ -1,11 +1,10 @@
#include <stdint.h>
-#define EVE_WIDGET_TYPE_FREE 1
-#define EVE_WIDGET_TYPE_SPACER 2
-#define EVE_WIDGET_TYPE_PAGE 3
-#define EVE_WIDGET_TYPE_STR 4
-#define EVE_WIDGET_TYPE_TEXT 5
-#define EVE_WIDGET_TYPE_SELECT 6
+#include "label.h"
+
+#define EVEP_WIDGET_FLAG_RO 0x01
+#define EVEP_WIDGET_FLAG_HIDDEN 0x02
+#define EVEP_WIDGET_FLAG_BUSY 0x04
struct EVEWidget;
@@ -20,12 +19,31 @@ typedef struct EVEWidget {
eve_kbd_input_handler_t putc;
EVELabel *label;
uint8_t type;
+ uint8_t flags;
uint8_t tag0;
uint8_t tagN;
} EVEWidget;
+#include "widgets.h"
+
+typedef struct EVEWidgetSpec {
+ EVERect g;
+ EVEWidgetSpecT tspec;
+ uint8_t type;
+ uint8_t flags;
+} EVEWidgetSpec;
+
+typedef int (*eve_widget_create_t) (EVEWidget *, EVEWidgetSpec *, EVEPage *);
+typedef void (*eve_widget_destroy_t) (EVEWidget *);
+
+int eve_widget_create(EVEWidget *widget, EVEWidgetSpec *spec, EVEPage *page);
+void eve_widget_destroy(EVEWidget *widget);
+
void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, eve_widget_draw_t draw, eve_widget_touch_t touch, eve_kbd_input_handler_t putc);
size_t eve_widget_size(uint8_t type);
void eve_widget_set_label(EVEWidget *widget, EVELabel *label);
EVEWidget *eve_widget_next(EVEWidget *widget);
-void eve_widget_focus(EVEWidget *widget, EVERect *rect); \ No newline at end of file
+
+void eve_widget_set_focus(EVEWidget *widget, EVERect *rect);
+void eve_widget_set_flags(EVEWidget *widget, uint8_t flags);
+void eve_widget_clr_flags(EVEWidget *widget, uint8_t flags); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/widgets.c b/fw/fe310/eos/eve/widget/widgets.c
new file mode 100644
index 0000000..ec422c1
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/widgets.c
@@ -0,0 +1,43 @@
+#include <stdlib.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+#include "eve_font.h"
+
+#include "screen/window.h"
+#include "screen/page.h"
+
+#include "widget.h"
+
+const size_t _eve_widget_size[] = {
+ 0,
+ sizeof(EVEFreeWidget),
+ sizeof(EVEWidget),
+ sizeof(EVEPageWidget),
+ sizeof(EVEToggleWidget),
+ sizeof(EVEStrWidget),
+ sizeof(EVETextWidget),
+ sizeof(EVESelectWidget),
+};
+
+const eve_widget_create_t _eve_widget_create[] = {
+ NULL,
+ eve_freew_create,
+ eve_spacerw_create,
+ eve_pagew_create,
+ eve_togglew_create,
+ eve_strw_create,
+ eve_textw_create,
+ eve_selectw_create,
+};
+
+const eve_widget_destroy_t _eve_widget_destroy[] = {
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ eve_strw_destroy,
+ eve_textw_destroy,
+ eve_selectw_destroy,
+};
diff --git a/fw/fe310/eos/eve/widget/widgets.h b/fw/fe310/eos/eve/widget/widgets.h
index 2f8d3ca..9c96d8c 100644
--- a/fw/fe310/eos/eve/widget/widgets.h
+++ b/fw/fe310/eos/eve/widget/widgets.h
@@ -1,39 +1,24 @@
-#include "label.h"
-#include "widget.h"
-
#include "freew.h"
#include "spacerw.h"
#include "pagew.h"
#include "strw.h"
#include "textw.h"
#include "selectw.h"
+#include "togglew.h"
+
+#define EVE_WIDGET_TYPE_FREE 1
+#define EVE_WIDGET_TYPE_SPACER 2
+#define EVE_WIDGET_TYPE_PAGE 3
+#define EVE_WIDGET_TYPE_TOGGLE 4
+#define EVE_WIDGET_TYPE_STR 5
+#define EVE_WIDGET_TYPE_TEXT 6
+#define EVE_WIDGET_TYPE_SELECT 7
typedef union EVEWidgetSpecT {
EVEFreeSpec free;
- EVESpacerSpec spacer;
EVEPageSpec page;
+ EVEToggleSpec toggle;
EVEStrSpec str;
EVETextSpec text;
EVESelectSpec select;
} EVEWidgetSpecT;
-
-typedef struct EVELabelSpec {
- EVERect g;
- EVEFont *font;
- char *title;
-} APPLabelSpec;
-
-typedef struct EVEWidgetSpec {
- APPLabelSpec label;
- struct {
- EVERect g;
- EVEWidgetSpecT spec;
- uint8_t type;
- } widget;
-} EVEWidgetSpec;
-
-typedef int (*eve_widget_create_t) (EVEWidget *, EVERect *, EVEPage *, EVEWidgetSpecT *);
-typedef void (*eve_widget_destroy_t) (EVEWidget *);
-
-int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, EVEWidgetSpecT *spec);
-void eve_widget_destroy(EVEWidget *widget);