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 | |
parent | b5aa60b256dd2b328515779883ba365aba3d995f (diff) |
page/form refactor; implemented form layout, labels
-rw-r--r-- | code/fe310/eos/eve/eve_kbd.c | 1 | ||||
-rw-r--r-- | code/fe310/eos/eve/screen/font.c | 14 | ||||
-rw-r--r-- | code/fe310/eos/eve/screen/font.h | 2 | ||||
-rw-r--r-- | code/fe310/eos/eve/screen/form.c | 82 | ||||
-rw-r--r-- | code/fe310/eos/eve/screen/form.h | 3 | ||||
-rw-r--r-- | code/fe310/eos/eve/screen/page.c | 29 | ||||
-rw-r--r-- | code/fe310/eos/eve/screen/page.h | 11 | ||||
-rw-r--r-- | code/fe310/eos/eve/screen/screen.c | 10 | ||||
-rw-r--r-- | code/fe310/eos/eve/widget/Makefile | 2 | ||||
-rw-r--r-- | code/fe310/eos/eve/widget/page.c | 23 | ||||
-rw-r--r-- | code/fe310/eos/eve/widget/page.h | 4 | ||||
-rw-r--r-- | code/fe310/eos/eve/widget/text.c | 45 | ||||
-rw-r--r-- | code/fe310/eos/eve/widget/text.h | 2 | ||||
-rw-r--r-- | code/fe310/eos/eve/widget/widget.c | 7 | ||||
-rw-r--r-- | code/fe310/eos/eve/widget/widget.h | 4 |
15 files changed, 164 insertions, 75 deletions
diff --git a/code/fe310/eos/eve/eve_kbd.c b/code/fe310/eos/eve/eve_kbd.c index 59cfa23..99210ce 100644 --- a/code/fe310/eos/eve/eve_kbd.c +++ b/code/fe310/eos/eve/eve_kbd.c @@ -135,7 +135,6 @@ uint8_t eve_kbd_draw(EVEKbd *kbd) { int mod_w = key_w + key_w / 2; int key_h = row_h - KEY_SPACERY; - eve_cmd_dl(SAVE_CONTEXT()); eve_cmd(CMD_KEYS, "hhhhhhs", x, y + row_h * 0, w, key_h, KEY_FONT, kbd->key_down, kbd->key_modifier & (FLAG_FN | FLAG_SHIFT) ? "!@#$%^&*()" : (kbd->key_modifier & FLAG_CTRL ? " @[\\]^_? " : "1234567890")); eve_cmd(CMD_KEYS, "hhhhhhs", x, y + row_h * 1, w, key_h, KEY_FONT, kbd->key_down, kbd->key_modifier & FLAG_FN ? "-_=+[]{}\\|" : kbd->key_modifier & (FLAG_SHIFT | FLAG_CTRL) ? "QWERTYUIOP" : "qwertyuiop"); diff --git a/code/fe310/eos/eve/screen/font.c b/code/fe310/eos/eve/screen/font.c index b5b7b74..26e7cf0 100644 --- a/code/fe310/eos/eve/screen/font.c +++ b/code/fe310/eos/eve/screen/font.c @@ -6,3 +6,17 @@ void eve_font_init(EVEFont *font, uint8_t font_id) { font->id = font_id; } + +uint16_t eve_font_string_width(EVEFont *font, char *s) { + uint16_t r = 0; + + while (*s) { + r += font->w[*s]; + s++; + } + return r; +} + +uint8_t eve_font_height(EVEFont *font) { + return font->h; +}
\ No newline at end of file diff --git a/code/fe310/eos/eve/screen/font.h b/code/fe310/eos/eve/screen/font.h index 0572015..24b745e 100644 --- a/code/fe310/eos/eve/screen/font.h +++ b/code/fe310/eos/eve/screen/font.h @@ -7,3 +7,5 @@ typedef struct EVEFont { } EVEFont; void eve_font_init(EVEFont *font, uint8_t font_id); +uint16_t eve_font_string_width(EVEFont *font, char *s); +uint8_t eve_font_height(EVEFont *font); 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); + } +} diff --git a/code/fe310/eos/eve/screen/form.h b/code/fe310/eos/eve/screen/form.h index e667fc8..006ef2e 100644 --- a/code/fe310/eos/eve/screen/form.h +++ b/code/fe310/eos/eve/screen/form.h @@ -4,7 +4,6 @@ struct EVEWidget; typedef struct EVEForm { EVEPage p; - struct EVEWidget *widget_f; struct EVEWidget *widget; uint16_t widget_size; } EVEForm; @@ -12,3 +11,5 @@ typedef struct EVEForm { int eve_form_init(EVEForm *form, struct EVEWidget *widget, uint16_t widget_size, eve_page_open_t open, eve_page_close_t close, EVEWindow *window); int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx); uint8_t eve_form_draw(EVEView *v, uint8_t tag0); +void eve_form_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx); +void eve_form_update_g(EVEPage *page, struct EVEWidget *widget); diff --git a/code/fe310/eos/eve/screen/page.c b/code/fe310/eos/eve/screen/page.c index fbd9327..4c72243 100644 --- a/code/fe310/eos/eve/screen/page.c +++ b/code/fe310/eos/eve/screen/page.c @@ -7,20 +7,24 @@ #include "screen.h" #include "window.h" #include "page.h" +#include "font.h" +#include "widget/label.h" #include "widget/widget.h" -void eve_page_init(EVEPage *page, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_open_t open, eve_page_close_t close, EVEWindow *window) { +void eve_page_init(EVEPage *page, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_open_t open, eve_page_close_t close, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g, EVEWindow *window) { memset(page, 0, sizeof(EVEPage)); page->v.touch = touch; page->v.draw = draw; page->open = open; page->close = close; - page->handle_evt = eve_page_handle_evt; + page->handle_evt = handle_evt; + page->update_g = update_g; + page->widget_f = NULL; page->window = window; } -void eve_page_focus(EVEPage *page, EVERect *f) { +void eve_page_set_focus(EVEPage *page, EVEWidget *widget, EVERect *f) { EVERect g; eve_window_visible_g(page->window, &g); @@ -39,22 +43,17 @@ void eve_page_focus(EVEPage *page, EVERect *f) { if ((f->y + f->h) > (page->win_y + g.y + g.h)) { page->win_y = (f->y + f->h) - (g.y + g.h); } + page->widget_f = widget; } -int eve_page_widget_visible(EVEPage *page, EVEWidget *widget) { +EVEWidget *eve_page_get_focus(EVEPage *page) { + return page->widget_f; +} + +int eve_page_rect_visible(EVEPage *page, EVERect *g) { uint16_t w = page->window->g.w; uint16_t h = page->window->g.h; - if (((widget->g.x + widget->g.w) >= page->win_x) && ((widget->g.y + widget->g.h) >= page->win_y) && (widget->g.x <= (page->win_x + w)) && (widget->g.y <= (page->win_y + h))) return 1; + 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_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 - } - */ -} diff --git a/code/fe310/eos/eve/screen/page.h b/code/fe310/eos/eve/screen/page.h index 42cae7d..a2e5898 100644 --- a/code/fe310/eos/eve/screen/page.h +++ b/code/fe310/eos/eve/screen/page.h @@ -6,6 +6,7 @@ struct EVEWidget; typedef void (*eve_page_open_t) (struct EVEPage *, struct EVEPage *); typedef void (*eve_page_close_t) (struct EVEPage *); typedef void (*eve_page_evt_handler_t) (struct EVEPage *, struct EVEWidget *, EVETouch *, uint16_t, uint8_t, int); +typedef void (*eve_page_g_updater_t) (struct EVEPage *, struct EVEWidget *); typedef struct EVEPage { EVEView v; @@ -14,10 +15,12 @@ typedef struct EVEPage { eve_page_open_t open; eve_page_close_t close; eve_page_evt_handler_t handle_evt; + eve_page_g_updater_t update_g; + struct EVEWidget *widget_f; EVEWindow *window; } EVEPage; -void eve_page_init(EVEPage *page, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_open_t open, eve_page_close_t close, EVEWindow *window); -void eve_page_focus(EVEPage *page, EVERect *focus); -int eve_page_widget_visible(EVEPage *page, struct EVEWidget *widget); -void eve_page_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx); +void eve_page_init(EVEPage *page, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_open_t open, eve_page_close_t close, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g, EVEWindow *window); +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); diff --git a/code/fe310/eos/eve/screen/screen.c b/code/fe310/eos/eve/screen/screen.c index d31cd2c..68b6fb8 100644 --- a/code/fe310/eos/eve/screen/screen.c +++ b/code/fe310/eos/eve/screen/screen.c @@ -81,9 +81,19 @@ void eve_screen_handle_touch(EVEScreen *screen, uint8_t tag0, int touch_idx) { w = w->next; } + eve_cmd_burst_start(); + eve_cmd_dl(CMD_DLSTART); + eve_cmd_dl(CLEAR_COLOR_RGB(0,0,0)); + eve_cmd_dl(CLEAR(1,1,1)); + w = screen->win_head; while(w) { if (eve_window_visible(w)) tagN = w->view->draw(w->view, tagN); w = w->next; } + + eve_cmd_dl(DISPLAY()); + eve_cmd_dl(CMD_SWAP); + eve_cmd_burst_end(); + eve_cmd_exec(1); } diff --git a/code/fe310/eos/eve/widget/Makefile b/code/fe310/eos/eve/widget/Makefile index 844e832..3fe0368 100644 --- a/code/fe310/eos/eve/widget/Makefile +++ b/code/fe310/eos/eve/widget/Makefile @@ -2,7 +2,7 @@ include ../../../common.mk CFLAGS += -I. -I.. -I../.. -obj = widget.o page.o text.o +obj = label.o widget.o page.o text.o %.o: %.c %.h diff --git a/code/fe310/eos/eve/widget/page.c b/code/fe310/eos/eve/widget/page.c index 89177ec..fad44ad 100644 --- a/code/fe310/eos/eve/widget/page.c +++ b/code/fe310/eos/eve/widget/page.c @@ -7,16 +7,22 @@ #include "screen/screen.h" #include "screen/window.h" #include "screen/page.h" +#include "screen/font.h" +#include "label.h" #include "widget.h" #include "page.h" -void eve_pagew_init(EVEPageWidget *widget, EVERect *g, uint8_t font_id, char *title, EVEPage *page) { +void eve_pagew_init(EVEPageWidget *widget, EVERect *g, char *title, EVEFont *font, EVEPage *page) { + EVEWidget *_widget = &widget->w; + memset(widget, 0, sizeof(EVEPageWidget)); - eve_widget_init(&widget->w, EVE_WIDGET_TYPE_PAGE, g, eve_pagew_touch, eve_pagew_draw, NULL); - widget->font_id = font_id; + 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; + if (_widget->g.w == 0) _widget->g.w = eve_font_string_width(font, widget->title); + if (_widget->g.h == 0) _widget->g.h = eve_font_height(font); } int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVERect *focus) { @@ -42,16 +48,13 @@ int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { EVEPageWidget *widget = (EVEPageWidget *)_widget; - char draw = page ? eve_page_widget_visible(page, _widget) : 1; widget->tag = tag0; - if (draw) { - if (tag0 != EVE_TAG_NOTAG) { - eve_cmd_dl(TAG(tag0)); - tag0++; - } - eve_cmd(CMD_TEXT, "hhhhs", _widget->g.x, _widget->g.y, widget->font_id, 0, widget->title); + if (tag0 != EVE_TAG_NOTAG) { + eve_cmd_dl(TAG(tag0)); + tag0++; } + eve_cmd(CMD_TEXT, "hhhhs", _widget->g.x, _widget->g.y, widget->font->id, 0, widget->title); return tag0; } diff --git a/code/fe310/eos/eve/widget/page.h b/code/fe310/eos/eve/widget/page.h index d7f87f0..0b21c95 100644 --- a/code/fe310/eos/eve/widget/page.h +++ b/code/fe310/eos/eve/widget/page.h @@ -3,11 +3,11 @@ typedef struct EVEPageWidget { EVEWidget w; char *title; + EVEFont *font; EVEPage *page; uint8_t tag; - uint8_t font_id; } EVEPageWidget; -void eve_pagew_init(EVEPageWidget *widget, EVERect *g, uint8_t font_id, char *title, EVEPage *page); +void eve_pagew_init(EVEPageWidget *widget, EVERect *g, char *title, EVEFont *font, EVEPage *page); int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVERect *focus); uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); diff --git a/code/fe310/eos/eve/widget/text.c b/code/fe310/eos/eve/widget/text.c index f098a5b..834729f 100644 --- a/code/fe310/eos/eve/widget/text.c +++ b/code/fe310/eos/eve/widget/text.c @@ -9,6 +9,7 @@ #include "screen/page.h" #include "screen/font.h" +#include "label.h" #include "widget.h" #include "text.h" @@ -24,21 +25,23 @@ #define LINE_END(w,l) (w->line[l]) #define LINE_EMPTY 0xffff -#define PAGE_WIN_X(p) (p ? p->win_x : 0) +#define PAGE_WIN_X(p) ((p) ? (p)->win_x : 0) void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEFont *font, char *text, uint64_t text_size, uint16_t *line, uint16_t line_size) { + EVEWidget *_widget = &widget->w; + memset(widget, 0, sizeof(EVETextWidget)); - eve_widget_init(&widget->w, EVE_WIDGET_TYPE_TEXT, g, eve_textw_touch, eve_textw_draw, eve_textw_putc); + eve_widget_init(_widget, EVE_WIDGET_TYPE_TEXT, g, eve_textw_touch, eve_textw_draw, eve_textw_putc); widget->text = text; widget->text_size = text_size; widget->line = line; widget->line_size = line_size; widget->font = font; - if (text_size && line_size) eve_textw_update(widget, 0); + if (text_size && line_size) eve_textw_update(widget, NULL, 0); } static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page, EVETouch *t, short *dx, short *dl) { - EVEWidget *_widget = (EVEWidget *)widget; + EVEWidget *_widget = &widget->w; int x = t->x0 + PAGE_WIN_X(page) - _widget->g.x; int l = (int)t->tag0 - widget->tag0 + widget->line0; int _dx, _dl; @@ -134,7 +137,7 @@ int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i } 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 = (EVEWidget *)widget; + EVEWidget *_widget = &widget->w; if (x1 != x2) { if (widget->tagN != EVE_TAG_NOTAG) { @@ -156,7 +159,7 @@ static void _draw_line(EVETextWidget *widget, uint16_t l, uint16_t ch, uint16_t static void _draw_cursor(EVETextWidget *widget, EVETextCursor *cursor) { uint16_t x, y; - EVEWidget *_widget = (EVEWidget *)widget; + EVEWidget *_widget = &widget->w; x = _widget->g.x + cursor->x; y = _widget->g.y + cursor->line * widget->font->h; @@ -209,10 +212,6 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { c2 = NULL; } - eve_cmd_dl(SAVE_CONTEXT()); - eve_cmd_dl(VERTEX_FORMAT(0)); - eve_cmd_dl(LINE_WIDTH(1)); - for (i=line0; i<lineN; i++) { if (c1 && !s && (c1->line == i)) { int l1, l2, l3; @@ -254,7 +253,6 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { _draw_line(widget, lineN, 0, 0, 0, _widget->g.w, 0); if (widget->tagN != EVE_TAG_NOTAG) widget->tagN++; } - eve_cmd_dl(RESTORE_CONTEXT()); return widget->tagN; } else { @@ -266,9 +264,10 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { } } -void eve_textw_putc(void *_w, int c) { +void eve_textw_putc(void *_page, int c) { int i, r; - EVETextWidget *widget = (EVETextWidget *)_w; + EVEPage *page = _page; + EVETextWidget *widget = (EVETextWidget *)eve_page_get_focus(page); EVETextCursor *cursor1 = &widget->cursor1; EVETextCursor *cursor2 = &widget->cursor2; @@ -316,8 +315,8 @@ void eve_textw_putc(void *_w, int c) { widget->line[i] += m; } r = cursor1->line; - if (cursor1->line) r = eve_textw_update(widget, cursor1->line - 1); - if (r == cursor1->line) r = eve_textw_update(widget, cursor1->line); + if (cursor1->line) r = eve_textw_update(widget, page, cursor1->line - 1); + if (r == cursor1->line) r = eve_textw_update(widget, page, cursor1->line); if (r < 0) return; if (cursor1->ch > widget->text_len) cursor1->ch = widget->text_len; @@ -333,12 +332,13 @@ void eve_textw_putc(void *_w, int c) { } } -int eve_textw_update(EVETextWidget *widget, uint16_t line) { +int eve_textw_update(EVETextWidget *widget, EVEPage *page, uint16_t line) { int i; char ch; uint8_t ch_w; uint16_t word_w, line_w, line_b; - EVEWidget *_widget = (EVEWidget *)widget; + uint16_t new_h; + EVEWidget *_widget = &widget->w; word_w = 0; line_w = 0; @@ -386,10 +386,17 @@ int eve_textw_update(EVETextWidget *widget, uint16_t line) { widget->text_len = i; widget->line_len = line; - _widget->g.h = (line + 1) * widget->font->h; + new_h = (line + 1) * widget->font->h; for (i=line; i<widget->line_size; i++) { widget->line[i] = LINE_EMPTY; } + + if (_widget->g.h != new_h) { + _widget->g.h = new_h; + if (page && page->update_g) page->update_g(page, _widget); + } + + return line; } void eve_textw_cursor_update(EVETextWidget *widget, EVETextCursor *cursor) { @@ -408,7 +415,7 @@ void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t int i; uint16_t _x, _d; uint16_t c_line = LINE_EMPTY; - EVEWidget *_widget = (EVEWidget *)widget; + EVEWidget *_widget = &widget->w; if ((tag >= widget->tag0) && ((widget->tagN == EVE_TAG_NOTAG) || (tag < widget->tagN))) c_line = tag - widget->tag0 + widget->line0; if (c_line < widget->line_len) { diff --git a/code/fe310/eos/eve/widget/text.h b/code/fe310/eos/eve/widget/text.h index 57798ee..b66d100 100644 --- a/code/fe310/eos/eve/widget/text.h +++ b/code/fe310/eos/eve/widget/text.h @@ -34,7 +34,7 @@ void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEFont *font, char *text int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVERect *focus); uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); void eve_textw_putc(void *_w, int c); -int eve_textw_update(EVETextWidget *widget, uint16_t line); +int eve_textw_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(EVETextCursor *cursor); diff --git a/code/fe310/eos/eve/widget/widget.c b/code/fe310/eos/eve/widget/widget.c index 2e253b3..c61a09a 100644 --- a/code/fe310/eos/eve/widget/widget.c +++ b/code/fe310/eos/eve/widget/widget.c @@ -9,6 +9,7 @@ #include "screen/page.h" #include "screen/font.h" +#include "label.h" #include "widget.h" #include "page.h" #include "text.h" @@ -20,11 +21,15 @@ static const size_t _eve_wsize[] = { }; 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) { - widget->type = type; if (g) widget->g = *g; widget->touch = touch; widget->draw = draw; widget->putc = putc; + widget->type = type; +} + +void eve_widget_set_label(EVEWidget *widget, EVELabel *label) { + widget->label = label; } EVEWidget *eve_widget_next(EVEWidget *widget) { diff --git a/code/fe310/eos/eve/widget/widget.h b/code/fe310/eos/eve/widget/widget.h index e6ea7a7..25e1b59 100644 --- a/code/fe310/eos/eve/widget/widget.h +++ b/code/fe310/eos/eve/widget/widget.h @@ -9,12 +9,14 @@ typedef int (*eve_widget_touch_t) (struct EVEWidget *, EVEPage *, uint8_t, int, typedef uint8_t (*eve_widget_draw_t) (struct EVEWidget *, EVEPage *, uint8_t); typedef struct EVEWidget { - uint8_t type; EVERect g; eve_widget_touch_t touch; eve_widget_draw_t draw; eve_kbd_input_handler_t putc; + EVELabel *label; + uint8_t type; } 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); +void eve_widget_set_label(EVEWidget *widget, EVELabel *label); EVEWidget *eve_widget_next(EVEWidget *widget); |