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/Makefile4
-rw-r--r--fw/fe310/eos/eve/widget/font.c61
-rw-r--r--fw/fe310/eos/eve/widget/font.h14
-rw-r--r--fw/fe310/eos/eve/widget/freew.c61
-rw-r--r--fw/fe310/eos/eve/widget/freew.h27
-rw-r--r--fw/fe310/eos/eve/widget/label.c4
-rw-r--r--fw/fe310/eos/eve/widget/label.h2
-rw-r--r--fw/fe310/eos/eve/widget/pagew.c29
-rw-r--r--fw/fe310/eos/eve/widget/pagew.h13
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.c36
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.h14
-rw-r--r--fw/fe310/eos/eve/widget/strw.c47
-rw-r--r--fw/fe310/eos/eve/widget/strw.h9
-rw-r--r--fw/fe310/eos/eve/widget/textw.c75
-rw-r--r--fw/fe310/eos/eve/widget/textw.h12
-rw-r--r--fw/fe310/eos/eve/widget/widget.c45
-rw-r--r--fw/fe310/eos/eve/widget/widget.h9
-rw-r--r--fw/fe310/eos/eve/widget/widgets.h23
18 files changed, 426 insertions, 59 deletions
diff --git a/fw/fe310/eos/eve/widget/Makefile b/fw/fe310/eos/eve/widget/Makefile
index 160db72..720029e 100644
--- a/fw/fe310/eos/eve/widget/Makefile
+++ b/fw/fe310/eos/eve/widget/Makefile
@@ -2,7 +2,7 @@ include ../../../common.mk
CFLAGS += -I.. -I../..
-obj = clipb.o label.o widget.o pagew.o strw.o textw.o
+obj = clipb.o font.o label.o widget.o freew.o spacerw.o pagew.o strw.o textw.o
%.o: %.c %.h
@@ -14,4 +14,4 @@ obj = clipb.o label.o widget.o pagew.o strw.o textw.o
all: $(obj)
clean:
- rm -f *.o \ No newline at end of file
+ rm -f *.o
diff --git a/fw/fe310/eos/eve/widget/font.c b/fw/fe310/eos/eve/widget/font.c
new file mode 100644
index 0000000..da02983
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/font.c
@@ -0,0 +1,61 @@
+#include <stdlib.h>
+
+#include "eve.h"
+#include "unicode.h"
+
+#include "font.h"
+
+void eve_font_init(EVEFont *font, uint8_t font_id) {
+ uint32_t p;
+
+ p = eve_read32(EVE_ROM_FONT_ADDR);
+ p += (148 * (font_id - 16));
+ font->id = font_id;
+ font->w = eve_read32(p + 136);
+ font->h = eve_read32(p + 140);
+ eve_readb(p, font->w_ch, 128);
+}
+
+uint8_t eve_font_ch_w(EVEFont *font, utf32_t ch) {
+ if (ch < 128) return font->w_ch[ch];
+ return 0;
+}
+
+uint16_t eve_font_str_w(EVEFont *font, utf8_t *str) {
+ uint16_t r = 0;
+ utf32_t ch;
+ uint8_t ch_w;
+ uint8_t ch_l;
+
+ if (str == NULL) return 0;
+
+ while (*str) {
+ ch_l = utf8_dec(str, &ch);
+ ch_w = eve_font_ch_w(font, ch);
+ r += ch_w;
+ str += ch_l;
+ }
+
+ return r;
+}
+
+uint16_t eve_font_buf_w(EVEFont *font, utf8_t *buf, uint16_t buf_len) {
+ int i = 0;
+ uint16_t r = 0;
+ utf32_t ch;
+ uint8_t ch_w;
+ uint8_t ch_l;
+
+ while (i < buf_len) {
+ ch_l = utf8_dec(buf + i, &ch);
+ ch_w = eve_font_ch_w(font, ch);
+ r += ch_w;
+ i += ch_l;
+ }
+
+ return r;
+}
+
+uint8_t eve_font_h(EVEFont *font) {
+ return font->h;
+} \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/font.h b/fw/fe310/eos/eve/widget/font.h
new file mode 100644
index 0000000..aff038c
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/font.h
@@ -0,0 +1,14 @@
+#include <stdint.h>
+
+typedef struct EVEFont {
+ uint8_t id;
+ uint8_t w;
+ uint8_t h;
+ uint8_t w_ch[128];
+} EVEFont;
+
+void eve_font_init(EVEFont *font, uint8_t font_id);
+uint8_t eve_font_ch_w(EVEFont *font, utf32_t ch);
+uint16_t eve_font_str_w(EVEFont *font, utf8_t *str);
+uint16_t eve_font_buf_w(EVEFont *font, utf8_t *buf, uint16_t buf_len);
+uint8_t eve_font_h(EVEFont *font);
diff --git a/fw/fe310/eos/eve/widget/freew.c b/fw/fe310/eos/eve/widget/freew.c
new file mode 100644
index 0000000..55f91cb
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/freew.c
@@ -0,0 +1,61 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+#include "unicode.h"
+
+#include "screen/screen.h"
+#include "screen/window.h"
+#include "screen/page.h"
+
+#include "font.h"
+#include "label.h"
+#include "widget.h"
+#include "freew.h"
+
+int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEFreeSpec *spec) {
+ eve_freew_init(widget, g, spec->touch, spec->draw, spec->putc);
+
+ return EVE_OK;
+}
+
+void eve_freew_init(EVEFreeWidget *widget, EVERect *g, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc) {
+ EVEWidget *_widget = &widget->w;
+
+ memset(widget, 0, sizeof(EVEFreeWidget));
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_FREE, g, eve_freew_touch, eve_freew_draw, putc);
+ eve_freew_update(widget, touch, draw, NULL);
+}
+
+void eve_freew_update(EVEFreeWidget *widget, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc) {
+ if (touch) widget->_touch = touch;
+ if (draw) widget->_draw = draw;
+ if (putc) widget->w.putc = putc;
+}
+
+int eve_freew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) {
+ EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
+ EVETouch *t;
+ uint16_t evt;
+ int ret = 0;
+
+ if (touch_idx > 0) return 0;
+
+ t = eve_touch_evt(tag0, touch_idx, widget->tag0, widget->tagN - widget->tag0, &evt);
+ if (t && evt) {
+ ret = widget->_touch(widget, page, t, evt, tag0, touch_idx);
+ if (!ret && page && page->handle_evt) ret = page->handle_evt(page, _widget, t, evt, tag0, touch_idx);
+ }
+
+ return ret;
+}
+
+uint8_t eve_freew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
+ EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
+
+ widget->tag0 = tag0;
+ widget->tagN = widget->_draw(widget, page, tag0);
+
+ return widget->tagN;
+}
diff --git a/fw/fe310/eos/eve/widget/freew.h b/fw/fe310/eos/eve/widget/freew.h
new file mode 100644
index 0000000..49f896f
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/freew.h
@@ -0,0 +1,27 @@
+#include <stdint.h>
+
+struct EVEFreeWidget;
+
+typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVEPage *, EVETouch *, uint16_t, uint8_t, int);
+typedef uint8_t (*eve_freew_draw_t) (struct EVEFreeWidget *, EVEPage *, uint8_t);
+
+typedef struct EVEFreeWidget {
+ EVEWidget w;
+ eve_freew_touch_t _touch;
+ eve_freew_draw_t _draw;
+ uint8_t tag0;
+ uint8_t tagN;
+} EVEFreeWidget;
+
+typedef struct EVEFreeSpec {
+ eve_freew_touch_t touch;
+ eve_freew_draw_t draw;
+ eve_kbd_input_handler_t putc;
+} EVEFreeSpec;
+
+int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEFreeSpec *spec);
+void eve_freew_init(EVEFreeWidget *widget, EVERect *g, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc);
+void eve_freew_update(EVEFreeWidget *widget, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc);
+
+int eve_freew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
+uint8_t eve_freew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/label.c b/fw/fe310/eos/eve/widget/label.c
index ebea823..b4af37f 100644
--- a/fw/fe310/eos/eve/widget/label.c
+++ b/fw/fe310/eos/eve/widget/label.c
@@ -8,15 +8,15 @@
#include "screen/screen.h"
#include "screen/window.h"
#include "screen/page.h"
-#include "screen/font.h"
+#include "font.h"
#include "label.h"
void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title) {
memset(label, 0, sizeof(EVELabel));
if (g) label->g = *g;
- label->title = title;
label->font = font;
+ label->title = title;
if (label->g.w == 0) label->g.w = eve_font_str_w(font, label->title);
if (label->g.h == 0) label->g.h = eve_font_h(font);
}
diff --git a/fw/fe310/eos/eve/widget/label.h b/fw/fe310/eos/eve/widget/label.h
index ec96844..659c057 100644
--- a/fw/fe310/eos/eve/widget/label.h
+++ b/fw/fe310/eos/eve/widget/label.h
@@ -2,8 +2,8 @@
typedef struct EVELabel {
EVERect g;
- char *title;
EVEFont *font;
+ char *title;
} EVELabel;
void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title);
diff --git a/fw/fe310/eos/eve/widget/pagew.c b/fw/fe310/eos/eve/widget/pagew.c
index c64c477..b3e71a6 100644
--- a/fw/fe310/eos/eve/widget/pagew.c
+++ b/fw/fe310/eos/eve/widget/pagew.c
@@ -8,20 +8,32 @@
#include "screen/screen.h"
#include "screen/window.h"
#include "screen/page.h"
-#include "screen/font.h"
+#include "font.h"
#include "label.h"
#include "widget.h"
#include "pagew.h"
-void eve_pagew_init(EVEPageWidget *widget, EVERect *g, char *title, EVEFont *font, EVEPage *page) {
+int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPageSpec *spec) {
+ eve_pagew_init(widget, g, spec->font, spec->title, spec->constructor);
+
+ return EVE_OK;
+}
+
+void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEFont *font, char *title, eve_page_constructor_t constructor) {
EVEWidget *_widget = &widget->w;
memset(widget, 0, sizeof(EVEPageWidget));
eve_widget_init(_widget, EVE_WIDGET_TYPE_PAGE, g, eve_pagew_touch, eve_pagew_draw, NULL);
- widget->title = title;
- widget->font = font;
- widget->page = page;
+ eve_pagew_update(widget, font, title, constructor);
+}
+
+void eve_pagew_update(EVEPageWidget *widget, EVEFont *font, char *title, eve_page_constructor_t constructor) {
+ EVEWidget *_widget = &widget->w;
+
+ if (font) widget->font = font;
+ if (title) widget->title = title;
+ if (constructor) widget->constructor = constructor;
if (_widget->g.w == 0) _widget->g.w = eve_font_str_w(font, widget->title);
if (_widget->g.h == 0) _widget->g.h = eve_font_h(font);
}
@@ -37,12 +49,13 @@ int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i
t = eve_touch_evt(tag0, touch_idx, widget->tag, 1, &evt);
if (t && evt) {
if (evt & EVE_TOUCH_ETYPE_TRACK_MASK) {
- if (page && page->handle_evt) page->handle_evt(page, _widget, t, evt, tag0, touch_idx);
+ if (page->handle_evt) ret = page->handle_evt(page, _widget, t, evt, tag0, touch_idx);
} else if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
- widget->page->open(widget->page, page);
+ eve_page_open(page, widget->constructor);
+ ret = 1;
}
- ret = 1;
}
+
return ret;
}
diff --git a/fw/fe310/eos/eve/widget/pagew.h b/fw/fe310/eos/eve/widget/pagew.h
index 1f9ae18..797f1c3 100644
--- a/fw/fe310/eos/eve/widget/pagew.h
+++ b/fw/fe310/eos/eve/widget/pagew.h
@@ -4,10 +4,19 @@ typedef struct EVEPageWidget {
EVEWidget w;
char *title;
EVEFont *font;
- EVEPage *page;
+ eve_page_constructor_t constructor;
uint8_t tag;
} EVEPageWidget;
-void eve_pagew_init(EVEPageWidget *widget, EVERect *g, char *title, EVEFont *font, EVEPage *page);
+typedef struct EVEPageSpec {
+ EVEFont *font;
+ char *title;
+ eve_page_constructor_t constructor;
+} EVEPageSpec;
+
+int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPageSpec *spec);
+void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEFont *font, char *title, eve_page_constructor_t constructor);
+void eve_pagew_update(EVEPageWidget *widget, EVEFont *font, char *title, eve_page_constructor_t constructor);
+
int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
diff --git a/fw/fe310/eos/eve/widget/spacerw.c b/fw/fe310/eos/eve/widget/spacerw.c
new file mode 100644
index 0000000..23aec14
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/spacerw.c
@@ -0,0 +1,36 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+#include "unicode.h"
+
+#include "screen/screen.h"
+#include "screen/window.h"
+#include "screen/page.h"
+
+#include "font.h"
+#include "label.h"
+#include "widget.h"
+#include "spacerw.h"
+
+int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVESpacerSpec *spec) {
+ eve_spacerw_init(widget, g);
+
+ return EVE_OK;
+}
+
+void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g) {
+ EVEWidget *_widget = &widget->w;
+
+ memset(widget, 0, sizeof(EVESpacerWidget));
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_SPACER, g, eve_spacerw_touch, eve_spacerw_draw, NULL);
+}
+
+int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) {
+ return 0;
+}
+
+uint8_t eve_spacerw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
+ return tag0;
+}
diff --git a/fw/fe310/eos/eve/widget/spacerw.h b/fw/fe310/eos/eve/widget/spacerw.h
new file mode 100644
index 0000000..cbde4e8
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/spacerw.h
@@ -0,0 +1,14 @@
+#include <stdint.h>
+
+typedef struct EVESpacerWidget {
+ EVEWidget w;
+} EVESpacerWidget;
+
+typedef struct EVESpacerSpec {
+} EVESpacerSpec;
+
+int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVESpacerSpec *spec);
+void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g);
+
+int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
+uint8_t eve_spacerw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
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);
}
diff --git a/fw/fe310/eos/eve/widget/strw.h b/fw/fe310/eos/eve/widget/strw.h
index 72fc6aa..9456603 100644
--- a/fw/fe310/eos/eve/widget/strw.h
+++ b/fw/fe310/eos/eve/widget/strw.h
@@ -27,7 +27,16 @@ typedef struct EVEStrWidget {
} track;
} EVEStrWidget;
+typedef struct EVEStrSpec {
+ EVEFont *font;
+ uint16_t str_size;
+} EVEStrSpec;
+
+int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEStrSpec *spec);
+void eve_strw_destroy(EVEStrWidget *widget);
void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEFont *font, utf8_t *str, uint16_t str_size);
+void eve_strw_update(EVEStrWidget *widget, EVEFont *font, utf8_t *str, uint16_t str_size);
+
int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
void eve_strw_putc(void *_page, int c);
diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c
index bf075cf..5835a57 100644
--- a/fw/fe310/eos/eve/widget/textw.c
+++ b/fw/fe310/eos/eve/widget/textw.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 "textw.h"
@@ -35,25 +35,59 @@
#define DIVC(x,y) ((x) / (y) + ((x) % (y) != 0))
+int eve_textw_create(EVETextWidget *widget, EVERect *g, EVETextSpec *spec) {
+ 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, spec->font, text, spec->text_size, line, spec->line_size);
+
+ return EVE_OK;
+}
+
+void eve_textw_destroy(EVETextWidget *widget) {
+ eve_free(widget->line);
+ eve_free(widget->text);
+}
+
void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size) {
- int rv, text_len;
EVEWidget *_widget = &widget->w;
memset(widget, 0, sizeof(EVETextWidget));
eve_widget_init(_widget, EVE_WIDGET_TYPE_TEXT, g, eve_textw_touch, eve_textw_draw, eve_textw_putc);
- widget->font = font;
- widget->text = text;
- widget->text_size = text_size;
- rv = utf8_verify(text, text_size, &text_len);
- if (rv != UTF_OK) {
- if (text_len >= text_size) text_len = 0;
- widget->text[text_len] = '\0';
+ eve_textw_update(widget, font, text, text_size, line, line_size);
+}
+
+void eve_textw_update(EVETextWidget *widget, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size) {
+ int rv, text_len;
+
+ if (font) widget->font = font;
+ if (text) {
+ widget->text = text;
+ widget->text_size = text_size;
+ rv = utf8_verify(text, text_size, &text_len);
+ if (rv != UTF_OK) {
+ if (text_len >= text_size) text_len = 0;
+ widget->text[text_len] = '\0';
+ }
+ widget->text_len = text_len;
+ }
+ if (line) {
+ widget->line = line;
+ widget->line_size = line_size;
}
- widget->text_len = text_len;
- widget->line = line;
- widget->line_size = line_size;
memset(widget->line, 0xff, line_size * sizeof(uint16_t));
- eve_textw_update(widget, NULL, 0);
+ eve_textw_text_update(widget, NULL, 0);
}
static void set_focus(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page) {
@@ -87,7 +121,6 @@ int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i
EVETextWidget *widget = (EVETextWidget *)_widget;
EVETouch *t;
uint16_t evt;
- int ret = 0;
if (touch_idx > 0) return 0;
@@ -121,7 +154,9 @@ int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i
break;
case TEXTW_TMODE_CURSOR:
- if (evt & EVE_TOUCH_ETYPE_TRACK) eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, eve_page_x(page, t->x) + widget->track.dx);
+ if (evt & EVE_TOUCH_ETYPE_TRACK) {
+ eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, eve_page_x(page, t->x) + widget->track.dx);
+ }
break;
default:
@@ -153,10 +188,10 @@ int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i
widget->track.dl = 0;
}
- ret = 1;
+ return 1;
}
- return ret;
+ return 0;
}
static void _draw_line(EVETextWidget *widget, EVEWindow *window, uint16_t l, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
@@ -387,8 +422,8 @@ void eve_textw_putc(void *_page, int c) {
}
r = cursor1->line;
- if (cursor1->line) r = eve_textw_update(widget, page, cursor1->line - 1);
- if ((cursor1->line == 0) || (r == cursor1->line - 1)) r = eve_textw_update(widget, page, cursor1->line);
+ if (cursor1->line) r = eve_textw_text_update(widget, page, cursor1->line - 1);
+ if ((cursor1->line == 0) || (r == cursor1->line - 1)) r = eve_textw_text_update(widget, page, cursor1->line);
if (cursor1->line && (cursor1->ch < LINE_START(widget, cursor1->line))) {
cursor1->line--;
@@ -403,7 +438,7 @@ void eve_textw_putc(void *_page, int c) {
}
}
-uint16_t eve_textw_update(EVETextWidget *widget, EVEPage *page, uint16_t line) {
+uint16_t eve_textw_text_update(EVETextWidget *widget, EVEPage *page, uint16_t line) {
int i;
utf32_t ch;
uint8_t ch_w;
diff --git a/fw/fe310/eos/eve/widget/textw.h b/fw/fe310/eos/eve/widget/textw.h
index cd46ea3..36ab466 100644
--- a/fw/fe310/eos/eve/widget/textw.h
+++ b/fw/fe310/eos/eve/widget/textw.h
@@ -29,11 +29,21 @@ typedef struct EVETextWidget {
} track;
} EVETextWidget;
+typedef struct EVETextSpec {
+ EVEFont *font;
+ uint16_t text_size;
+ uint16_t line_size;
+} EVETextSpec;
+
+int eve_textw_create(EVETextWidget *widget, EVERect *g, EVETextSpec *spec);
+void eve_textw_destroy(EVETextWidget *widget);
void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size);
+void eve_textw_update(EVETextWidget *widget, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size);
+
int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
void eve_textw_putc(void *_w, int c);
-uint16_t eve_textw_update(EVETextWidget *widget, EVEPage *page, uint16_t line);
+uint16_t eve_textw_text_update(EVETextWidget *widget, EVEPage *page, uint16_t line);
void eve_textw_cursor_update(EVETextWidget *widget, EVETextCursor *cursor);
void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t tag, int16_t x);
void eve_textw_cursor_clear(EVETextWidget *widget, EVETextCursor *cursor);
diff --git a/fw/fe310/eos/eve/widget/widget.c b/fw/fe310/eos/eve/widget/widget.c
index ab121d8..7c1fcad 100644
--- a/fw/fe310/eos/eve/widget/widget.c
+++ b/fw/fe310/eos/eve/widget/widget.c
@@ -8,19 +8,34 @@
#include "screen/screen.h"
#include "screen/window.h"
#include "screen/page.h"
-#include "screen/font.h"
-#include "label.h"
-#include "widget.h"
-#include "pagew.h"
-#include "strw.h"
-#include "textw.h"
+#include "widgets.h"
-static const size_t _eve_wsize[] = {
+static const size_t _widget_size[] = {
0,
+ sizeof(EVEFreeWidget),
+ sizeof(EVESpacerWidget),
sizeof(EVEPageWidget),
sizeof(EVEStrWidget),
- sizeof(EVETextWidget)
+ sizeof(EVETextWidget),
+};
+
+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,
+};
+
+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,
};
void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, eve_widget_touch_t touch, eve_widget_draw_t draw, eve_kbd_input_handler_t putc) {
@@ -31,11 +46,23 @@ void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, eve_widget_tou
widget->type = type;
}
+size_t eve_widget_size(uint8_t type) {
+ return _widget_size[type];
+}
+
void eve_widget_set_label(EVEWidget *widget, EVELabel *label) {
widget->label = label;
}
EVEWidget *eve_widget_next(EVEWidget *widget) {
char *_w = (char *)widget;
- return (EVEWidget *)(_w + _eve_wsize[widget->type]);
+ return (EVEWidget *)(_w + _widget_size[widget->type]);
+}
+
+int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEWidgetSpec *spec) {
+ return _widget_create[type](widget, g, spec);
}
+
+void eve_widget_destroy(EVEWidget *widget) {
+ if (_widget_destroy[widget->type]) _widget_destroy[widget->type](widget);
+} \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/widget.h b/fw/fe310/eos/eve/widget/widget.h
index 1aa2cd7..cff5c1d 100644
--- a/fw/fe310/eos/eve/widget/widget.h
+++ b/fw/fe310/eos/eve/widget/widget.h
@@ -1,8 +1,10 @@
#include <stdint.h>
-#define EVE_WIDGET_TYPE_PAGE 1
-#define EVE_WIDGET_TYPE_STR 2
-#define EVE_WIDGET_TYPE_TEXT 3
+#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
struct EVEWidget;
@@ -19,5 +21,6 @@ typedef struct EVEWidget {
} EVEWidget;
void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, eve_widget_touch_t touch, eve_widget_draw_t draw, 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);
diff --git a/fw/fe310/eos/eve/widget/widgets.h b/fw/fe310/eos/eve/widget/widgets.h
new file mode 100644
index 0000000..4206894
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/widgets.h
@@ -0,0 +1,23 @@
+#include "font.h"
+#include "label.h"
+#include "widget.h"
+
+#include "freew.h"
+#include "spacerw.h"
+#include "pagew.h"
+#include "strw.h"
+#include "textw.h"
+
+typedef union EVEWidgetSpec {
+ EVEFreeSpec free;
+ EVESpacerSpec spacer;
+ EVEPageSpec page;
+ EVEStrSpec str;
+ EVETextSpec text;
+} EVEWidgetSpec;
+
+typedef int (*eve_widget_create_t) (EVEWidget *, EVERect *g, EVEWidgetSpec *);
+typedef void (*eve_widget_destroy_t) (EVEWidget *);
+
+int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEWidgetSpec *spec);
+void eve_widget_destroy(EVEWidget *widget);