summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-03-25 19:58:43 +0100
committerUros Majstorovic <majstor@majstor.org>2021-03-25 19:58:43 +0100
commit58232586e1ed65fc8a8e382796628aa087b5dc4c (patch)
treea2a174228ad0b217369820750a6c1d4f087d8d7b /fw/fe310/eos/eve
parent95f69d4f83ad8f7fbb56349f29e902928510362b (diff)
uievt added to view
Diffstat (limited to 'fw/fe310/eos/eve')
-rw-r--r--fw/fe310/eos/eve/eve_font.c4
-rw-r--r--fw/fe310/eos/eve/eve_font.h2
-rw-r--r--fw/fe310/eos/eve/screen/form.c22
-rw-r--r--fw/fe310/eos/eve/screen/form.h5
-rw-r--r--fw/fe310/eos/eve/screen/page.c17
-rw-r--r--fw/fe310/eos/eve/screen/page.h6
-rw-r--r--fw/fe310/eos/eve/screen/view.c10
-rw-r--r--fw/fe310/eos/eve/screen/view.h12
-rw-r--r--fw/fe310/eos/eve/screen/window.c12
-rw-r--r--fw/fe310/eos/eve/screen/window.h4
-rw-r--r--fw/fe310/eos/eve/widget/freew.c32
-rw-r--r--fw/fe310/eos/eve/widget/freew.h18
-rw-r--r--fw/fe310/eos/eve/widget/label.c2
-rw-r--r--fw/fe310/eos/eve/widget/pagew.c46
-rw-r--r--fw/fe310/eos/eve/widget/pagew.h12
-rw-r--r--fw/fe310/eos/eve/widget/selectw.c138
-rw-r--r--fw/fe310/eos/eve/widget/selectw.h10
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.c20
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.h8
-rw-r--r--fw/fe310/eos/eve/widget/strw.c236
-rw-r--r--fw/fe310/eos/eve/widget/strw.h10
-rw-r--r--fw/fe310/eos/eve/widget/textw.c222
-rw-r--r--fw/fe310/eos/eve/widget/textw.h12
-rw-r--r--fw/fe310/eos/eve/widget/widget.c17
-rw-r--r--fw/fe310/eos/eve/widget/widget.h12
-rw-r--r--fw/fe310/eos/eve/widget/widgets.h5
26 files changed, 490 insertions, 404 deletions
diff --git a/fw/fe310/eos/eve/eve_font.c b/fw/fe310/eos/eve/eve_font.c
index d71607c..e1e3aee 100644
--- a/fw/fe310/eos/eve/eve_font.c
+++ b/fw/fe310/eos/eve/eve_font.c
@@ -1,7 +1,5 @@
#include <stdlib.h>
-#include "unicode.h"
-
#include "eve.h"
#include "eve_font.h"
@@ -58,4 +56,4 @@ uint16_t eve_font_buf_w(EVEFont *font, utf8_t *buf, uint16_t buf_len) {
uint8_t eve_font_h(EVEFont *font) {
return font->h;
-} \ No newline at end of file
+}
diff --git a/fw/fe310/eos/eve/eve_font.h b/fw/fe310/eos/eve/eve_font.h
index aff038c..87ef41f 100644
--- a/fw/fe310/eos/eve/eve_font.h
+++ b/fw/fe310/eos/eve/eve_font.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+#include "unicode.h"
+
typedef struct EVEFont {
uint8_t id;
uint8_t w;
diff --git a/fw/fe310/eos/eve/screen/form.c b/fw/fe310/eos/eve/screen/form.c
index d3707fc..8ea53c8 100644
--- a/fw/fe310/eos/eve/screen/form.c
+++ b/fw/fe310/eos/eve/screen/form.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"
@@ -45,6 +43,7 @@ static void form_update_g(EVEForm *form, EVEWidget *_widget) {
widget = eve_widget_next(widget);
}
+ form->w = form->p.v.window->g.w;
form->h = h + l_h;
}
@@ -121,13 +120,18 @@ static int form_handle_evt(EVEForm *form, EVEWidget *widget, EVETouch *touch, ui
return ret;
}
-int eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_form_action_t action, eve_form_destructor_t destructor) {
+void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_form_action_t action, eve_form_destructor_t destructor) {
memset(form, 0, sizeof(EVEForm));
- eve_page_init(&form->p, window, stack, eve_form_draw, eve_form_touch, (eve_page_destructor_t)destructor);
+ eve_page_init(&form->p, window, stack, eve_form_draw, eve_form_touch, NULL, (eve_page_destructor_t)destructor);
+ eve_form_update(form, widget, widget_size, action);
+}
- form->widget = widget;
- form->widget_size = widget_size;
- form->action = action;
+void eve_form_update(EVEForm *form, EVEWidget *widget, uint16_t widget_size, eve_form_action_t action) {
+ if (widget) {
+ form->widget = widget;
+ form->widget_size = widget_size;
+ }
+ if (action) form->action = action;
form_update_g(form, NULL);
}
@@ -152,7 +156,7 @@ uint8_t eve_form_draw(EVEView *view, uint8_t tag0) {
}
if (eve_page_rect_visible(&form->p, &widget->g)) {
uint16_t h = widget->g.h;
- tagN = widget->draw(widget, &form->p, tagN);
+ tagN = widget->draw(widget, tagN);
if (h != widget->g.h) form_update_g(form, widget);
}
widget = eve_widget_next(widget);
@@ -186,7 +190,7 @@ int eve_form_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) {
_evt = eve_touch_evt(touch, evt, tag0, widget->tag0, widget->tagN - widget->tag0);
if (_evt) {
if (!form->evt_lock) {
- ret = widget->touch(widget, &form->p, touch, _evt);
+ ret = widget->touch(widget, touch, _evt);
if (ret) return 1;
}
ret = form_handle_evt(form, widget, touch, _evt, tag0);
diff --git a/fw/fe310/eos/eve/screen/form.h b/fw/fe310/eos/eve/screen/form.h
index 96c5930..eb817e5 100644
--- a/fw/fe310/eos/eve/screen/form.h
+++ b/fw/fe310/eos/eve/screen/form.h
@@ -20,10 +20,11 @@ typedef struct EVEForm {
uint64_t lho_t0;
} EVEForm;
-int eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, eve_form_action_t action, eve_form_destructor_t destructor);
+void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, eve_form_action_t action, eve_form_destructor_t destructor);
+void eve_form_update(EVEForm *form, struct EVEWidget *widget, uint16_t widget_size, eve_form_action_t action);
-int eve_form_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0);
uint8_t eve_form_draw(EVEView *view, uint8_t tag0);
+int eve_form_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0);
void eve_form_update_g(EVEForm *form, struct EVEWidget *widget);
int eve_form_handle_evt(EVEForm *form, struct EVEWidget *widget, EVETouch *touch, uint16_t evt);
diff --git a/fw/fe310/eos/eve/screen/page.c b/fw/fe310/eos/eve/screen/page.c
index 0951b1b..4b8799c 100644
--- a/fw/fe310/eos/eve/screen/page.c
+++ b/fw/fe310/eos/eve/screen/page.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"
@@ -13,11 +11,9 @@
#include "widget/label.h"
#include "widget/widget.h"
-#define CH_EOF 0x1a
-
-void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, eve_view_draw_t draw, eve_view_touch_t touch, eve_page_destructor_t destructor) {
+void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, eve_page_destructor_t destructor) {
memset(page, 0, sizeof(EVEPage));
- eve_view_init(&page->v, window, draw, touch, NULL);
+ eve_view_init(&page->v, window, draw, touch, uievt, NULL);
page->destructor = destructor;
page->stack = stack;
page->widget_f = NULL;
@@ -67,13 +63,13 @@ void eve_page_set_focus(EVEPage *page, EVEWidget *widget, EVERect *f) {
if (widget_f && widget_f->putc) {
eve_window_kbd_detach(window);
- widget_f->putc(page, CH_EOF);
+ widget_f->putc(widget_f, EVE_PAGE_KBDCH_CLOSE);
}
if (widget && widget->putc) {
EVEKbd *kbd = eve_window_kbd(window);
if (kbd) {
- eve_kbd_set_handler(kbd, widget->putc, page);
+ eve_kbd_set_handler(kbd, widget->putc, widget);
eve_window_kbd_attach(window);
}
}
@@ -113,3 +109,8 @@ int eve_page_rect_visible(EVEPage *page, EVERect *g) {
if (((g->x + g->w) >= page->win_x) && ((g->y + g->h) >= page->win_y) && (g->x <= (page->win_x + w)) && (g->y <= (page->win_y + h))) return 1;
return 0;
}
+
+void eve_page_uievt_push(EVEPage *page, uint16_t evt, void *param) {
+ EVEView *view = &page->v;
+ eve_view_uievt_push(view, evt, param ? param : page);
+}
diff --git a/fw/fe310/eos/eve/screen/page.h b/fw/fe310/eos/eve/screen/page.h
index cf6b8be..ded7185 100644
--- a/fw/fe310/eos/eve/screen/page.h
+++ b/fw/fe310/eos/eve/screen/page.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+#define EVE_PAGE_KBDCH_CLOSE 0x1a
+
struct EVEWidget;
struct EVEPage;
@@ -14,7 +16,7 @@ typedef struct EVEPage {
struct EVEWidget *widget_f;
} EVEPage;
-void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, eve_view_draw_t draw, eve_view_touch_t touch, eve_page_destructor_t destructor);
+void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, eve_page_destructor_t destructor);
void eve_page_open(EVEPage *parent, eve_view_constructor_t constructor);
void eve_page_close(EVEPage *page);
@@ -26,3 +28,5 @@ int16_t eve_page_scr_y(EVEPage *page, int16_t y);
void eve_page_set_focus(EVEPage *page, struct EVEWidget *widget, EVERect *focus);
struct EVEWidget *eve_page_get_focus(EVEPage *page);
int eve_page_rect_visible(EVEPage *page, EVERect *g);
+
+void eve_page_uievt_push(EVEPage *page, uint16_t evt, void *param); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/screen/view.c b/fw/fe310/eos/eve/screen/view.c
index ce4101f..3f93c2f 100644
--- a/fw/fe310/eos/eve/screen/view.c
+++ b/fw/fe310/eos/eve/screen/view.c
@@ -3,12 +3,14 @@
#include "eve.h"
#include "eve_kbd.h"
+#include "eve_font.h"
#include "window.h"
-void eve_view_init(EVEView *view, EVEWindow *window, eve_view_draw_t draw, eve_view_touch_t touch, void *param) {
- view->touch = touch;
+void eve_view_init(EVEView *view, EVEWindow *window, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, void *param) {
view->draw = draw;
+ view->touch = touch;
+ view->uievt = uievt;
view->param = param;
view->window = window;
view->color_bg = 0x000000;
@@ -57,3 +59,7 @@ void eve_view_destroy(EVEWindow *window, EVEViewStack *stack) {
constructor(window, stack);
}
}
+
+void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param) {
+ if (view->uievt) view->uievt(view, evt, param);
+} \ No newline at end of file
diff --git a/fw/fe310/eos/eve/screen/view.h b/fw/fe310/eos/eve/screen/view.h
index f0e2eb0..527282b 100644
--- a/fw/fe310/eos/eve/screen/view.h
+++ b/fw/fe310/eos/eve/screen/view.h
@@ -1,6 +1,8 @@
#include <stdint.h>
-#define EVE_VIEW_SIZE_STACK 16
+#include "uievt.h"
+
+#define EVE_VIEW_SIZE_STACK 16
struct EVEView;
struct EVEViewStack;
@@ -8,11 +10,13 @@ struct EVEWindow;
typedef uint8_t (*eve_view_draw_t) (struct EVEView *, uint8_t);
typedef int (*eve_view_touch_t) (struct EVEView *, EVETouch *, uint16_t, uint8_t);
+typedef void (*eve_view_uievt_t) (struct EVEView *, uint16_t, void *);
typedef void (*eve_view_constructor_t) (struct EVEWindow *window, struct EVEViewStack *);
typedef struct EVEView {
eve_view_draw_t draw;
eve_view_touch_t touch;
+ eve_view_uievt_t uievt;
struct EVEWindow *window;
void *param;
uint32_t color_bg;
@@ -25,11 +29,13 @@ typedef struct EVEViewStack {
uint8_t level;
} EVEViewStack;
-void eve_view_init(EVEView *view, struct EVEWindow *window, eve_view_draw_t draw, eve_view_touch_t touch, void *param);
+void eve_view_init(EVEView *view, struct EVEWindow *window, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, void *param);
void eve_view_set_color_bg(EVEView *view, uint8_t r, uint8_t g, uint8_t b);
void eve_view_set_color_fg(EVEView *view, uint8_t r, uint8_t g, uint8_t b);
uint8_t eve_view_clear(EVEView *view, uint8_t tag0);
void eve_view_stack_init(EVEViewStack *stack);
void eve_view_create(struct EVEWindow *window, EVEViewStack *stack, eve_view_constructor_t constructor);
-void eve_view_destroy(struct EVEWindow *window, EVEViewStack *stack); \ No newline at end of file
+void eve_view_destroy(struct EVEWindow *window, EVEViewStack *stack);
+
+void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/screen/window.c b/fw/fe310/eos/eve/screen/window.c
index 369c134..2971ab5 100644
--- a/fw/fe310/eos/eve/screen/window.c
+++ b/fw/fe310/eos/eve/screen/window.c
@@ -3,6 +3,7 @@
#include "eve.h"
#include "eve_kbd.h"
+#include "eve_font.h"
#include "window.h"
@@ -17,12 +18,13 @@ void eve_window_init(EVEWindow *window, EVERect *g, EVEWindow *parent, char *nam
window->name = name;
}
-void eve_window_init_root(EVEWindowRoot *window, EVERect *g, char *name) {
+void eve_window_init_root(EVEWindowRoot *window, EVERect *g, char *name, EVEFont *font) {
EVEWindow *_window = &window->w;
eve_window_init(_window, g, NULL, name);
_window->root = _window;
window->mem_next = EVE_RAM_G;
+ window->font = font;
window->win_kbd = NULL;
eve_touch_set_handler(eve_window_root_touch, window);
}
@@ -49,7 +51,7 @@ void eve_window_init_kbd(EVEWindowKbd *window, EVERect *g, EVEWindowRoot *root,
_window->root = (EVEWindow *)root;
window->kbd = kbd;
root->win_kbd = window;
- eve_view_init(&window->v, _window, kbd_draw, kbd_touch, kbd);
+ eve_view_init(&window->v, _window, kbd_draw, kbd_touch, NULL, kbd);
}
void eve_window_set_parent(EVEWindow *window, EVEWindow *parent) {
@@ -264,3 +266,9 @@ void eve_window_kbd_detach(EVEWindow *window) {
eve_kbd_close(kbd);
}
}
+
+EVEFont *eve_window_font(EVEWindow *window) {
+ EVEWindowRoot *win_root = (EVEWindowRoot *)window->root;
+
+ return win_root->font;
+}
diff --git a/fw/fe310/eos/eve/screen/window.h b/fw/fe310/eos/eve/screen/window.h
index 3e082d4..76ccee9 100644
--- a/fw/fe310/eos/eve/screen/window.h
+++ b/fw/fe310/eos/eve/screen/window.h
@@ -23,11 +23,12 @@ typedef struct EVEWindowKbd {
typedef struct EVEWindowRoot {
EVEWindow w;
uint32_t mem_next;
+ EVEFont *font;
EVEWindowKbd *win_kbd;
} EVEWindowRoot;
void eve_window_init(EVEWindow *window, EVERect *g, EVEWindow *parent, char *name);
-void eve_window_init_root(EVEWindowRoot *window, EVERect *g, char *name);
+void eve_window_init_root(EVEWindowRoot *window, EVERect *g, char *name, EVEFont *font);
void eve_window_init_kbd(EVEWindowKbd *window, EVERect *g, EVEWindowRoot *root, char *name, EVEKbd *kbd);
void eve_window_set_parent(EVEWindow *window, EVEWindow *parent);
@@ -48,3 +49,4 @@ void eve_window_root_touch(EVETouch *touch, uint16_t evt, uint8_t tag0, void *wi
EVEKbd *eve_window_kbd(EVEWindow *window);
void eve_window_kbd_attach(EVEWindow *window);
void eve_window_kbd_detach(EVEWindow *window);
+EVEFont *eve_window_font(EVEWindow *window); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/freew.c b/fw/fe310/eos/eve/widget/freew.c
index f129af0..1a55ea9 100644
--- a/fw/fe310/eos/eve/widget/freew.c
+++ b/fw/fe310/eos/eve/widget/freew.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"
@@ -14,23 +12,23 @@
#include "widget.h"
#include "freew.h"
-int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEFont *font, EVEFreeSpec *spec) {
- eve_freew_init(widget, g, font, spec->touch, spec->draw, spec->putc);
+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, EVEFont *font, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc) {
+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;
memset(widget, 0, sizeof(EVEFreeWidget));
- eve_widget_init(_widget, EVE_WIDGET_TYPE_FREE, g, font, eve_freew_touch, eve_freew_draw, putc);
- eve_freew_update(widget, touch, draw, NULL);
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_FREE, g, page, eve_freew_draw, eve_freew_touch, putc);
+ eve_freew_update(widget, draw, touch, 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;
+void eve_freew_update(EVEFreeWidget *widget, eve_freew_draw_t draw, eve_freew_touch_t touch, eve_kbd_input_handler_t putc) {
if (draw) widget->_draw = draw;
+ if (touch) widget->_touch = touch;
if (putc) widget->w.putc = putc;
}
@@ -43,18 +41,18 @@ void eve_freew_tag(EVEFreeWidget *widget) {
}
}
-int eve_freew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
- EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
-
- return widget->_touch(widget, page, t, evt);
-}
-
-uint8_t eve_freew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
+uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0) {
EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
_widget->tag0 = tag0;
_widget->tagN = tag0;
- widget->_draw(widget, page);
+ widget->_draw(widget);
return _widget->tagN;
}
+
+int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
+ EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
+
+ return widget->_touch(widget, touch, evt);
+}
diff --git a/fw/fe310/eos/eve/widget/freew.h b/fw/fe310/eos/eve/widget/freew.h
index a237e88..d6d2bf7 100644
--- a/fw/fe310/eos/eve/widget/freew.h
+++ b/fw/fe310/eos/eve/widget/freew.h
@@ -2,25 +2,25 @@
struct EVEFreeWidget;
-typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVEPage *, EVETouch *, uint16_t);
-typedef void (*eve_freew_draw_t) (struct EVEFreeWidget *, EVEPage *);
+typedef void (*eve_freew_draw_t) (struct EVEFreeWidget *);
+typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVETouch *, uint16_t);
typedef struct EVEFreeWidget {
EVEWidget w;
- eve_freew_touch_t _touch;
eve_freew_draw_t _draw;
+ eve_freew_touch_t _touch;
} EVEFreeWidget;
typedef struct EVEFreeSpec {
- eve_freew_touch_t touch;
eve_freew_draw_t draw;
+ eve_freew_touch_t touch;
eve_kbd_input_handler_t putc;
} EVEFreeSpec;
-int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEFont *font, EVEFreeSpec *spec);
-void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEFont *font, 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_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_update(EVEFreeWidget *widget, 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_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
-uint8_t eve_freew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
+uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0);
+int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
diff --git a/fw/fe310/eos/eve/widget/label.c b/fw/fe310/eos/eve/widget/label.c
index cc05487..f2d2e8e 100644
--- a/fw/fe310/eos/eve/widget/label.c
+++ b/fw/fe310/eos/eve/widget/label.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"
diff --git a/fw/fe310/eos/eve/widget/pagew.c b/fw/fe310/eos/eve/widget/pagew.c
index 6754338..4f59d2e 100644
--- a/fw/fe310/eos/eve/widget/pagew.c
+++ b/fw/fe310/eos/eve/widget/pagew.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"
@@ -14,40 +12,32 @@
#include "widget.h"
#include "pagew.h"
-int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEFont *font, EVEPageSpec *spec) {
- eve_pagew_init(widget, g, font, spec->title, spec->constructor);
+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, EVEFont *font, char *title, eve_view_constructor_t constructor) {
+void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *title, eve_view_constructor_t constructor) {
EVEWidget *_widget = &widget->w;
memset(widget, 0, sizeof(EVEPageWidget));
- eve_widget_init(_widget, EVE_WIDGET_TYPE_PAGE, g, font, eve_pagew_touch, eve_pagew_draw, NULL);
- eve_pagew_update(widget, title, constructor);
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_PAGE, g, page, eve_pagew_draw, eve_pagew_touch, NULL);
+ eve_pagew_update(widget, font, title, constructor);
}
-void eve_pagew_update(EVEPageWidget *widget, char *title, eve_view_constructor_t constructor) {
+void eve_pagew_update(EVEPageWidget *widget, EVEFont *font, char *title, eve_view_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.h == 0) _widget->g.h = eve_font_h(_widget->font);
-}
-
-int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
- EVEPageWidget *widget = (EVEPageWidget *)_widget;
-
- if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
- eve_page_open(page, widget->constructor);
- return 1;
- }
-
- return 0;
+ if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font);
}
-uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
+uint8_t eve_pagew_draw(EVEWidget *_widget, uint8_t tag0) {
EVEPageWidget *widget = (EVEPageWidget *)_widget;
_widget->tag0 = tag0;
@@ -57,7 +47,19 @@ uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
}
_widget->tagN = tag0;
- eve_cmd(CMD_TEXT, "hhhhs", _widget->g.x, _widget->g.y, _widget->font->id, 0, widget->title);
+ eve_cmd(CMD_TEXT, "hhhhs", _widget->g.x, _widget->g.y, widget->font->id, 0, widget->title);
return _widget->tagN;
}
+
+int eve_pagew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
+ EVEPage *parent = _widget->page;
+ EVEPageWidget *widget = (EVEPageWidget *)_widget;
+
+ if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
+ eve_page_open(parent, widget->constructor);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/fw/fe310/eos/eve/widget/pagew.h b/fw/fe310/eos/eve/widget/pagew.h
index 3678d9c..ef34f48 100644
--- a/fw/fe310/eos/eve/widget/pagew.h
+++ b/fw/fe310/eos/eve/widget/pagew.h
@@ -2,8 +2,8 @@
typedef struct EVEPageWidget {
EVEWidget w;
- char *title;
EVEFont *font;
+ char *title;
eve_view_constructor_t constructor;
} EVEPageWidget;
@@ -13,9 +13,9 @@ typedef struct EVEPageSpec {
eve_view_constructor_t constructor;
} EVEPageSpec;
-int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEFont *font, EVEPageSpec *spec);
-void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEFont *font, char *title, eve_view_constructor_t constructor);
-void eve_pagew_update(EVEPageWidget *widget, char *title, eve_view_constructor_t constructor);
+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);
+void eve_pagew_update(EVEPageWidget *widget, EVEFont *font, char *title, eve_view_constructor_t constructor);
-int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
-uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
+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 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;
}
diff --git a/fw/fe310/eos/eve/widget/selectw.h b/fw/fe310/eos/eve/widget/selectw.h
index 0045228..00623c1 100644
--- a/fw/fe310/eos/eve/widget/selectw.h
+++ b/fw/fe310/eos/eve/widget/selectw.h
@@ -15,13 +15,13 @@ typedef struct EVESelectSpec {
uint8_t multi;
} EVESelectSpec;
-int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEFont *font, EVESelectSpec *spec);
+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_update(EVESelectWidget *widget, EVEFont *font, utf8_t *option, uint16_t option_size);
void eve_selectw_destroy(EVESelectWidget *widget);
-void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi);
-void eve_selectw_update(EVESelectWidget *widget, utf8_t *option, uint16_t option_size);
-int eve_selectw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
-uint8_t eve_selectw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
+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);
diff --git a/fw/fe310/eos/eve/widget/spacerw.c b/fw/fe310/eos/eve/widget/spacerw.c
index 992ab5b..d9f9104 100644
--- a/fw/fe310/eos/eve/widget/spacerw.c
+++ b/fw/fe310/eos/eve/widget/spacerw.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"
@@ -14,25 +12,25 @@
#include "widget.h"
#include "spacerw.h"
-int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEFont *font, EVESpacerSpec *spec) {
- eve_spacerw_init(widget, g);
+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(EVESpacerWidget *widget, EVERect *g) {
+void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g, EVEPage *page) {
EVEWidget *_widget = &widget->w;
memset(widget, 0, sizeof(EVESpacerWidget));
- eve_widget_init(_widget, EVE_WIDGET_TYPE_SPACER, g, NULL, eve_spacerw_touch, eve_spacerw_draw, NULL);
-}
-
-int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
- return 0;
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_SPACER, g, page, eve_spacerw_draw, eve_spacerw_touch, NULL);
}
-uint8_t eve_spacerw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
+uint8_t eve_spacerw_draw(EVEWidget *_widget, uint8_t tag0) {
_widget->tag0 = tag0;
_widget->tagN = tag0;
return _widget->tagN;
}
+
+int eve_spacerw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
+ return 0;
+}
diff --git a/fw/fe310/eos/eve/widget/spacerw.h b/fw/fe310/eos/eve/widget/spacerw.h
index 0722ce2..9dafa8b 100644
--- a/fw/fe310/eos/eve/widget/spacerw.h
+++ b/fw/fe310/eos/eve/widget/spacerw.h
@@ -7,8 +7,8 @@ typedef struct EVESpacerWidget {
typedef struct EVESpacerSpec {
} EVESpacerSpec;
-int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEFont *font, EVESpacerSpec *spec);
-void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g);
+int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEPage *page, EVESpacerSpec *spec);
+void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g, EVEPage *page);
-int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
-uint8_t eve_spacerw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
+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 862d524..e65dd97 100644
--- a/fw/fe310/eos/eve/widget/strw.c
+++ b/fw/fe310/eos/eve/widget/strw.c
@@ -1,7 +1,6 @@
#include <stdlib.h>
#include <string.h>
-#include "unicode.h"
#include "clipb.h"
#include "eve.h"
@@ -23,7 +22,6 @@
#define CH_BS 0x08
#define CH_DEL 0x7f
-#define CH_EOF 0x1a
#define CH_CTRLX 0x18
#define CH_CTRLC 0x03
@@ -31,7 +29,8 @@
#define CHAR_VALID_INPUT(c) ((c >= 0x20) && (c < 0x7f))
-int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEFont *font, EVEStrSpec *spec) {
+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;
@@ -39,27 +38,24 @@ int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEFont *font, EVEStrSpec
if (str == NULL) return EVE_ERR_NOMEM;
str[0] = '\0';
- eve_strw_init(widget, g, font, str, spec->str_size);
+ eve_strw_init(widget, g, page, 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) {
+void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *str, uint16_t str_size) {
EVEWidget *_widget = &widget->w;
memset(widget, 0, sizeof(EVEStrWidget));
- eve_widget_init(_widget, EVE_WIDGET_TYPE_STR, g, font, eve_strw_touch, eve_strw_draw, eve_strw_putc);
- eve_strw_update(widget, str, str_size);
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_STR, g, page, eve_strw_draw, eve_strw_touch, eve_strw_putc);
+ eve_strw_update(widget, font, str, str_size);
}
-void eve_strw_update(EVEStrWidget *widget, utf8_t *str, uint16_t 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;
@@ -69,127 +65,61 @@ void eve_strw_update(EVEStrWidget *widget, utf8_t *str, uint16_t str_size) {
widget->str[str_len] = '\0';
}
widget->str_len = str_len;
- widget->str_g.w = eve_font_str_w(_widget->font, str);
+ widget->str_g.w = eve_font_str_w(widget->font, str);
}
- if (_widget->g.h == 0) _widget->g.h = eve_font_h(_widget->font);
+ if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font);
}
-static void set_focus(EVEStrWidget *widget, EVEPage *page) {
- EVERect focus;
+void eve_strw_destroy(EVEStrWidget *widget) {
+ eve_free(widget->str);
+}
+
+static void set_focus(EVEStrWidget *widget) {
EVEWidget *_widget = &widget->w;
+ EVEPage *page = _widget->page;
+ EVERect focus;
focus.x = _widget->g.x;
focus.y = _widget->g.y;
focus.w = _widget->g.w;
- focus.h = 2 * _widget->font->h;
+ focus.h = 2 * widget->font->h;
eve_page_set_focus(page, _widget, &focus);
}
-static EVEStrCursor *cursor_prox(EVEStrWidget *widget, EVEStrCursor *cursor, EVEPage *page, EVETouch *t, short *dx) {
+static EVEStrCursor *cursor_prox(EVEStrWidget *widget, EVEStrCursor *cursor, EVETouch *touch, short *dx) {
EVEWidget *_widget = &widget->w;
- int x = eve_page_x(page, t->x0) - _widget->g.x + widget->str_g.x;
+ EVEPage *page = _widget->page;
+ int x = eve_page_x(page, touch->x0) - _widget->g.x + widget->str_g.x;
int _dx;
*dx = cursor->x - x;
_dx = *dx < 0 ? -(*dx) : *dx;
- if (_dx <= _widget->font->w) return cursor;
+ if (_dx <= widget->font->w) return cursor;
return NULL;
}
-int eve_strw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
- EVEStrWidget *widget = (EVEStrWidget *)_widget;
- EVEStrCursor *t_cursor = NULL;
- short dx;
- int ret = 0;
-
- if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) {
- if (widget->cursor2.on) {
- t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx);
- }
- if ((t_cursor == NULL) && widget->cursor1.on) {
- t_cursor = cursor_prox(widget, &widget->cursor1, page, t, &dx);
- }
- if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
- if (t_cursor) {
- widget->track.mode = STRW_TRACK_CRSR;
- widget->track.cursor = t_cursor;
- widget->track.dx = dx;
- } else if (t->eevt & EVE_TOUCH_EETYPE_TRACK_X) {
- widget->track.mode = STRW_TRACK_TXT;
- }
- }
- }
-
- if ((evt & EVE_TOUCH_ETYPE_TRACK) && widget->track.mode) {
- int x, w1;
-
- switch (widget->track.mode) {
- case STRW_TRACK_TXT:
- if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
- widget->str_g.x0 = widget->str_g.x;
- }
- x = widget->str_g.x0 + t->x0 - t->x;
- w1 = _widget->g.w - _widget->font->w;
- if (x > widget->str_g.w - w1) x = widget->str_g.w - w1;
- if (x < 0) x = 0;
- widget->str_g.x = x;
- break;
-
- case STRW_TRACK_CRSR:
- eve_strw_cursor_set(widget, widget->track.cursor, eve_page_x(page, t->x) + widget->track.dx);
- break;
- }
- ret = 1;
- } else if (evt & EVE_TOUCH_ETYPE_LPRESS) {
- if (widget->cursor2.on) {
- // copy
- } else if (widget->cursor1.on) {
- if (t_cursor) {
- // paste
- } else {
- eve_strw_cursor_set(widget, &widget->cursor2, eve_page_x(page, t->x));
- }
- } else {
- // select
- }
- ret = 1;
- } else if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(t->eevt & EVE_TOUCH_EETYPE_LPRESS)) {
- eve_strw_cursor_set(widget, &widget->cursor1, eve_page_x(page, t->x0));
- if (widget->cursor2.on) eve_strw_cursor_clear(widget, &widget->cursor2);
- set_focus(widget, page);
- ret = 1;
- }
-
- if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
- widget->track.mode = STRW_TRACK_NONE;
- widget->track.cursor = NULL;
- widget->track.dx = 0;
- }
-
- return ret;
-}
-
-static void _draw_str(EVEStrWidget *widget, EVEPage *page, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
+static void _draw_str(EVEStrWidget *widget, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
int16_t x;
EVEWidget *_widget = &widget->w;
+ EVEPage *page = _widget->page;
x = _widget->g.x - widget->str_g.x;
if (x1 != x2) {
eve_cmd_dl(BEGIN(EVE_RECTS));
if (!s) eve_cmd_dl(COLOR_MASK(0 ,0 ,0 ,0));
eve_cmd_dl(VERTEX2F(x + x1, _widget->g.y));
- eve_cmd_dl(VERTEX2F(x + x2, _widget->g.y + _widget->font->h));
+ eve_cmd_dl(VERTEX2F(x + x2, _widget->g.y + widget->font->h));
if (!s) {
eve_cmd_dl(COLOR_MASK(1 ,1 ,1 ,1));
eve_cmd_dl(BEGIN(EVE_LINES));
- eve_cmd_dl(VERTEX2F(x + x1, _widget->g.y + _widget->font->h));
- eve_cmd_dl(VERTEX2F(x + x2, _widget->g.y + _widget->font->h));
+ eve_cmd_dl(VERTEX2F(x + x1, _widget->g.y + widget->font->h));
+ eve_cmd_dl(VERTEX2F(x + x2, _widget->g.y + widget->font->h));
}
eve_cmd_dl(END());
if (len) {
if (s) eve_cmd_dl(COLOR_RGBC(page->v.color_bg));
- eve_cmd(CMD_TEXT, "hhhhpb", x + x1, _widget->g.y, _widget->font->id, 0, widget->str + ch, len, 0);
+ eve_cmd(CMD_TEXT, "hhhhpb", x + x1, _widget->g.y, widget->font->id, 0, widget->str + ch, len, 0);
if (s) eve_cmd_dl(COLOR_RGBC(page->v.color_fg));
}
}
@@ -203,11 +133,11 @@ static void _draw_cursor(EVEStrWidget *widget, EVEStrCursor *cursor) {
y = _widget->g.y;
eve_cmd_dl(BEGIN(EVE_LINES));
eve_cmd_dl(VERTEX2F(x, y));
- eve_cmd_dl(VERTEX2F(x, y + _widget->font->h));
+ eve_cmd_dl(VERTEX2F(x, y + widget->font->h));
eve_cmd_dl(END());
}
-uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
+uint8_t eve_strw_draw(EVEWidget *_widget, uint8_t tag0) {
EVEStrWidget *widget = (EVEStrWidget *)_widget;
char cut = widget->str_g.x || (widget->str_g.w > _widget->g.w);
@@ -220,6 +150,7 @@ uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
_widget->tagN = tag0;
if (cut) {
+ EVEPage *page = _widget->page;
EVEWindow *window = page->v.window;
int16_t x = eve_page_scr_x(page, _widget->g.x);
int16_t y = eve_page_scr_y(page, _widget->g.y);
@@ -265,12 +196,12 @@ uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
l1 = c1->ch;
l2 = c2->ch - c1->ch;
l3 = widget->str_len - c2->ch;
- _draw_str(widget, page, 0, l1, 0, c1->x, 0);
- _draw_str(widget, page, c1->ch, l2, c1->x, c2->x, 1);
- _draw_str(widget, page, c2->ch, l3, c2->x, widget->str_g.x + _widget->g.w, 0);
+ _draw_str(widget, 0, l1, 0, c1->x, 0);
+ _draw_str(widget, c1->ch, l2, c1->x, c2->x, 1);
+ _draw_str(widget, c2->ch, l3, c2->x, widget->str_g.x + _widget->g.w, 0);
} else {
if (widget->cursor1.on) _draw_cursor(widget, &widget->cursor1);
- _draw_str(widget, page, 0, widget->str_len, 0, widget->str_g.x + _widget->g.w, 0);
+ _draw_str(widget, 0, widget->str_len, 0, widget->str_g.x + _widget->g.w, 0);
}
if (cut) {
@@ -280,21 +211,94 @@ uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
return _widget->tagN;
}
-void eve_strw_putc(void *_page, int c) {
- EVEPage *page = _page;
- EVEStrWidget *widget = (EVEStrWidget *)eve_page_get_focus(page);
+int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
+ EVEPage *page = _widget->page;
+ EVEStrWidget *widget = (EVEStrWidget *)_widget;
+ EVEStrCursor *t_cursor = NULL;
+ short dx;
+ int ret = 0;
+
+ if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) {
+ if (widget->cursor2.on) {
+ t_cursor = cursor_prox(widget, &widget->cursor2, touch, &dx);
+ }
+ if ((t_cursor == NULL) && widget->cursor1.on) {
+ t_cursor = cursor_prox(widget, &widget->cursor1, touch, &dx);
+ }
+ if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
+ if (t_cursor) {
+ widget->track.mode = STRW_TRACK_CRSR;
+ widget->track.cursor = t_cursor;
+ widget->track.dx = dx;
+ } else if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X) {
+ widget->track.mode = STRW_TRACK_TXT;
+ }
+ }
+ }
+
+ if ((evt & EVE_TOUCH_ETYPE_TRACK) && widget->track.mode) {
+ int x, w1;
+
+ switch (widget->track.mode) {
+ case STRW_TRACK_TXT:
+ if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
+ widget->str_g.x0 = widget->str_g.x;
+ }
+ x = widget->str_g.x0 + touch->x0 - touch->x;
+ w1 = _widget->g.w - widget->font->w;
+ if (x > widget->str_g.w - w1) x = widget->str_g.w - w1;
+ if (x < 0) x = 0;
+ widget->str_g.x = x;
+ break;
+
+ case STRW_TRACK_CRSR:
+ eve_strw_cursor_set(widget, widget->track.cursor, eve_page_x(page, touch->x) + widget->track.dx);
+ break;
+ }
+ ret = 1;
+ } else if (evt & EVE_TOUCH_ETYPE_LPRESS) {
+ if (widget->cursor2.on) {
+ // copy
+ } else if (widget->cursor1.on) {
+ if (t_cursor) {
+ // paste
+ } else {
+ eve_strw_cursor_set(widget, &widget->cursor2, eve_page_x(page, touch->x));
+ }
+ } else {
+ // select
+ }
+ ret = 1;
+ } else if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(touch->eevt & EVE_TOUCH_EETYPE_LPRESS)) {
+ eve_strw_cursor_set(widget, &widget->cursor1, eve_page_x(page, touch->x0));
+ if (widget->cursor2.on) eve_strw_cursor_clear(widget, &widget->cursor2);
+ set_focus(widget);
+ ret = 1;
+ }
+
+ if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
+ widget->track.mode = STRW_TRACK_NONE;
+ widget->track.cursor = NULL;
+ widget->track.dx = 0;
+ }
+
+ return ret;
+}
+
+void eve_strw_putc(void *w, int c) {
+ EVEStrWidget *widget = (EVEStrWidget *)w;
EVEWidget *_widget = &widget->w;
EVEStrCursor *cursor1 = &widget->cursor1;
EVEStrCursor *cursor2 = &widget->cursor2;
utf8_t *str;
utf8_t *clipb = NULL;
- int w0 = _widget->font->w;
- int w1 = _widget->g.w - _widget->font->w;
+ int w0 = widget->font->w;
+ int w1 = _widget->g.w - widget->font->w;
int ins_c = 0, del_c = 0;
int ins_w = 0, del_w = 0;
- if (c == CH_EOF) {
+ if (c == EVE_PAGE_KBDCH_CLOSE) {
if (cursor1->on) eve_strw_cursor_clear(widget, cursor1);
if (cursor2->on) eve_strw_cursor_clear(widget, cursor2);
return;
@@ -310,7 +314,7 @@ void eve_strw_putc(void *_page, int c) {
case CH_BS:
if (cursor1->ch > 0) {
del_c = -utf8_seek(str, -1, &uc);
- del_w = eve_font_ch_w(_widget->font, uc);
+ del_w = eve_font_ch_w(widget->font, uc);
memmove(str - del_c, str, widget->str_len - cursor1->ch + 1);
widget->str_len -= del_c;
widget->str_g.w -= del_w;
@@ -322,7 +326,7 @@ void eve_strw_putc(void *_page, int c) {
case CH_DEL:
if (cursor1->ch < widget->str_len) {
del_c = utf8_dec(str, &uc);
- del_w = eve_font_ch_w(_widget->font, uc);
+ del_w = eve_font_ch_w(widget->font, uc);
memmove(str, str + del_c, widget->str_len - cursor1->ch - del_c + 1);
widget->str_len -= del_c;
widget->str_g.w -= del_w;
@@ -345,7 +349,7 @@ void eve_strw_putc(void *_page, int c) {
c1 = cursor2;
}
del_c = c2->ch - c1->ch;
- del_w = eve_font_buf_w(_widget->font, str, del_c);
+ del_w = eve_font_buf_w(widget->font, str, del_c);
if ((c == CH_CTRLX) || (c == CH_CTRLC)) {
eve_clipb_push(str, del_c);
if (c == CH_CTRLC) return;
@@ -355,7 +359,7 @@ void eve_strw_putc(void *_page, int c) {
str = widget->str + c1->ch;
if (CHAR_VALID_INPUT(c)) {
ins_c = utf8_enc(c, utf8_buf);
- ins_w = eve_font_ch_w(_widget->font, c);
+ ins_w = eve_font_ch_w(widget->font, c);
} else if (c == CH_CTRLV) {
int rv, clipb_len = 0;
@@ -368,7 +372,7 @@ void eve_strw_putc(void *_page, int c) {
}
}
ins_c = clipb_len;
- ins_w = eve_font_str_w(_widget->font, clipb);
+ ins_w = eve_font_str_w(widget->font, clipb);
}
if (widget->str_len + ins_c >= widget->str_size + del_c) {
ins_c = 0;
@@ -411,7 +415,7 @@ void eve_strw_cursor_set(EVEStrWidget *widget, EVEStrCursor *cursor, int16_t x)
i = 0;
while (i < widget->str_len) {
ch_l = utf8_dec(widget->str + i, &ch);
- ch_w = eve_font_ch_w(_widget->font, ch);
+ ch_w = eve_font_ch_w(widget->font, ch);
_x += ch_w;
i += ch_l;
if (_x >= x) {
diff --git a/fw/fe310/eos/eve/widget/strw.h b/fw/fe310/eos/eve/widget/strw.h
index fa1faf8..ae54700 100644
--- a/fw/fe310/eos/eve/widget/strw.h
+++ b/fw/fe310/eos/eve/widget/strw.h
@@ -31,13 +31,13 @@ typedef struct EVEStrSpec {
uint16_t str_size;
} EVEStrSpec;
-int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEFont *font, EVEStrSpec *spec);
+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_update(EVEStrWidget *widget, EVEFont *font, utf8_t *str, uint16_t str_size);
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, utf8_t *str, uint16_t str_size);
-int eve_strw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
-uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
+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 7e18475..4224f44 100644
--- a/fw/fe310/eos/eve/widget/textw.c
+++ b/fw/fe310/eos/eve/widget/textw.c
@@ -1,7 +1,6 @@
#include <stdlib.h>
#include <string.h>
-#include "unicode.h"
#include "clipb.h"
#include "eve.h"
@@ -19,7 +18,6 @@
#define CH_BS 0x08
#define CH_DEL 0x7f
-#define CH_EOF 0x1a
#define CH_CTRLX 0x18
#define CH_CTRLC 0x03
@@ -34,7 +32,8 @@
#define DIVC(x,y) ((x) / (y) + ((x) % (y) != 0))
-int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEFont *font, EVETextSpec *spec) {
+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;
@@ -49,27 +48,23 @@ int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEFont *font, EVETextSp
return EVE_ERR_NOMEM;
}
- eve_textw_init(widget, g, font, text, spec->text_size, line, spec->line_size);
+ eve_textw_init(widget, g, page, 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) {
+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;
memset(widget, 0, sizeof(EVETextWidget));
- eve_widget_init(_widget, EVE_WIDGET_TYPE_TEXT, g, font, eve_textw_touch, eve_textw_draw, eve_textw_putc);
- eve_textw_update(widget, text, text_size, line, line_size);
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_TEXT, g, page, eve_textw_draw, eve_textw_touch, eve_textw_putc);
+ eve_textw_update(widget, font, text, text_size, line, line_size);
}
-void eve_textw_update(EVETextWidget *widget, 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 rv, text_len;
+ if (font) widget->font = font;
if (text) {
widget->text = text;
widget->text_size = text_size;
@@ -88,21 +83,28 @@ void eve_textw_update(EVETextWidget *widget, utf8_t *text, uint16_t text_size, u
eve_textw_text_update(widget, 0);
}
-static void set_focus(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page) {
- EVERect focus;
+void eve_textw_destroy(EVETextWidget *widget) {
+ eve_free(widget->line);
+ eve_free(widget->text);
+}
+
+static void set_focus(EVETextWidget *widget, EVETextCursor *cursor) {
EVEWidget *_widget = &widget->w;
+ EVEPage *page = _widget->page;
+ EVERect focus;
focus.x = _widget->g.x;
- focus.y = _widget->g.y + cursor->line * _widget->font->h;
+ focus.y = _widget->g.y + cursor->line * widget->font->h;
focus.w = _widget->g.w;
- focus.h = 2 * _widget->font->h;
+ focus.h = 2 * widget->font->h;
eve_page_set_focus(page, _widget, &focus);
}
-static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page, EVETouch *t, short *dx, short *dl) {
+static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, EVETouch *touch, short *dx, short *dl) {
EVEWidget *_widget = &widget->w;
- int x = eve_page_x(page, t->x0) - _widget->g.x;
- int l = (int)t->tag0 - _widget->tag0 + widget->line0;
+ EVEPage *page = _widget->page;
+ int x = eve_page_x(page, touch->x0) - _widget->g.x;
+ int l = (int)touch->tag0 - _widget->tag0 + widget->line0;
int _dx, _dl;
*dx = cursor->x - x;
@@ -111,80 +113,29 @@ static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor,
_dx = *dx < 0 ? -(*dx) : *dx;
_dl = *dl < 0 ? -(*dl) : *dl;
- if ((_dx <= _widget->font->h) && (_dl <= 1)) return cursor;
+ if ((_dx <= widget->font->h) && (_dl <= 1)) return cursor;
return NULL;
}
-int eve_textw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
- EVETextWidget *widget = (EVETextWidget *)_widget;
- EVETextCursor *t_cursor = NULL;
- short dx, dl;
- int ret = 0;
-
- if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) {
- if (widget->cursor2.on) {
- t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx, &dl);
- }
- if ((t_cursor == NULL) && widget->cursor1.on) {
- t_cursor = cursor_prox(widget, &widget->cursor1, page, t, &dx, &dl);
- }
- if (t_cursor && (evt & EVE_TOUCH_ETYPE_TRACK_START)) {
- widget->track.cursor = t_cursor;
- widget->track.dx = dx;
- widget->track.dl = dl;
- }
- }
-
- if ((evt & EVE_TOUCH_ETYPE_TRACK) && widget->track.cursor) {
- eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, eve_page_x(page, t->x) + widget->track.dx);
- ret = 1;
- } else if (evt & EVE_TOUCH_ETYPE_LPRESS) {
- if (widget->cursor2.on) {
- // copy
- } else if (widget->cursor1.on) {
- if (t_cursor && (dl == 0)) {
- // paste
- } else {
- eve_textw_cursor_set(widget, &widget->cursor2, t->tag, eve_page_x(page, t->x));
- }
- } else {
- // select
- }
- ret = 1;
- } else if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(t->eevt & EVE_TOUCH_EETYPE_LPRESS)) {
- eve_textw_cursor_set(widget, &widget->cursor1, t->tag_up, eve_page_x(page, t->x0));
- if (widget->cursor2.on) eve_textw_cursor_clear(widget, &widget->cursor2);
- set_focus(widget, &widget->cursor1, page);
- ret = 1;
- }
-
- if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
- widget->track.cursor = NULL;
- widget->track.dx = 0;
- widget->track.dl = 0;
- }
-
- return ret;
-}
-
-static void _draw_line(EVETextWidget *widget, EVEPage *page, uint16_t l, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
+static void _draw_line(EVETextWidget *widget, uint16_t l, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
EVEWidget *_widget = &widget->w;
+ EVEPage *page = _widget->page;
if (x1 != x2) {
eve_cmd_dl(BEGIN(EVE_RECTS));
if (!s) eve_cmd_dl(COLOR_MASK(0 ,0 ,0 ,0));
- eve_cmd_dl(VERTEX2F(_widget->g.x + x1, _widget->g.y + l * _widget->font->h));
- eve_cmd_dl(VERTEX2F(_widget->g.x + x2, _widget->g.y + (l + 1) * _widget->font->h));
+ eve_cmd_dl(VERTEX2F(_widget->g.x + x1, _widget->g.y + l * widget->font->h));
+ eve_cmd_dl(VERTEX2F(_widget->g.x + x2, _widget->g.y + (l + 1) * widget->font->h));
if (!s) {
eve_cmd_dl(COLOR_MASK(1 ,1 ,1 ,1));
eve_cmd_dl(BEGIN(EVE_LINES));
- eve_cmd_dl(VERTEX2F(_widget->g.x + x1, _widget->g.y + (l + 1) * _widget->font->h));
- eve_cmd_dl(VERTEX2F(_widget->g.x + x2, _widget->g.y + (l + 1) * _widget->font->h));
+ eve_cmd_dl(VERTEX2F(_widget->g.x + x1, _widget->g.y + (l + 1) * widget->font->h));
+ eve_cmd_dl(VERTEX2F(_widget->g.x + x2, _widget->g.y + (l + 1) * widget->font->h));
}
eve_cmd_dl(END());
if (len) {
if (s) eve_cmd_dl(COLOR_RGBC(page->v.color_bg));
- eve_cmd(CMD_TEXT, "hhhhpb", _widget->g.x + x1, _widget->g.y + l * _widget->font->h, _widget->font->id, 0, widget->text + ch, len, 0);
+ eve_cmd(CMD_TEXT, "hhhhpb", _widget->g.x + x1, _widget->g.y + l * widget->font->h, widget->font->id, 0, widget->text + ch, len, 0);
if (s) eve_cmd_dl(COLOR_RGBC(page->v.color_fg));
}
}
@@ -195,21 +146,22 @@ static void _draw_cursor(EVETextWidget *widget, EVETextCursor *cursor) {
EVEWidget *_widget = &widget->w;
x = _widget->g.x + cursor->x;
- y = _widget->g.y + cursor->line * _widget->font->h;
+ y = _widget->g.y + cursor->line * widget->font->h;
eve_cmd_dl(BEGIN(EVE_LINES));
eve_cmd_dl(VERTEX2F(x, y));
- eve_cmd_dl(VERTEX2F(x, y + _widget->font->h));
+ eve_cmd_dl(VERTEX2F(x, y + widget->font->h));
eve_cmd_dl(END());
}
-uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
+uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) {
+ EVEPage *page = _widget->page;
EVETextWidget *widget = (EVETextWidget *)_widget;
int line0, lineN;
int _line0, _lineN;
char lineNvisible;
- _line0 = line0 = ((int)page->win_y - _widget->g.y) / _widget->font->h;
- _lineN = lineN = DIVC(((int)page->win_y - _widget->g.y + page->v.window->g.h), _widget->font->h);
+ _line0 = line0 = ((int)page->win_y - _widget->g.y) / widget->font->h;
+ _lineN = lineN = DIVC(((int)page->win_y - _widget->g.y + page->v.window->g.h), widget->font->h);
if (line0 < 0) line0 = 0;
if (lineN < 0) lineN = 0;
if (line0 > widget->line_len) line0 = widget->line_len;
@@ -256,10 +208,10 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
l3 = 0;
s = 1;
}
- _draw_line(widget, page, i, LINE_START(widget, i), l1, 0, c1->x, 0);
- _draw_line(widget, page, i, c1->ch, l2, c1->x, s ? _widget->g.w : c2->x, 1);
+ _draw_line(widget, i, LINE_START(widget, i), l1, 0, c1->x, 0);
+ _draw_line(widget, i, c1->ch, l2, c1->x, s ? _widget->g.w : c2->x, 1);
if (!s) {
- _draw_line(widget, page, i, c2->ch, l3, c2->x, _widget->g.w, 0);
+ _draw_line(widget, i, c2->ch, l3, c2->x, _widget->g.w, 0);
c1 = NULL;
c2 = NULL;
}
@@ -267,14 +219,14 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
int l1 = c2->ch - LINE_START(widget, i);
int l2 = LINE_START(widget, i) + LINE_LEN(widget, i) - c2->ch;
- _draw_line(widget, page, i, LINE_START(widget, i), l1, 0, c2->x, 1);
- _draw_line(widget, page, i, c2->ch, l2, c2->x, _widget->g.w, 0);
+ _draw_line(widget, i, LINE_START(widget, i), l1, 0, c2->x, 1);
+ _draw_line(widget, i, c2->ch, l2, c2->x, _widget->g.w, 0);
c1 = NULL;
c2 = NULL;
s = 0;
} else {
if (widget->cursor1.on && (widget->cursor1.line == i)) _draw_cursor(widget, &widget->cursor1);
- _draw_line(widget, page, i, LINE_START(widget, i), LINE_LEN(widget, i), 0, _widget->g.w, s);
+ _draw_line(widget, i, LINE_START(widget, i), LINE_LEN(widget, i), 0, _widget->g.w, s);
}
}
if (lineNvisible) {
@@ -283,7 +235,7 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
eve_touch_set_opt(_widget->tagN, TEXTW_TOUCH_OPT);
_widget->tagN++;
}
- _draw_line(widget, page, lineN, 0, 0, 0, _widget->g.w, 0);
+ _draw_line(widget, lineN, 0, 0, 0, _widget->g.w, 0);
}
} else {
widget->line0 = 0;
@@ -291,14 +243,64 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
_widget->tagN = EVE_TAG_NOTAG;
}
- _widget->g.h = (widget->line_len + 1) * _widget->font->h;
-
return _widget->tagN;
}
-void eve_textw_putc(void *_page, int c) {
- EVEPage *page = _page;
- EVETextWidget *widget = (EVETextWidget *)eve_page_get_focus(page);
+int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
+ EVEPage *page = _widget->page;
+ EVETextWidget *widget = (EVETextWidget *)_widget;
+ EVETextCursor *t_cursor = NULL;
+ short dx, dl;
+ int ret = 0;
+
+ if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) {
+ if (widget->cursor2.on) {
+ t_cursor = cursor_prox(widget, &widget->cursor2, touch, &dx, &dl);
+ }
+ if ((t_cursor == NULL) && widget->cursor1.on) {
+ t_cursor = cursor_prox(widget, &widget->cursor1, touch, &dx, &dl);
+ }
+ if (t_cursor && (evt & EVE_TOUCH_ETYPE_TRACK_START)) {
+ widget->track.cursor = t_cursor;
+ widget->track.dx = dx;
+ widget->track.dl = dl;
+ }
+ }
+
+ if ((evt & EVE_TOUCH_ETYPE_TRACK) && widget->track.cursor) {
+ eve_textw_cursor_set(widget, widget->track.cursor, touch->tag + widget->track.dl, eve_page_x(page, touch->x) + widget->track.dx);
+ ret = 1;
+ } else if (evt & EVE_TOUCH_ETYPE_LPRESS) {
+ if (widget->cursor2.on) {
+ // copy
+ } else if (widget->cursor1.on) {
+ if (t_cursor && (dl == 0)) {
+ // paste
+ } else {
+ eve_textw_cursor_set(widget, &widget->cursor2, touch->tag, eve_page_x(page, touch->x));
+ }
+ } else {
+ // select
+ }
+ ret = 1;
+ } else if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(touch->eevt & EVE_TOUCH_EETYPE_LPRESS)) {
+ eve_textw_cursor_set(widget, &widget->cursor1, touch->tag_up, eve_page_x(page, touch->x0));
+ if (widget->cursor2.on) eve_textw_cursor_clear(widget, &widget->cursor2);
+ set_focus(widget, &widget->cursor1);
+ ret = 1;
+ }
+
+ if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
+ widget->track.cursor = NULL;
+ widget->track.dx = 0;
+ widget->track.dl = 0;
+ }
+
+ return ret;
+}
+
+void eve_textw_putc(void *w, int c) {
+ EVETextWidget *widget = (EVETextWidget *)w;
EVEWidget *_widget = &widget->w;
EVETextCursor *cursor1 = &widget->cursor1;
EVETextCursor *cursor2 = &widget->cursor2;
@@ -308,7 +310,7 @@ void eve_textw_putc(void *_page, int c) {
int ins_c = 0, del_c = 0;
int ch_w = 0;
- if (c == CH_EOF) {
+ if (c == EVE_PAGE_KBDCH_CLOSE) {
if (cursor1->on) eve_textw_cursor_clear(widget, cursor1);
if (cursor2->on) eve_textw_cursor_clear(widget, cursor2);
return;
@@ -324,7 +326,7 @@ void eve_textw_putc(void *_page, int c) {
case CH_BS:
if (cursor1->ch > 0) {
del_c = -utf8_seek(text, -1, &uc);
- ch_w = eve_font_ch_w(_widget->font, uc);
+ ch_w = eve_font_ch_w(widget->font, uc);
memmove(text - del_c, text, widget->text_len - cursor1->ch + 1);
cursor1->ch -= del_c;
}
@@ -333,7 +335,7 @@ void eve_textw_putc(void *_page, int c) {
case CH_DEL:
if (cursor1->ch < widget->text_len) {
del_c = utf8_dec(text, &uc);
- ch_w = eve_font_ch_w(_widget->font, uc);
+ ch_w = eve_font_ch_w(widget->font, uc);
memmove(text, text + del_c, widget->text_len - cursor1->ch - del_c + 1);
}
break;
@@ -359,7 +361,7 @@ void eve_textw_putc(void *_page, int c) {
text = widget->text + c1->ch;
if (CHAR_VALID_INPUT(c)) {
ins_c = utf8_enc(c, utf8_buf);
- ch_w = eve_font_ch_w(_widget->font, c);
+ ch_w = eve_font_ch_w(widget->font, c);
} else if (c == CH_CTRLV) {
int rv, clipb_len = 0;
@@ -372,7 +374,7 @@ void eve_textw_putc(void *_page, int c) {
}
}
ins_c = clipb_len;
- ch_w = eve_font_str_w(_widget->font, clipb);
+ ch_w = eve_font_str_w(widget->font, clipb);
}
if (widget->text_len + ins_c >= widget->text_size + del_c) {
ins_c = 0;
@@ -407,11 +409,11 @@ void eve_textw_putc(void *_page, int c) {
if (cursor1->line && (cursor1->ch < LINE_START(widget, cursor1->line))) {
cursor1->line--;
eve_textw_cursor_update(widget, cursor1);
- set_focus(widget, cursor1, page);
+ set_focus(widget, cursor1);
} else if (cursor1->ch > LINE_END(widget, cursor1->line)) {
while (cursor1->ch > LINE_END(widget, cursor1->line)) cursor1->line++;
eve_textw_cursor_update(widget, cursor1);
- set_focus(widget, cursor1, page);
+ set_focus(widget, cursor1);
} else {
cursor1->x += ch_w;
}
@@ -425,6 +427,7 @@ uint16_t eve_textw_text_update(EVETextWidget *widget, uint16_t line) {
uint16_t word_w, line_w, line_b;
uint16_t new_h;
EVEWidget *_widget = &widget->w;
+ EVEPage *page = _widget->page;
word_w = 0;
line_w = 0;
@@ -440,7 +443,7 @@ uint16_t eve_textw_text_update(EVETextWidget *widget, uint16_t line) {
widget->line[line] = LINE_EMPTY;
}
- ch_w = eve_font_ch_w(_widget->font, ch);
+ ch_w = eve_font_ch_w(widget->font, ch);
if (ch <= 0x20) {
if ((ch == '\n') || (ch == '\0')) {
if (widget->line[line] == i) return line;
@@ -473,11 +476,16 @@ uint16_t eve_textw_text_update(EVETextWidget *widget, uint16_t line) {
i += ch_l;
}
- widget->line_len = line;
for (i=line; i<widget->line_size; i++) {
widget->line[i] = LINE_EMPTY;
}
+ if (widget->line_len != line) {
+ widget->line_len = line;
+ _widget->g.h = (widget->line_len + 1) * widget->font->h;
+ eve_widget_uievt_push(_widget, EVE_UIEVT_WIDGET_UPDATE_G, NULL);
+ }
+
return line;
}
@@ -490,7 +498,7 @@ void eve_textw_cursor_update(EVETextWidget *widget, EVETextCursor *cursor) {
while ((i < cursor->ch) && (i < LINE_END(widget, cursor->line))) {
ch_l = utf8_dec(widget->text + i, &ch);
- x += eve_font_ch_w(_widget->font, ch);
+ x += eve_font_ch_w(widget->font, ch);
i += ch_l;
}
cursor->x = x;
@@ -521,7 +529,7 @@ void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t
i = LINE_START(widget, cursor->line);
while (i < LINE_END(widget, cursor->line)) {
ch_l = utf8_dec(widget->text + i, &ch);
- ch_w = eve_font_ch_w(_widget->font, ch);
+ ch_w = eve_font_ch_w(widget->font, ch);
_x += ch_w;
i += ch_l;
if (_x >= x) {
diff --git a/fw/fe310/eos/eve/widget/textw.h b/fw/fe310/eos/eve/widget/textw.h
index abf8f33..59e6f8c 100644
--- a/fw/fe310/eos/eve/widget/textw.h
+++ b/fw/fe310/eos/eve/widget/textw.h
@@ -9,6 +9,7 @@ typedef struct EVETextCursor {
typedef struct EVETextWidget {
EVEWidget w;
+ EVEFont *font;
utf8_t *text;
uint16_t text_size;
uint16_t text_len;
@@ -31,14 +32,15 @@ typedef struct EVETextSpec {
uint16_t line_size;
} EVETextSpec;
-int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEFont *font, EVETextSpec *spec);
+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_update(EVETextWidget *widget, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size);
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, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size);
-int eve_textw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
-uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
+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);
+
uint16_t eve_textw_text_update(EVETextWidget *widget, 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);
diff --git a/fw/fe310/eos/eve/widget/widget.c b/fw/fe310/eos/eve/widget/widget.c
index 09894bc..6f6a3ff 100644
--- a/fw/fe310/eos/eve/widget/widget.c
+++ b/fw/fe310/eos/eve/widget/widget.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"
@@ -42,11 +40,11 @@ static const eve_widget_destroy_t _widget_destroy[] = {
(eve_widget_destroy_t)eve_selectw_destroy,
};
-void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEFont *font, eve_widget_touch_t touch, eve_widget_draw_t draw, eve_kbd_input_handler_t putc) {
+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;
- widget->font = font;
- widget->touch = touch;
+ widget->page = page;
widget->draw = draw;
+ widget->touch = touch;
widget->putc = putc;
widget->type = type;
}
@@ -64,10 +62,15 @@ EVEWidget *eve_widget_next(EVEWidget *widget) {
return (EVEWidget *)(_w + _widget_size[widget->type]);
}
-int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEFont *font, EVEWidgetSpecT *spec) {
- return _widget_create[type](widget, g, font, spec);
+int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, EVEWidgetSpecT *spec) {
+ return _widget_create[type](widget, g, page, spec);
}
void eve_widget_destroy(EVEWidget *widget) {
if (_widget_destroy[widget->type]) _widget_destroy[widget->type](widget);
+}
+
+void eve_widget_uievt_push(EVEWidget *widget, uint16_t evt, void *param) {
+ EVEView *view = &widget->page->v;
+ eve_view_uievt_push(view, evt, param ? param : 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 5dc8abe..0f76799 100644
--- a/fw/fe310/eos/eve/widget/widget.h
+++ b/fw/fe310/eos/eve/widget/widget.h
@@ -9,14 +9,14 @@
struct EVEWidget;
-typedef int (*eve_widget_touch_t) (struct EVEWidget *, EVEPage *, EVETouch *, uint16_t);
-typedef uint8_t (*eve_widget_draw_t) (struct EVEWidget *, EVEPage *, uint8_t);
+typedef uint8_t (*eve_widget_draw_t) (struct EVEWidget *, uint8_t);
+typedef int (*eve_widget_touch_t) (struct EVEWidget *, EVETouch *, uint16_t);
typedef struct EVEWidget {
EVERect g;
- EVEFont *font;
- eve_widget_touch_t touch;
+ EVEPage *page;
eve_widget_draw_t draw;
+ eve_widget_touch_t touch;
eve_kbd_input_handler_t putc;
EVELabel *label;
uint8_t type;
@@ -24,7 +24,9 @@ typedef struct EVEWidget {
uint8_t tagN;
} EVEWidget;
-void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEFont *font, eve_widget_touch_t touch, eve_widget_draw_t draw, eve_kbd_input_handler_t putc);
+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_uievt_push(EVEWidget *widget, uint16_t evt, void *param); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/widgets.h b/fw/fe310/eos/eve/widget/widgets.h
index c33fc03..2f8d3ca 100644
--- a/fw/fe310/eos/eve/widget/widgets.h
+++ b/fw/fe310/eos/eve/widget/widgets.h
@@ -27,14 +27,13 @@ typedef struct EVEWidgetSpec {
APPLabelSpec label;
struct {
EVERect g;
- EVEFont *font;
EVEWidgetSpecT spec;
uint8_t type;
} widget;
} EVEWidgetSpec;
-typedef int (*eve_widget_create_t) (EVEWidget *, EVERect *g, EVEFont *, EVEWidgetSpecT *);
+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, EVEFont *font, EVEWidgetSpecT *spec);
+int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, EVEWidgetSpecT *spec);
void eve_widget_destroy(EVEWidget *widget);