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/widget | |
parent | b5aa60b256dd2b328515779883ba365aba3d995f (diff) |
page/form refactor; implemented form layout, labels
Diffstat (limited to 'code/fe310/eos/eve/widget')
-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 |
7 files changed, 52 insertions, 35 deletions
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); |