diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-06-10 02:39:37 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-06-10 02:39:37 +0200 |
commit | 294d4533489e9ed6b7e71c63a1faa9722a2621c6 (patch) | |
tree | 04a3b9be039206e4457ff5632b98a7f793ddc001 /code/fe310/eos/eve/screen/form.c | |
parent | b5aa60b256dd2b328515779883ba365aba3d995f (diff) |
page/form refactor; implemented form layout, labels
Diffstat (limited to 'code/fe310/eos/eve/screen/form.c')
-rw-r--r-- | code/fe310/eos/eve/screen/form.c | 82 |
1 files changed, 63 insertions, 19 deletions
diff --git a/code/fe310/eos/eve/screen/form.c b/code/fe310/eos/eve/screen/form.c index ae381e6..442b329 100644 --- a/code/fe310/eos/eve/screen/form.c +++ b/code/fe310/eos/eve/screen/form.c @@ -7,48 +7,57 @@ #include "screen.h" #include "window.h" #include "page.h" +#include "font.h" #include "form.h" +#include "widget/label.h" #include "widget/widget.h" #define CH_EOF 0x1a int eve_form_init(EVEForm *form, EVEWidget *widget, uint16_t widget_size, eve_page_open_t open, eve_page_close_t close, EVEWindow *window) { memset(form, 0, sizeof(EVEForm)); - eve_page_init(&form->p, eve_form_touch, eve_form_draw, open, close, window); + eve_page_init(&form->p, eve_form_touch, eve_form_draw, open, close, eve_form_handle_evt, eve_form_update_g, window); form->widget = widget; form->widget_size = widget_size; + eve_form_update_g(&form->p, NULL); } int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx) { EVEForm *form = (EVEForm *)v; EVEWidget *widget = form->widget; - int a, i, ret = 0; + EVEWidget *widget_f = eve_page_get_focus(&form->p); + int i, ret = 0; EVERect focus = {0,0,0,0}; for (i=0; i<form->widget_size; i++) { - a = widget->touch(widget, &form->p, tag0, touch_idx, &focus); - ret = ret || a; - if (focus.w && focus.h && (form->widget_f != widget)) { - EVEKbd *kbd = eve_screen_get_kbd(form->p.window->screen); - - if (kbd) { - if (form->widget_f && form->widget_f->putc) { - eve_screen_hide_kbd(form->p.window->screen); - form->widget_f->putc(form->widget_f, CH_EOF); - } - eve_kbd_set_handler(kbd, widget->putc, widget); - if (widget && widget->putc) { - eve_screen_show_kbd(form->p.window->screen); + if (eve_page_rect_visible(&form->p, &widget->g)) { + int a; + EVERect r = {0,0,0,0}; + + a = widget->touch(widget, &form->p, tag0, touch_idx, &r); + ret = ret || a; + if (r.w && r.h && (widget_f != widget)) { + EVEKbd *kbd = eve_screen_get_kbd(form->p.window->screen); + + if (kbd) { + if (widget_f && widget_f->putc) { + eve_screen_hide_kbd(form->p.window->screen); + widget_f->putc(widget_f, CH_EOF); + } + eve_kbd_set_handler(kbd, widget->putc, &form->p); + if (widget->putc) { + eve_screen_show_kbd(form->p.window->screen); + } } + widget_f = widget; + focus = r; } - form->widget_f = widget; } widget = eve_widget_next(widget); - memset(&focus, 0, sizeof(focus)); } - eve_page_focus(&form->p, &focus); + if (focus.w && focus.h) eve_page_set_focus(&form->p, widget_f, &focus); return ret; } @@ -58,8 +67,15 @@ uint8_t eve_form_draw(EVEView *v, uint8_t tag0) { int i; uint8_t tagN = tag0; + eve_cmd_dl(VERTEX_FORMAT(0)); + for (i=0; i<form->widget_size; i++) { - tagN = widget->draw(widget, &form->p, tagN); + if (widget->label && eve_page_rect_visible(&form->p, &widget->label->g)) { + eve_cmd_dl(TAG_MASK(0)); + eve_label_draw(widget->label); + eve_cmd_dl(TAG_MASK(1)); + } + if (eve_page_rect_visible(&form->p, &widget->g)) tagN = widget->draw(widget, &form->p, tagN); widget = eve_widget_next(widget); } @@ -69,3 +85,31 @@ uint8_t eve_form_draw(EVEView *v, uint8_t tag0) { return tagN; } + +void eve_form_handle_evt(EVEPage *page, EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx) { + /* + if (evt & EVE_TOUCH_ETYPE_TRACK_Y) { + // do scroll + } else { + // go back / forward + } + */ +} + +void eve_form_update_g(EVEPage *page, EVEWidget *_widget) { + EVEForm *form = (EVEForm *)page; + EVEWidget *widget = form->widget; + int i; + uint16_t h = 0; + + for (i=0; i<form->widget_size; i++) { + if (widget->label) { + widget->label->g.y = h; + if (widget->label->g.w + widget->g.w > form->p.window->screen->w) h += widget->label->g.h; + } + widget->g.y = h; + h += widget->g.h; + + widget = eve_widget_next(widget); + } +} |