From 0ebaa6f7c2ae1cb7e72d8b5ff4b34e3fe7c5ace8 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sat, 11 Jul 2020 14:17:12 +0200 Subject: page focus interface changed; widget is responsible for setting focus --- code/fe310/eos/eve/widget/pagew.c | 3 +-- code/fe310/eos/eve/widget/pagew.h | 2 +- code/fe310/eos/eve/widget/strw.c | 23 +++++++++++++---------- code/fe310/eos/eve/widget/strw.h | 2 +- code/fe310/eos/eve/widget/textw.c | 27 +++++++++++++++------------ code/fe310/eos/eve/widget/textw.h | 3 +-- code/fe310/eos/eve/widget/widget.h | 2 +- 7 files changed, 33 insertions(+), 29 deletions(-) (limited to 'code/fe310/eos/eve/widget') diff --git a/code/fe310/eos/eve/widget/pagew.c b/code/fe310/eos/eve/widget/pagew.c index 51393e0..8c3b515 100644 --- a/code/fe310/eos/eve/widget/pagew.c +++ b/code/fe310/eos/eve/widget/pagew.c @@ -25,7 +25,7 @@ void eve_pagew_init(EVEPageWidget *widget, EVERect *g, char *title, EVEFont *fon if (_widget->g.h == 0) _widget->g.h = eve_font_h(font); } -int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVERect *focus) { +int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) { EVEPageWidget *widget = (EVEPageWidget *)_widget; EVETouch *t; uint16_t evt; @@ -39,7 +39,6 @@ int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i if (page && page->handle_evt) page->handle_evt(page, _widget, t, evt, tag0, touch_idx); } else if (evt & EVE_TOUCH_ETYPE_TAG_UP) { widget->page->open(widget->page, page); - if (focus) *focus = _widget->g; } ret = 1; } diff --git a/code/fe310/eos/eve/widget/pagew.h b/code/fe310/eos/eve/widget/pagew.h index 0b21c95..1f9ae18 100644 --- a/code/fe310/eos/eve/widget/pagew.h +++ b/code/fe310/eos/eve/widget/pagew.h @@ -9,5 +9,5 @@ typedef struct EVEPageWidget { } EVEPageWidget; 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); +int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx); uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); diff --git a/code/fe310/eos/eve/widget/strw.c b/code/fe310/eos/eve/widget/strw.c index d7b4729..82e86b7 100644 --- a/code/fe310/eos/eve/widget/strw.c +++ b/code/fe310/eos/eve/widget/strw.c @@ -41,6 +41,17 @@ void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEFont *font, char *str, u if (_widget->g.h == 0) _widget->g.h = eve_font_h(font); } +static void set_focus(EVEStrWidget *widget, EVEPage *page) { + EVERect focus; + EVEWidget *_widget = &widget->w; + + focus.x = _widget->g.x; + focus.y = _widget->g.y; + focus.w = _widget->g.w; + 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) { EVEWidget *_widget = &widget->w; int x = eve_page_x(page, t->x0) - _widget->g.x + widget->str_g.x; @@ -53,7 +64,7 @@ static EVEStrCursor *cursor_prox(EVEStrWidget *widget, EVEStrCursor *cursor, EVE return NULL; } -int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVERect *focus) { +int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) { EVEStrWidget *widget = (EVEStrWidget *)_widget; EVETouch *t; uint16_t evt; @@ -64,7 +75,6 @@ int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_id if (t && evt) { EVEStrCursor *t_cursor = NULL; short dx; - char f = 0; if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) { if (widget->cursor2.on) { @@ -126,7 +136,7 @@ int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_id 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); - f = 1; + set_focus(widget, page); } break; } @@ -137,13 +147,6 @@ int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_id widget->track.dx = 0; } - if (f && focus) { - focus->x = _widget->g.x; - focus->y = _widget->g.y; - focus->w = _widget->g.w; - focus->h = 2 * widget->font->h; - } - return 1; } diff --git a/code/fe310/eos/eve/widget/strw.h b/code/fe310/eos/eve/widget/strw.h index 04a813e..1277c20 100644 --- a/code/fe310/eos/eve/widget/strw.h +++ b/code/fe310/eos/eve/widget/strw.h @@ -28,7 +28,7 @@ typedef struct EVEStrWidget { } EVEStrWidget; void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEFont *font, char *str, uint16_t str_size); -int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVERect *focus); +int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx); uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); void eve_strw_putc(void *_page, int c); void eve_strw_cursor_set(EVEStrWidget *widget, EVEStrCursor *cursor, int16_t x); diff --git a/code/fe310/eos/eve/widget/textw.c b/code/fe310/eos/eve/widget/textw.c index 47f5aa2..0f230aa 100644 --- a/code/fe310/eos/eve/widget/textw.c +++ b/code/fe310/eos/eve/widget/textw.c @@ -45,6 +45,17 @@ void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEFont *font, char *text if (text_size && line_size) eve_textw_update(widget, NULL, 0); } +static void set_focus(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page) { + EVERect focus; + EVEWidget *_widget = &widget->w; + + focus.x = _widget->g.x; + focus.y = _widget->g.y + cursor->line * widget->font->h; + focus.w = _widget->g.w; + 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) { EVEWidget *_widget = &widget->w; int x = eve_page_x(page, t->x0) - _widget->g.x; @@ -61,7 +72,7 @@ static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, return NULL; } -int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVERect *focus) { +int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) { EVETextWidget *widget = (EVETextWidget *)_widget; EVETouch *t; uint16_t evt; @@ -119,7 +130,7 @@ int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i 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); - widget->cursor_f = &widget->cursor1; + set_focus(widget, &widget->cursor1, page); } break; } @@ -134,14 +145,6 @@ int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i ret = 1; } - if (widget->cursor_f && focus) { - focus->x = _widget->g.x; - focus->y = _widget->g.y + widget->cursor_f->line * widget->font->h; - focus->w = _widget->g.w; - focus->h = 2 * widget->font->h; - widget->cursor_f = NULL; - } - return ret; } @@ -373,12 +376,12 @@ void eve_textw_putc(void *_page, int c) { if (cursor1->line && (cursor1->ch < LINE_START(widget, cursor1->line))) { cursor1->line--; - widget->cursor_f = cursor1; eve_textw_cursor_update(widget, cursor1); + set_focus(widget, cursor1, page); } else if (cursor1->ch > LINE_END(widget, cursor1->line)) { while (cursor1->ch > LINE_END(widget, cursor1->line)) cursor1->line++; - widget->cursor_f = cursor1; eve_textw_cursor_update(widget, cursor1); + set_focus(widget, cursor1, page); } else { cursor1->x += ch_w; } diff --git a/code/fe310/eos/eve/widget/textw.h b/code/fe310/eos/eve/widget/textw.h index 68176f1..ee3eefb 100644 --- a/code/fe310/eos/eve/widget/textw.h +++ b/code/fe310/eos/eve/widget/textw.h @@ -18,7 +18,6 @@ typedef struct EVETextWidget { uint16_t line_len; EVETextCursor cursor1; EVETextCursor cursor2; - EVETextCursor *cursor_f; uint16_t line0; uint8_t tag0; uint8_t tagN; @@ -31,7 +30,7 @@ typedef struct EVETextWidget { } EVETextWidget; void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEFont *font, char *text, uint16_t text_size, uint16_t *line, uint16_t line_size); -int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVERect *focus); +int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx); uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); void eve_textw_putc(void *_w, int c); int eve_textw_update(EVETextWidget *widget, EVEPage *page, uint16_t line); diff --git a/code/fe310/eos/eve/widget/widget.h b/code/fe310/eos/eve/widget/widget.h index 7083be3..1aa2cd7 100644 --- a/code/fe310/eos/eve/widget/widget.h +++ b/code/fe310/eos/eve/widget/widget.h @@ -6,7 +6,7 @@ struct EVEWidget; -typedef int (*eve_widget_touch_t) (struct EVEWidget *, EVEPage *, uint8_t, int, EVERect *); +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 { -- cgit v1.2.3