summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve/screen/page.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos/eve/screen/page.c')
-rw-r--r--fw/fe310/eos/eve/screen/page.c135
1 files changed, 94 insertions, 41 deletions
diff --git a/fw/fe310/eos/eve/screen/page.c b/fw/fe310/eos/eve/screen/page.c
index 64fc473..9cbc638 100644
--- a/fw/fe310/eos/eve/screen/page.c
+++ b/fw/fe310/eos/eve/screen/page.c
@@ -14,25 +14,47 @@
#define PAGE_TMODE_TRACK 1
#define PAGE_TMODE_SCROLL 2
-void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, uint8_t opt, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, eve_page_destructor_t destructor) {
+void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, uint8_t opt, eve_page_draw_t draw, eve_page_touch_t touch, eve_page_uievt_t uievt, eve_page_destructor_t destructor) {
memset(page, 0, sizeof(EVEPage));
- eve_view_init(&page->v, window, draw, touch, uievt, NULL);
+ eve_view_init(&page->v, window, (eve_view_draw_t)draw, (eve_view_touch_t)touch, (eve_view_uievt_t)uievt, NULL);
page->stack = stack;
page->opt = opt;
page->destructor = destructor;
eve_page_set_widget(page, widget, widget_size);
}
-EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx) {
+EVEWidget *eve_page_widget(EVEPage *page, uint16_t _idx) {
EVEWidget *w = page->widget;
- int i;
+ int i, idx;
+
+ if (_idx >= page->widget_size) return NULL;
+
+ idx = 0;
+ for (i=0; i<page->widget_size; i++) {
+ if (!(w->flags & EVE_WIDGET_FLAG_SKIP)) {
+ if (idx == _idx) {
+ return w;
+ }
+ idx++;
+ }
+ w = eve_widget_next(w);
+ }
+ return NULL;
+}
- if (idx >= page->widget_size) return NULL;
+EVEWidget *eve_page_widget_search(EVEPage *page, char *label) {
+ EVEWidget *w = page->widget;
+ int i;
- for (i=0; i<idx; i++) {
+ for (i=0; i<page->widget_size; i++) {
+ if (!(w->flags & EVE_WIDGET_FLAG_SKIP)) {
+ if (w->label && (strcmp(w->label->title, label) == 0)) {
+ return w;
+ }
+ }
w = eve_widget_next(w);
}
- return w;
+ return NULL;
}
void eve_page_set_widget(EVEPage *page, EVEWidget *widget, uint16_t widget_size) {
@@ -45,8 +67,9 @@ void eve_page_open(EVEPage *parent, eve_view_constructor_t constructor) {
EVEViewStack *stack = parent->stack;
eve_page_destructor_t destructor = parent->destructor;
+ eve_page_set_focus(parent, NULL);
if (destructor) destructor(parent);
- eve_view_create(window, stack, constructor);
+ eve_stack_create_view(stack, window, constructor);
}
void eve_page_close(EVEPage *page) {
@@ -56,6 +79,7 @@ void eve_page_close(EVEPage *page) {
if (stack->level <= 1) return;
+ eve_page_set_focus(page, NULL);
if (eve_timer_running()) {
eve_timer_stop();
}
@@ -66,7 +90,7 @@ void eve_page_close(EVEPage *page) {
eve_window_kbd_detach(window);
if (destructor) destructor(page);
- eve_view_destroy(window, stack);
+ eve_stack_back(stack, window);
}
/* Screen to page coordinates */
@@ -104,7 +128,7 @@ int eve_page_rect_visible(EVEPage *page, EVERect *g) {
return 0;
}
-void eve_page_rect_set_visible(EVEPage *page, EVERect *rect) {
+void eve_page_show_rect(EVEPage *page, EVERect *rect) {
EVERect g;
eve_window_visible_g(page->v.window, &g);
@@ -125,11 +149,27 @@ void eve_page_rect_set_visible(EVEPage *page, EVERect *rect) {
}
}
+/* returns true if x or y are out of page bounds for window */
+int eve_page_oob(EVEPage *page, int *_max_x, int *_max_y) {
+ int max_x, max_y;
+ EVERect vg;
+
+ eve_window_visible_g(page->v.window, &vg);
+ max_x = page->g.w > vg.w ? page->g.w - vg.w : 0;
+ max_y = page->g.h > vg.h ? page->g.h - vg.h : 0;
+
+ if (_max_x) *_max_x = max_x;
+ if (_max_y) *_max_y = max_y;
+
+ return ((page->g.x < 0) || (page->g.x > max_x) ||
+ (page->g.y < 0) || (page->g.y > max_y));
+}
+
EVEWidget *eve_page_focus(EVEPage *page) {
return page->widget_f;
}
-void eve_page_set_focus(EVEPage *page, EVEWidget *widget, EVERect *rect) {
+void eve_page_set_focus(EVEPage *page, EVEWidget *widget) {
if (page->widget_f != widget) {
EVEWindow *window = page->v.window;
EVEWidget *widget_f = page->widget_f;
@@ -148,11 +188,8 @@ void eve_page_set_focus(EVEPage *page, EVEWidget *widget, EVERect *rect) {
page->widget_f = widget;
if (page->widget_f) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_FOCUS_IN, page->widget_f);
}
- if (rect) eve_page_rect_set_visible(page, rect);
}
-#include <stdio.h>
-
static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0) {
EVEView *view = &page->v;
EVEWindow *window = view->window;
@@ -174,7 +211,7 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0
if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(touch->eevt & (EVE_TOUCH_EETYPE_TRACK_XY | EVE_TOUCH_EETYPE_ABORT))) {
int _ret = 0;
- if (page->widget_f) eve_page_set_focus(page, NULL, NULL);
+ eve_page_set_focus(page, NULL);
_ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_TOUCH, touch, evt, tag0);
if (_ret) return _ret;
ret = 1;
@@ -200,20 +237,17 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0
if (((evt & EVE_TOUCH_ETYPE_TRACK_STOP) && !(evt & EVE_TOUCH_ETYPE_TRACK_ABORT)) ||
((evt & EVE_TOUCH_ETYPE_POINT_UP) && (touch->eevt & EVE_TOUCH_EETYPE_ABORT) && !(touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY))) {
if ((page->track_mode == PAGE_TMODE_SCROLL) && (page->opt & EVE_PAGE_OPT_SCROLL_BACK)) {
- int wmax_x, wmax_y;
- int lho_x, lho_y;
- EVERect vg;
-
- eve_window_visible_g(page->v.window, &vg);
- wmax_x = page->g.w > vg.w ? page->g.w - vg.w : 0;
- wmax_y = page->g.h > vg.h ? page->g.h - vg.h : 0;
- lho_x = page->g.x < 0 ? 0 : wmax_x;
- lho_y = page->g.y < 0 ? 0 : wmax_y;
- if ((page->g.x < 0) || (page->g.x > wmax_x) ||
- (page->g.y < 0) || (page->g.y > wmax_y)) {
- EVEPhyLHO *lho = &page->lho;
+ int max_x, max_y;
+ int oob;
+
+ oob = eve_page_oob(page, &max_x, &max_y);
+ if (oob) {
+ int lho_x, lho_y;
uint8_t _tag;
+ EVEPhyLHO *lho = &page->lho;
+ lho_x = page->g.x < 0 ? 0 : max_x;
+ lho_y = page->g.y < 0 ? 0 : max_y;
eve_window_scroll(window->root, &_tag);
page->lho_t0 = eve_get_tick();
@@ -272,11 +306,9 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0
more = eve_phy_lho_tick(lho, eve_get_tick() - page->lho_t0, scroll_x ? &x : NULL, scroll_y ? &y : NULL);
if (scroll_x) page->g.x = x;
if (scroll_y) page->g.y = y;
- printf("TIMER: %d\n", y);
if (!more) {
int _ret = 0;
- printf("TIMER STOP!\n");
page->track_mode = PAGE_TMODE_NONE;
eve_timer_stop();
eve_window_scroll_stop(window);
@@ -290,8 +322,8 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0
return ret;
}
-uint8_t eve_page_draw(EVEView *view, uint8_t tag0) {
- EVEPage *page = (EVEPage *)view;
+uint8_t eve_page_draw(EVEPage *page, uint8_t tag0) {
+ EVEView *view = &page->v;
EVEWidget *widget = page->widget;
int i;
uint8_t tagN = tag0;
@@ -308,6 +340,8 @@ uint8_t eve_page_draw(EVEView *view, uint8_t tag0) {
eve_cmd_dl(VERTEX_TRANSLATE_X(eve_page_scr_x(page, 0) * 16));
eve_cmd_dl(VERTEX_TRANSLATE_Y(eve_page_scr_y(page, 0) * 16));
for (i=0; i<page->widget_size; i++) {
+ if (widget->flags & EVE_WIDGET_FLAG_HIDDEN) goto draw_nextw;
+
if (widget->label && eve_page_rect_visible(page, &widget->label->g)) {
eve_cmd_dl(TAG_MASK(0));
eve_label_draw(widget->label);
@@ -316,6 +350,8 @@ uint8_t eve_page_draw(EVEView *view, uint8_t tag0) {
if (eve_page_rect_visible(page, &widget->g)) {
tagN = widget->draw(widget, tagN);
}
+
+draw_nextw:
widget = eve_widget_next(widget);
}
eve_cmd_dl(RESTORE_CONTEXT());
@@ -327,9 +363,9 @@ uint8_t eve_page_draw(EVEView *view, uint8_t tag0) {
return tagN;
}
-int eve_page_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) {
- EVEPage *page = (EVEPage *)view;
+int eve_page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0) {
EVEWidget *widget = page->widget;
+ EVEViewStack *stack = page->stack;
int8_t touch_idx = eve_touch_get_idx(touch);
uint16_t _evt;
int i, ret;
@@ -339,20 +375,37 @@ int eve_page_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) {
_evt = eve_touch_evt(touch, evt, tag0, page->v.tag, 1);
if (_evt) {
ret = page_touch(page, touch, _evt, tag0);
+ if (stack->dirty) {
+ stack->dirty = 0;
+ return 1;
+ }
if (ret) return 1;
}
for (i=0; i<page->widget_size; i++) {
- if (eve_page_rect_visible(page, &widget->g)) {
- _evt = eve_touch_evt(touch, evt, tag0, widget->tag0, widget->tagN - widget->tag0);
- if (_evt) {
- if (page->track_mode == PAGE_TMODE_NONE) {
- ret = widget->touch(widget, touch, _evt);
- if (ret) return 1;
+ if (!eve_page_rect_visible(page, &widget->g) || (widget->flags & (EVE_WIDGET_FLAG_SKIP | EVE_WIDGET_FLAG_RO | EVE_WIDGET_FLAG_HIDDEN))) goto touch_nextw;
+
+ _evt = eve_touch_evt(touch, evt, tag0, widget->tag0, widget->tagN - widget->tag0);
+ if (_evt) {
+ if (page->track_mode == PAGE_TMODE_NONE) {
+ ret = widget->touch(widget, touch, _evt);
+ if (stack->dirty) {
+ stack->dirty = 0;
+ return 1;
+ }
+ if (ret) {
+ eve_widget_set_focus(widget);
+ return 1;
}
- ret = page_touch(page, touch, _evt, tag0);
- if (ret) return 1;
}
+ ret = page_touch(page, touch, _evt, tag0);
+ if (stack->dirty) {
+ stack->dirty = 0;
+ return 1;
+ }
+ if (ret) return 1;
}
+
+touch_nextw:
widget = eve_widget_next(widget);
}