diff options
author | Uros Majstorovic <majstor@majstor.org> | 2021-02-28 21:51:55 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2021-02-28 21:51:55 +0100 |
commit | 0a11eb9d378d66387dca3178e1bd2c62e61174bd (patch) | |
tree | fdbf40ecf442cd45c3274df328b3993bfc9a1696 | |
parent | 3d67aa36fdf8164cf367acc71b8d7fe55fd10cc6 (diff) |
added app form
-rw-r--r-- | fw/fe310/eos/app/app_form.c | 99 | ||||
-rw-r--r-- | fw/fe310/eos/app/app_form.h | 7 |
2 files changed, 106 insertions, 0 deletions
diff --git a/fw/fe310/eos/app/app_form.c b/fw/fe310/eos/app/app_form.c new file mode 100644 index 0000000..ffb416b --- /dev/null +++ b/fw/fe310/eos/app/app_form.c @@ -0,0 +1,99 @@ +#include <stdlib.h> + +#include "unicode.h" + +#include "eve/eve.h" +#include "eve/eve_kbd.h" +#include "eve/eve_font.h" + +#include "eve/screen/screen.h" +#include "eve/screen/window.h" +#include "eve/screen/view.h" +#include "eve/screen/page.h" +#include "eve/screen/form.h" + +#include "eve/widget/widgets.h" + +#include "app_screen.h" +#include "app_form.h" + +static EVEFont font; + +static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) { + int i; + + for (i=0; i<widget_size; i++) { + if (widget->label) eve_free(widget->label); + eve_widget_destroy(widget); + widget = eve_widget_next(widget); + } +} + +EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec spec[], uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor) { + EVEWidget *widgets; + EVEWidget *widget; + EVELabel *label; + EVEForm *form; + EVEFont *_font; + int w_size = 0; + int i, r; + + for (i=0; i<spec_size; i++) { + w_size += eve_widget_size(spec[i].widget.type); + } + form = eve_malloc(sizeof(EVEForm)); + if (form == NULL) { + return NULL; + } + + widgets = eve_malloc(w_size); + if (widgets == NULL) { + eve_free(form); + return NULL; + } + + widget = widgets; + for (i=0; i<spec_size; i++) { + _font = spec[i].widget.font ? spec[i].widget.font : &font; + r = eve_widget_create(widget, spec[i].widget.type, &spec[i].widget.g, _font, &spec[i].widget.spec); + if (r) { + widgets_destroy(widgets, i); + eve_free(widgets); + eve_free(form); + return NULL; + } + if (spec[i].label.title) { + _font = spec[i].label.font ? spec[i].label.font : &font; + label = eve_malloc(sizeof(EVELabel)); + if (label == NULL) { + eve_widget_destroy(widget); + widgets_destroy(widgets, i); + eve_free(widgets); + eve_free(form); + return NULL; + } + eve_label_init(label, &spec[i].label.g, _font, spec[i].label.title); + eve_widget_set_label(widget, label); + } + if (widget->label && (widget->label->g.w == 0)) eve_font_str_w(label->font, label->title) + APP_LABEL_MARGIN; + if (widget->g.w == 0) widget->g.w = APP_SCREEN_W - (widget->label ? widget->label->g.w : 0); + widget = eve_widget_next(widget); + } + + if (destructor == NULL) destructor = app_form_destroy; + eve_form_init(form, window, stack, widgets, spec_size, action, destructor); + + return form; +} + +void app_form_destroy(EVEForm *form) { + widgets_destroy(form->widget, form->widget_size); + eve_free(form->widget); + eve_free(form); +} + +void app_form_init(void) { + eve_spi_start(); + eve_font_init(&font, APP_FONT_HANDLE); + eve_spi_stop(); +} diff --git a/fw/fe310/eos/app/app_form.h b/fw/fe310/eos/app/app_form.h new file mode 100644 index 0000000..ed62253 --- /dev/null +++ b/fw/fe310/eos/app/app_form.h @@ -0,0 +1,7 @@ +#include <stdint.h> + +#define APP_FONT_HANDLE 31 +#define APP_LABEL_MARGIN 10 + +EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec spec[], uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor); +void app_form_destroy(EVEForm *form); |