diff options
author | Uros Majstorovic <majstor@majstor.org> | 2022-09-04 18:16:20 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2022-09-04 18:16:20 +0200 |
commit | ec0caa569b356f186e87c13e50550ca1b807dde6 (patch) | |
tree | ab07671a8aed9c573fe20d2d100be0ab1c5e68a7 /fw/fe310/eos/eve/screen/form.c | |
parent | 7f8e473ac12191ca4449de96033e2acda07dc4c4 (diff) |
eve support when i2s is running
Diffstat (limited to 'fw/fe310/eos/eve/screen/form.c')
-rw-r--r-- | fw/fe310/eos/eve/screen/form.c | 134 |
1 files changed, 71 insertions, 63 deletions
diff --git a/fw/fe310/eos/eve/screen/form.c b/fw/fe310/eos/eve/screen/form.c index 13021a0..3e5b97c 100644 --- a/fw/fe310/eos/eve/screen/form.c +++ b/fw/fe310/eos/eve/screen/form.c @@ -12,39 +12,6 @@ #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) -static void form_update_g(EVEForm *form, EVEWidget *_widget) { - EVEPage *page = &form->p; - EVEWidget *widget = page->widget; - int i; - uint16_t w = 0; - uint16_t h = 0; - uint16_t l_h = 0; - - for (i=0; i<page->widget_size; i++) { - if (widget->label) { - h += l_h; - w = widget->label->g.w; - l_h = widget->label->g.h; - widget->label->g.x = 0; - widget->label->g.y = h; - } - if (w + widget->g.w > form->p.v.window->g.w) { - h += l_h; - w = 0; - l_h = 0; - } - widget->g.x = w; - widget->g.y = h; - - w += widget->g.w; - l_h = MAX(l_h, widget->g.h); - - widget = eve_widget_next(widget); - } - page->g.w = page->v.window->g.w; - page->g.h = h + l_h; -} - static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) { int i; @@ -55,38 +22,38 @@ static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) { } } -EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEFormSpec spec[], uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor) { +EVEPage *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEFormSpec spec[], uint16_t spec_size, eve_page_uievt_t uievt, eve_page_destructor_t destructor) { EVEWidget *widgets; EVEWidget *widget; EVELabel *label; - EVEForm *form; + EVEPage *page; int w_size = 0; int i, r; if (uievt == NULL) uievt = eve_form_uievt; if (destructor == NULL) destructor = eve_form_destroy; - form = eve_malloc(sizeof(EVEForm)); - if (form == NULL) { + page = eve_malloc(sizeof(EVEPage)); + if (page == NULL) { return NULL; } - eve_form_init(form, window, stack, NULL, 0, uievt, action, destructor); + eve_form_init(page, window, stack, NULL, 0, uievt, destructor); for (i=0; i<spec_size; i++) { w_size += eve_widget_size(spec[i].widget.type); } widgets = eve_malloc(w_size); if (widgets == NULL) { - eve_free(form); + eve_free(page); return NULL; } widget = widgets; for (i=0; i<spec_size; i++) { - r = eve_widget_create(widget, &spec[i].widget, (EVEPage *)form); + r = eve_widget_create(widget, &spec[i].widget, page); if (r) { widgets_destroy(widgets, i); eve_free(widgets); - eve_free(form); + eve_free(page); return NULL; } if (spec[i].label.title) { @@ -95,42 +62,46 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEFormSpec spe eve_widget_destroy(widget); widgets_destroy(widgets, i); eve_free(widgets); - eve_free(form); + eve_free(page); return NULL; } - eve_label_create(label, &spec[i].label, (EVEPage *)form); + eve_label_create(label, &spec[i].label, page); eve_widget_set_label(widget, label); } if (widget->g.w == 0) widget->g.w = window->g.w - (widget->label ? widget->label->g.w : 0); widget = eve_widget_next(widget); } - eve_form_set_widget(form, widgets, spec_size); + eve_form_set_widget(page, widgets, spec_size); - return form; + return page; } -void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor) { - memset(form, 0, sizeof(EVEForm)); - eve_page_init(&form->p, window, stack, NULL, 0, EVE_PAGE_OPT_SCROLL_Y | EVE_PAGE_OPT_SCROLL_BACK | EVE_PAGE_OPT_TRACK_EXT_Y, eve_page_draw, eve_page_touch, (eve_view_uievt_t)uievt, (eve_page_destructor_t)destructor); - form->action = action; - eve_form_set_widget(form, widget, widget_size); +void eve_form_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_page_uievt_t uievt, eve_page_destructor_t destructor) { + eve_page_init(page, window, stack, NULL, 0, EVE_PAGE_OPT_SCROLL_Y | EVE_PAGE_OPT_SCROLL_BACK | EVE_PAGE_OPT_TRACK_EXT_Y, eve_page_draw, eve_page_touch, uievt, destructor); + if (widget) eve_form_set_widget(page, widget, widget_size); } -void eve_form_set_widget(EVEForm *form, EVEWidget *widget, uint16_t widget_size) { - eve_page_set_widget((EVEPage *)form, widget, widget_size); - form_update_g(form, NULL); +void eve_form_set_widget(EVEPage *page, EVEWidget *widget, uint16_t widget_size) { + eve_page_set_widget(page, widget, widget_size); + eve_form_update_g(page, NULL); } -void eve_form_destroy(EVEForm *form) { - widgets_destroy(form->p.widget, form->p.widget_size); - eve_free(form->p.widget); - eve_free(form); +void eve_form_destroy(EVEPage *page) { + widgets_destroy(page->widget, page->widget_size); + eve_free(page->widget); + eve_free(page); } -int eve_form_uievt(EVEForm *form, uint16_t evt, void *param) { +int eve_form_uievt(EVEPage *page, uint16_t evt, void *param) { switch (evt) { case EVE_UIEVT_WIDGET_UPDATE_G: - form_update_g(form, (EVEWidget *)param); + eve_form_update_g(page, (EVEWidget *)param); + break; + + case EVE_UIEVT_WIDGET_FOCUS_IN: + break; + + case EVE_UIEVT_WIDGET_FOCUS_OUT: break; case EVE_UIEVT_GEST_SCROLL_START: @@ -146,14 +117,51 @@ int eve_form_uievt(EVEForm *form, uint16_t evt, void *param) { EVEUIEvtTouch *touch_p = (EVEUIEvtTouch *)param; if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT) { - eve_page_close((EVEPage *)form); + eve_page_close(page); return 1; } - if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) { - if (form->action) form->action(form); - } break; } } return 0; } + +void eve_form_update_g(EVEPage *page, EVEWidget *_widget) { + EVEWidget *widget = page->widget; + EVEWidget *lastw = NULL; + int i; + uint16_t w = 0; + uint16_t h = 0; + uint16_t l_h = 0; + + for (i=0; i<page->widget_size; i++) { + if (widget->flags & EVE_WIDGET_FLAG_HIDDEN) goto update_g_nextw; + if (widget->label) { + h += l_h; + w = widget->label->g.w; + l_h = widget->label->g.h; + widget->label->g.x = 0; + widget->label->g.y = h; + } + if (w + widget->g.w > page->v.window->g.w) { + h += l_h; + w = 0; + l_h = 0; + } + widget->g.x = w; + widget->g.y = h; + + w += widget->g.w; + l_h = MAX(l_h, widget->g.h); + + lastw = widget; +update_g_nextw: + widget = eve_widget_next(widget); + } + page->g.w = page->v.window->g.w; + page->g.h = h + l_h; + + if (lastw && eve_page_oob(page, NULL, NULL)) { + eve_page_show_rect(page, &lastw->g); + } +} |