summaryrefslogtreecommitdiff
path: root/fw
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2020-08-23 22:37:16 +0200
committerUros Majstorovic <majstor@majstor.org>2020-08-23 22:37:16 +0200
commit1e5eb7cb910e6f23c69c2c986b6373e9f9abb980 (patch)
tree5e8ed0ad6b2fcba747c626c1c51afebbf76b3b9d /fw
parent57c1824affca858023c65c84e188ea7dc6c0a5f2 (diff)
dynamic memory alloc for gui added; page navigation added
Diffstat (limited to 'fw')
-rw-r--r--fw/fe310/Makefile2
-rw-r--r--fw/fe310/eos/Makefile4
-rw-r--r--fw/fe310/eos/app/Makefile17
-rw-r--r--fw/fe310/eos/app/root.c133
-rw-r--r--fw/fe310/eos/app/root.h27
-rw-r--r--fw/fe310/eos/app/status.c23
-rw-r--r--fw/fe310/eos/app/status.h4
-rw-r--r--fw/fe310/eos/cell.h1
-rw-r--r--fw/fe310/eos/eve/Makefile2
-rw-r--r--fw/fe310/eos/eve/eve.c1
-rw-r--r--fw/fe310/eos/eve/eve.h1
-rw-r--r--fw/fe310/eos/eve/eve_platform.h7
-rw-r--r--fw/fe310/eos/eve/screen/Makefile4
-rw-r--r--fw/fe310/eos/eve/screen/form.c28
-rw-r--r--fw/fe310/eos/eve/screen/form.h4
-rw-r--r--fw/fe310/eos/eve/screen/page.c42
-rw-r--r--fw/fe310/eos/eve/screen/page.h25
-rw-r--r--fw/fe310/eos/eve/widget/Makefile4
-rw-r--r--fw/fe310/eos/eve/widget/font.c (renamed from fw/fe310/eos/eve/screen/font.c)0
-rw-r--r--fw/fe310/eos/eve/widget/font.h (renamed from fw/fe310/eos/eve/screen/font.h)0
-rw-r--r--fw/fe310/eos/eve/widget/freew.c61
-rw-r--r--fw/fe310/eos/eve/widget/freew.h27
-rw-r--r--fw/fe310/eos/eve/widget/label.c4
-rw-r--r--fw/fe310/eos/eve/widget/label.h2
-rw-r--r--fw/fe310/eos/eve/widget/pagew.c29
-rw-r--r--fw/fe310/eos/eve/widget/pagew.h13
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.c36
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.h14
-rw-r--r--fw/fe310/eos/eve/widget/strw.c47
-rw-r--r--fw/fe310/eos/eve/widget/strw.h9
-rw-r--r--fw/fe310/eos/eve/widget/textw.c75
-rw-r--r--fw/fe310/eos/eve/widget/textw.h12
-rw-r--r--fw/fe310/eos/eve/widget/widget.c45
-rw-r--r--fw/fe310/eos/eve/widget/widget.h9
-rw-r--r--fw/fe310/eos/eve/widget/widgets.h23
-rw-r--r--fw/fe310/test/Makefile2
-rw-r--r--fw/fe310/test/modem.c22
37 files changed, 662 insertions, 97 deletions
diff --git a/fw/fe310/Makefile b/fw/fe310/Makefile
index f1430fb..69ac470 100644
--- a/fw/fe310/Makefile
+++ b/fw/fe310/Makefile
@@ -2,7 +2,7 @@ include common.mk
CFLAGS += -I./include
-subdirs = bsp/drivers bsp/gloss bsp/metal eos eos/eve eos/eve/screen eos/eve/widget
+subdirs = bsp/drivers bsp/gloss bsp/metal eos eos/eve eos/eve/screen eos/eve/widget eos/app
all: libeos.a
diff --git a/fw/fe310/eos/Makefile b/fw/fe310/eos/Makefile
index 301a30e..ef08fd1 100644
--- a/fw/fe310/eos/Makefile
+++ b/fw/fe310/eos/Makefile
@@ -1,6 +1,6 @@
include ../common.mk
-CFLAGS += -I../bsp/include -I../bsp/drivers
+CFLAGS += -I. -I../bsp/include -I../bsp/drivers
obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o power.o i2s.o uart.o spi.o spi_dev.o net.o wifi.o cell.o sock.o unicode.o
@@ -14,4 +14,4 @@ obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o power.o i2s.o uart.o
all: $(obj)
clean:
- rm -f *.o \ No newline at end of file
+ rm -f *.o
diff --git a/fw/fe310/eos/app/Makefile b/fw/fe310/eos/app/Makefile
new file mode 100644
index 0000000..7bb9951
--- /dev/null
+++ b/fw/fe310/eos/app/Makefile
@@ -0,0 +1,17 @@
+include ../../common.mk
+
+CFLAGS += -I..
+
+obj = root.o status.o
+
+
+%.o: %.c %.h
+ $(CC) $(CFLAGS) -c $<
+
+%.o: %.S
+ $(CC) $(CFLAGS) -c $<
+
+all: $(obj)
+
+clean:
+ rm -f *.o
diff --git a/fw/fe310/eos/app/root.c b/fw/fe310/eos/app/root.c
new file mode 100644
index 0000000..160316f
--- /dev/null
+++ b/fw/fe310/eos/app/root.c
@@ -0,0 +1,133 @@
+#include <stdlib.h>
+
+#include "net.h"
+#include "unicode.h"
+
+#include "eve/eve.h"
+#include "eve/eve_kbd.h"
+
+#include "eve/screen/screen.h"
+#include "eve/screen/window.h"
+#include "eve/screen/kbdwin.h"
+#include "eve/screen/page.h"
+#include "eve/screen/form.h"
+
+#include "eve/widget/widgets.h"
+
+#include "status.h"
+#include "root.h"
+
+EVEFont _app_font_default;
+extern eve_page_constructor_t _app_home_page;
+
+static EVEScreen screen;
+static EVEWindow win_status;
+static EVEWindow win_main;
+static EVEKbdWin win_kbd;
+static EVEView view_status = {
+ app_status_touch,
+ app_status_draw,
+ NULL
+};
+static EVEPageStack page_stack;
+
+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);
+ }
+}
+
+EVEForm *app_form_create(EVEWindow *window, EVEPageStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_page_destructor_t destructor) {
+ EVEWidget *widgets;
+ EVEWidget *widget;
+ EVELabel *label;
+ EVEForm *form;
+ 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(form));
+ 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++) {
+ r = eve_widget_create(widget, spec[i].widget.type, &spec[i].widget.g, &spec[i].widget.spec);
+ if (r) {
+ widgets_destroy(widgets, i);
+ eve_free(widgets);
+ eve_free(form);
+ return NULL;
+ }
+ if (spec[i].label.title) {
+ label = eve_malloc(sizeof(label));
+ 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, spec[i].label.font, spec[i].label.title);
+ eve_widget_set_label(widget, label);
+ }
+ widget = eve_widget_next(widget);
+ }
+
+ if (destructor == NULL) destructor = (eve_page_destructor_t)app_form_destroy;
+ eve_form_init(form, window, stack, widgets, spec_size, 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_root_init(void) {
+ EVERect g;
+
+ eos_spi_dev_start(EOS_DEV_DISP);
+
+ eve_brightness(0x40);
+ eve_font_init(&_app_font_default, APP_FONT_HANDLE);
+ eve_screen_init(&screen, APP_SCREEN_W, APP_SCREEN_H);
+
+ g.x = 0;
+ g.y = 0;
+ g.w = APP_SCREEN_W;
+ g.h = APP_STATUS_H;
+ eve_window_init(&win_status, &g, &view_status, &screen);
+ g.x = 0;
+ g.y = APP_STATUS_H;
+ g.w = APP_SCREEN_W;
+ g.h = APP_SCREEN_H - APP_STATUS_H;
+ eve_window_init(&win_main, &g, NULL, &screen);
+ eve_kbdwin_init(&win_kbd, &screen);
+
+ eve_page_stack_init(&page_stack);
+ eve_page_create(&win_main, &page_stack, _app_home_page);
+
+ eve_window_append(&win_status);
+ eve_window_append(&win_main);
+ eve_kbdwin_append(&win_kbd);
+ eve_screen_draw(&screen);
+
+ eos_spi_dev_stop();
+
+ eos_net_acquire_for_evt(EOS_EVT_UI | EVE_ETYPE_INTR, 1);
+}
diff --git a/fw/fe310/eos/app/root.h b/fw/fe310/eos/app/root.h
new file mode 100644
index 0000000..09284e2
--- /dev/null
+++ b/fw/fe310/eos/app/root.h
@@ -0,0 +1,27 @@
+#include <stdint.h>
+
+#define APP_SCREEN_W 480
+#define APP_SCREEN_H 800
+#define APP_STATUS_H 60
+
+#define APP_FONT_HANDLE 31
+
+typedef struct APPLabelSpec {
+ EVERect g;
+ EVEFont *font;
+ char *title;
+} APPLabelSpec;
+
+typedef struct APPWidgetSpec {
+ APPLabelSpec label;
+ struct {
+ EVERect g;
+ EVEWidgetSpec spec;
+ uint8_t type;
+ } widget;
+} APPWidgetSpec;
+
+
+void app_root_init(void);
+EVEForm *app_form_create(EVEWindow *window, EVEPageStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_page_destructor_t destructor);
+void app_form_destroy(EVEForm *form); \ No newline at end of file
diff --git a/fw/fe310/eos/app/status.c b/fw/fe310/eos/app/status.c
new file mode 100644
index 0000000..39c471e
--- /dev/null
+++ b/fw/fe310/eos/app/status.c
@@ -0,0 +1,23 @@
+
+#include <stdlib.h>
+
+#include "unicode.h"
+
+#include "eve/eve.h"
+#include "eve/eve_kbd.h"
+
+#include "eve/screen/screen.h"
+#include "eve/screen/window.h"
+#include "eve/screen/page.h"
+
+#include "status.h"
+
+int app_status_touch(EVEView *v, uint8_t tag0, int touch_idx) {
+ return 0;
+}
+
+uint8_t app_status_draw(EVEView *v, uint8_t tag0) {
+ return tag0;
+}
+
+
diff --git a/fw/fe310/eos/app/status.h b/fw/fe310/eos/app/status.h
new file mode 100644
index 0000000..a121b13
--- /dev/null
+++ b/fw/fe310/eos/app/status.h
@@ -0,0 +1,4 @@
+#include <stdint.h>
+
+int app_status_touch(EVEView *v, uint8_t tag0, int touch_idx);
+uint8_t app_status_draw(EVEView *v, uint8_t tag0);
diff --git a/fw/fe310/eos/cell.h b/fw/fe310/eos/cell.h
index 92c8c7c..371f7ba 100644
--- a/fw/fe310/eos/cell.h
+++ b/fw/fe310/eos/cell.h
@@ -34,6 +34,7 @@
#define EOS_CELL_MTYPE_USSD_REQUEST 1
#define EOS_CELL_MTYPE_USSD_REPLY 2
+#define EOS_CELL_MTYPE_USSD_CANCEL 3
#define EOS_CELL_MTYPE_DATA_CONFIGURE 1
#define EOS_CELL_MTYPE_DATA_CONNECT 2
diff --git a/fw/fe310/eos/eve/Makefile b/fw/fe310/eos/eve/Makefile
index d700b30..68d406a 100644
--- a/fw/fe310/eos/eve/Makefile
+++ b/fw/fe310/eos/eve/Makefile
@@ -14,4 +14,4 @@ obj = eve.o eve_touch.o eve_track.o eve_kbd.o eve_text.o eve_platform.o
all: $(obj)
clean:
- rm -f *.o \ No newline at end of file
+ rm -f *.o
diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c
index 1db5744..1152699 100644
--- a/fw/fe310/eos/eve/eve.c
+++ b/fw/fe310/eos/eve/eve.c
@@ -395,6 +395,7 @@ static int _init(void) {
}
int eve_init(int pwr_on) {
+ pwr_on = 1; // override this for now
if (pwr_on) {
int rv = _init();
if (rv) return rv;
diff --git a/fw/fe310/eos/eve/eve.h b/fw/fe310/eos/eve/eve.h
index eb59959..c482d83 100644
--- a/fw/fe310/eos/eve/eve.h
+++ b/fw/fe310/eos/eve/eve.h
@@ -7,6 +7,7 @@
#define EVE_OK 0
#define EVE_ERR -1
+#define EVE_ERR_NOMEM -100
#define EVE_PSTATE_ACTIVE 0
#define EVE_PSTATE_STANDBY 1
diff --git a/fw/fe310/eos/eve/eve_platform.h b/fw/fe310/eos/eve/eve_platform.h
index 41ec6b4..514c4ee 100644
--- a/fw/fe310/eos/eve/eve_platform.h
+++ b/fw/fe310/eos/eve/eve_platform.h
@@ -1,7 +1,7 @@
#include <stdint.h>
-#include "../spi.h"
-#include "../timer.h"
+#include "spi.h"
+#include "timer.h"
#define EVE_ETYPE_INTR 1
#define EVE_PIN_INTR 0
@@ -19,6 +19,9 @@
#define eve_spi_xchg24 eos_spi_xchg24
#define eve_spi_xchg32 eos_spi_xchg32
+#define eve_malloc malloc
+#define eve_free free
+
void eve_time_sleep(uint32_t ms);
void eve_timer_set(uint32_t ms);
void eve_timer_clear(void);
diff --git a/fw/fe310/eos/eve/screen/Makefile b/fw/fe310/eos/eve/screen/Makefile
index b6cb393..b1650bd 100644
--- a/fw/fe310/eos/eve/screen/Makefile
+++ b/fw/fe310/eos/eve/screen/Makefile
@@ -2,7 +2,7 @@ include ../../../common.mk
CFLAGS += -I.. -I../..
-obj = font.o screen.o window.o kbdwin.o page.o form.o
+obj = screen.o window.o kbdwin.o page.o form.o
%.o: %.c %.h
@@ -14,4 +14,4 @@ obj = font.o screen.o window.o kbdwin.o page.o form.o
all: $(obj)
clean:
- rm -f *.o \ No newline at end of file
+ rm -f *.o
diff --git a/fw/fe310/eos/eve/screen/form.c b/fw/fe310/eos/eve/screen/form.c
index f7d37ee..52cfdc6 100644
--- a/fw/fe310/eos/eve/screen/form.c
+++ b/fw/fe310/eos/eve/screen/form.c
@@ -8,15 +8,18 @@
#include "screen.h"
#include "window.h"
#include "page.h"
-#include "font.h"
#include "form.h"
+#include "widget/font.h"
#include "widget/label.h"
#include "widget/widget.h"
-int eve_form_init(EVEForm *form, EVEWindow *window, EVEWidget *widget, uint16_t widget_size, eve_page_open_t open, eve_page_close_t close) {
+#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
+#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
+
+int eve_form_init(EVEForm *form, EVEWindow *window, EVEPageStack *stack, EVEWidget *widget, uint16_t widget_size, eve_page_destructor_t destructor) {
memset(form, 0, sizeof(EVEForm));
- eve_page_init(&form->p, window, eve_form_touch, eve_form_draw, open, close, eve_form_handle_evt, eve_form_update_g);
+ eve_page_init(&form->p, window, stack, eve_form_touch, eve_form_draw, eve_form_handle_evt, eve_form_update_g, destructor);
form->widget = widget;
form->widget_size = widget_size;
eve_form_update_g(&form->p, NULL);
@@ -80,7 +83,7 @@ uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
return tagN;
}
-void eve_form_handle_evt(EVEPage *page, EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx) {
+int eve_form_handle_evt(EVEPage *page, EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx) {
/*
if (evt & EVE_TOUCH_ETYPE_TRACK_Y) {
// do scroll
@@ -94,15 +97,28 @@ void eve_form_update_g(EVEPage *page, EVEWidget *_widget) {
EVEForm *form = (EVEForm *)page;
EVEWidget *widget = form->widget;
int i;
+ uint16_t w = 0;
uint16_t h = 0;
+ uint16_t _h = 0;
for (i=0; i<form->widget_size; i++) {
if (widget->label) {
+ h += _h;
+ w = widget->label->g.w;
+ _h = widget->label->g.h;
+ widget->label->g.x = 0;
widget->label->g.y = h;
- if (widget->label->g.w + widget->g.w > form->p.v.window->g.w) h += widget->label->g.h;
}
+ if (w + widget->g.w >= form->p.v.window->g.w) {
+ h += _h;
+ w = 0;
+ _h = 0;
+ }
+ widget->g.x = w;
widget->g.y = h;
- h += widget->g.h;
+
+ w += widget->g.w;
+ _h = MAX(_h, widget->g.h);
widget = eve_widget_next(widget);
}
diff --git a/fw/fe310/eos/eve/screen/form.h b/fw/fe310/eos/eve/screen/form.h
index 7742b8c..91a4f8a 100644
--- a/fw/fe310/eos/eve/screen/form.h
+++ b/fw/fe310/eos/eve/screen/form.h
@@ -8,8 +8,8 @@ typedef struct EVEForm {
uint16_t widget_size;
} EVEForm;
-int eve_form_init(EVEForm *form, EVEWindow *window, struct EVEWidget *widget, uint16_t widget_size, eve_page_open_t open, eve_page_close_t close);
+int eve_form_init(EVEForm *form, EVEWindow *window, EVEPageStack *stack, struct EVEWidget *widget, uint16_t widget_size, eve_page_destructor_t destructor);
int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx);
uint8_t eve_form_draw(EVEView *v, uint8_t tag0);
-void eve_form_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx);
+int eve_form_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx);
void eve_form_update_g(EVEPage *page, struct EVEWidget *widget);
diff --git a/fw/fe310/eos/eve/screen/page.c b/fw/fe310/eos/eve/screen/page.c
index f54056c..9579346 100644
--- a/fw/fe310/eos/eve/screen/page.c
+++ b/fw/fe310/eos/eve/screen/page.c
@@ -8,26 +8,60 @@
#include "screen.h"
#include "window.h"
#include "page.h"
-#include "font.h"
+#include "widget/font.h"
#include "widget/label.h"
#include "widget/widget.h"
#define CH_EOF 0x1a
-void eve_page_init(EVEPage *page, EVEWindow *window, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_open_t open, eve_page_close_t close, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g) {
+void eve_page_init(EVEPage *page, EVEWindow *window, EVEPageStack *stack, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g, eve_page_destructor_t destructor) {
memset(page, 0, sizeof(EVEPage));
page->v.touch = touch;
page->v.draw = draw;
page->v.window = window;
- page->open = open;
- page->close = close;
page->handle_evt = handle_evt;
page->update_g = update_g;
+ page->destructor = destructor;
+ page->stack = stack;
page->widget_f = NULL;
window->view = (EVEView *)page;
}
+void eve_page_stack_init(EVEPageStack *stack) {
+ memset(stack, 0, sizeof(EVEPageStack));
+}
+
+void eve_page_create(EVEWindow *window, EVEPageStack *stack, eve_page_constructor_t constructor) {
+ if (stack->level < EVE_PAGE_SIZE_STACK - 1) {
+ stack->constructor[stack->level] = constructor;
+ stack->level++;
+ constructor(window, stack);
+ }
+}
+
+void eve_page_open(EVEPage *parent, eve_page_constructor_t constructor) {
+ EVEWindow *window = parent->v.window;
+ EVEPageStack *stack = parent->stack;
+
+ parent->destructor(parent);
+ eve_page_create(window, stack, constructor);
+}
+
+void eve_page_close(EVEPage *page) {
+ EVEWindow *window = page->v.window;
+ EVEPageStack *stack = page->stack;
+
+ if (stack->level > 1) {
+ eve_page_constructor_t constructor;
+
+ stack->level--;
+ constructor = stack->constructor[stack->level - 1];
+ page->destructor(page);
+ constructor(window, stack);
+ }
+}
+
int16_t eve_page_x(EVEPage *page, int16_t x) {
return x + page->win_x - page->v.window->g.x;
}
diff --git a/fw/fe310/eos/eve/screen/page.h b/fw/fe310/eos/eve/screen/page.h
index eebedfd..227375c 100644
--- a/fw/fe310/eos/eve/screen/page.h
+++ b/fw/fe310/eos/eve/screen/page.h
@@ -1,25 +1,38 @@
#include <stdint.h>
+#define EVE_PAGE_SIZE_STACK 16
+
struct EVEPage;
struct EVEWidget;
+struct EVEPageStack;
-typedef void (*eve_page_open_t) (struct EVEPage *, struct EVEPage *);
-typedef void (*eve_page_close_t) (struct EVEPage *);
-typedef void (*eve_page_evt_handler_t) (struct EVEPage *, struct EVEWidget *, EVETouch *, uint16_t, uint8_t, int);
+typedef void (*eve_page_constructor_t) (EVEWindow *window, struct EVEPageStack *);
+typedef void (*eve_page_destructor_t) (struct EVEPage *);
+typedef int (*eve_page_evt_handler_t) (struct EVEPage *, struct EVEWidget *, EVETouch *, uint16_t, uint8_t, int);
typedef void (*eve_page_g_updater_t) (struct EVEPage *, struct EVEWidget *);
typedef struct EVEPage {
EVEView v;
int16_t win_x;
int16_t win_y;
- eve_page_open_t open;
- eve_page_close_t close;
eve_page_evt_handler_t handle_evt;
eve_page_g_updater_t update_g;
+ eve_page_destructor_t destructor;
+ struct EVEPageStack *stack;
struct EVEWidget *widget_f;
} EVEPage;
-void eve_page_init(EVEPage *page, EVEWindow *window, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_open_t open, eve_page_close_t close, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g);
+typedef struct EVEPageStack {
+ eve_page_constructor_t constructor[EVE_PAGE_SIZE_STACK];
+ uint8_t level;
+} EVEPageStack;
+
+void eve_page_init(EVEPage *page, EVEWindow *window, EVEPageStack *stack, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g, eve_page_destructor_t destructor);
+void eve_page_stack_init(EVEPageStack *stack);
+void eve_page_create(EVEWindow *window, EVEPageStack *stack, eve_page_constructor_t constructor);
+void eve_page_open(EVEPage *parent, eve_page_constructor_t constructor);
+void eve_page_close(EVEPage *page);
+
int16_t eve_page_x(EVEPage *page, int16_t x);
int16_t eve_page_y(EVEPage *page, int16_t y);
int16_t eve_page_scr_x(EVEPage *page, int16_t x);
diff --git a/fw/fe310/eos/eve/widget/Makefile b/fw/fe310/eos/eve/widget/Makefile
index 160db72..720029e 100644
--- a/fw/fe310/eos/eve/widget/Makefile
+++ b/fw/fe310/eos/eve/widget/Makefile
@@ -2,7 +2,7 @@ include ../../../common.mk
CFLAGS += -I.. -I../..
-obj = clipb.o label.o widget.o pagew.o strw.o textw.o
+obj = clipb.o font.o label.o widget.o freew.o spacerw.o pagew.o strw.o textw.o
%.o: %.c %.h
@@ -14,4 +14,4 @@ obj = clipb.o label.o widget.o pagew.o strw.o textw.o
all: $(obj)
clean:
- rm -f *.o \ No newline at end of file
+ rm -f *.o
diff --git a/fw/fe310/eos/eve/screen/font.c b/fw/fe310/eos/eve/widget/font.c
index da02983..da02983 100644
--- a/fw/fe310/eos/eve/screen/font.c
+++ b/fw/fe310/eos/eve/widget/font.c
diff --git a/fw/fe310/eos/eve/screen/font.h b/fw/fe310/eos/eve/widget/font.h
index aff038c..aff038c 100644
--- a/fw/fe310/eos/eve/screen/font.h
+++ b/fw/fe310/eos/eve/widget/font.h
diff --git a/fw/fe310/eos/eve/widget/freew.c b/fw/fe310/eos/eve/widget/freew.c
new file mode 100644
index 0000000..55f91cb
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/freew.c
@@ -0,0 +1,61 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+#include "unicode.h"
+
+#include "screen/screen.h"
+#include "screen/window.h"
+#include "screen/page.h"
+
+#include "font.h"
+#include "label.h"
+#include "widget.h"
+#include "freew.h"
+
+int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEFreeSpec *spec) {
+ eve_freew_init(widget, g, spec->touch, spec->draw, spec->putc);
+
+ return EVE_OK;
+}
+
+void eve_freew_init(EVEFreeWidget *widget, EVERect *g, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc) {
+ EVEWidget *_widget = &widget->w;
+
+ memset(widget, 0, sizeof(EVEFreeWidget));
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_FREE, g, eve_freew_touch, eve_freew_draw, putc);
+ eve_freew_update(widget, touch, draw, NULL);
+}
+
+void eve_freew_update(EVEFreeWidget *widget, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc) {
+ if (touch) widget->_touch = touch;
+ if (draw) widget->_draw = draw;
+ if (putc) widget->w.putc = putc;
+}
+
+int eve_freew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) {
+ EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
+ EVETouch *t;
+ uint16_t evt;
+ int ret = 0;
+
+ if (touch_idx > 0) return 0;
+
+ t = eve_touch_evt(tag0, touch_idx, widget->tag0, widget->tagN - widget->tag0, &evt);
+ if (t && evt) {
+ ret = widget->_touch(widget, page, t, evt, tag0, touch_idx);
+ if (!ret && page && page->handle_evt) ret = page->handle_evt(page, _widget, t, evt, tag0, touch_idx);
+ }
+
+ return ret;
+}
+
+uint8_t eve_freew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
+ EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
+
+ widget->tag0 = tag0;
+ widget->tagN = widget->_draw(widget, page, tag0);
+
+ return widget->tagN;
+}
diff --git a/fw/fe310/eos/eve/widget/freew.h b/fw/fe310/eos/eve/widget/freew.h
new file mode 100644
index 0000000..49f896f
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/freew.h
@@ -0,0 +1,27 @@
+#include <stdint.h>
+
+struct EVEFreeWidget;
+
+typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVEPage *, EVETouch *, uint16_t, uint8_t, int);
+typedef uint8_t (*eve_freew_draw_t) (struct EVEFreeWidget *, EVEPage *, uint8_t);
+
+typedef struct EVEFreeWidget {
+ EVEWidget w;
+ eve_freew_touch_t _touch;
+ eve_freew_draw_t _draw;
+ uint8_t tag0;
+ uint8_t tagN;
+} EVEFreeWidget;
+
+typedef struct EVEFreeSpec {
+ eve_freew_touch_t touch;
+ eve_freew_draw_t draw;
+ eve_kbd_input_handler_t putc;
+} EVEFreeSpec;
+
+int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEFreeSpec *spec);
+void eve_freew_init(EVEFreeWidget *widget, EVERect *g, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc);
+void eve_freew_update(EVEFreeWidget *widget, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc);
+
+int eve_freew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
+uint8_t eve_freew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/label.c b/fw/fe310/eos/eve/widget/label.c
index ebea823..b4af37f 100644
--- a/fw/fe310/eos/eve/widget/label.c
+++ b/fw/fe310/eos/eve/widget/label.c
@@ -8,15 +8,15 @@
#include "screen/screen.h"
#include "screen/window.h"
#include "screen/page.h"
-#include "screen/font.h"
+#include "font.h"
#include "label.h"
void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title) {
memset(label, 0, sizeof(EVELabel));
if (g) label->g = *g;
- label->title = title;
label->font = font;
+ label->title = title;
if (label->g.w == 0) label->g.w = eve_font_str_w(font, label->title);
if (label->g.h == 0) label->g.h = eve_font_h(font);
}
diff --git a/fw/fe310/eos/eve/widget/label.h b/fw/fe310/eos/eve/widget/label.h
index ec96844..659c057 100644
--- a/fw/fe310/eos/eve/widget/label.h
+++ b/fw/fe310/eos/eve/widget/label.h
@@ -2,8 +2,8 @@
typedef struct EVELabel {
EVERect g;
- char *title;
EVEFont *font;
+ char *title;
} EVELabel;
void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title);
diff --git a/fw/fe310/eos/eve/widget/pagew.c b/fw/fe310/eos/eve/widget/pagew.c
index c64c477..b3e71a6 100644
--- a/fw/fe310/eos/eve/widget/pagew.c
+++ b/fw/fe310/eos/eve/widget/pagew.c
@@ -8,20 +8,32 @@
#include "screen/screen.h"
#include "screen/window.h"
#include "screen/page.h"
-#include "screen/font.h"
+#include "font.h"
#include "label.h"
#include "widget.h"
#include "pagew.h"
-void eve_pagew_init(EVEPageWidget *widget, EVERect *g, char *title, EVEFont *font, EVEPage *page) {
+int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPageSpec *spec) {
+ eve_pagew_init(widget, g, spec->font, spec->title, spec->constructor);
+
+ return EVE_OK;
+}
+
+void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEFont *font, char *title, eve_page_constructor_t constructor) {
EVEWidget *_widget = &widget->w;
memset(widget, 0, sizeof(EVEPageWidget));
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;
+ eve_pagew_update(widget, font, title, constructor);
+}
+
+void eve_pagew_update(EVEPageWidget *widget, EVEFont *font, char *title, eve_page_constructor_t constructor) {
+ EVEWidget *_widget = &widget->w;
+
+ if (font) widget->font = font;
+ if (title) widget->title = title;
+ if (constructor) widget->constructor = constructor;
if (_widget->g.w == 0) _widget->g.w = eve_font_str_w(font, widget->title);
if (_widget->g.h == 0) _widget->g.h = eve_font_h(font);
}
@@ -37,12 +49,13 @@ int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i
t = eve_touch_evt(tag0, touch_idx, widget->tag, 1, &evt);
if (t && evt) {
if (evt & EVE_TOUCH_ETYPE_TRACK_MASK) {
- if (page && page->handle_evt) page->handle_evt(page, _widget, t, evt, tag0, touch_idx);
+ if (page->handle_evt) ret = page->handle_evt(page, _widget, t, evt, tag0, touch_idx);
} else if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
- widget->page->open(widget->page, page);
+ eve_page_open(page, widget->constructor);
+ ret = 1;
}
- ret = 1;
}
+
return ret;
}
diff --git a/fw/fe310/eos/eve/widget/pagew.h b/fw/fe310/eos/eve/widget/pagew.h
index 1f9ae18..797f1c3 100644
--- a/fw/fe310/eos/eve/widget/pagew.h
+++ b/fw/fe310/eos/eve/widget/pagew.h
@@ -4,10 +4,19 @@ typedef struct EVEPageWidget {
EVEWidget w;
char *title;
EVEFont *font;
- EVEPage *page;
+ eve_page_constructor_t constructor;
uint8_t tag;
} EVEPageWidget;
-void eve_pagew_init(EVEPageWidget *widget, EVERect *g, char *title, EVEFont *font, EVEPage *page);
+typedef struct EVEPageSpec {
+ EVEFont *font;
+ char *title;
+ eve_page_constructor_t constructor;
+} EVEPageSpec;
+
+int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPageSpec *spec);
+void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEFont *font, char *title, eve_page_constructor_t constructor);
+void eve_pagew_update(EVEPageWidget *widget, EVEFont *font, char *title, eve_page_constructor_t constructor);
+
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/fw/fe310/eos/eve/widget/spacerw.c b/fw/fe310/eos/eve/widget/spacerw.c
new file mode 100644
index 0000000..23aec14
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/spacerw.c
@@ -0,0 +1,36 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+#include "unicode.h"
+
+#include "screen/screen.h"
+#include "screen/window.h"
+#include "screen/page.h"
+
+#include "font.h"
+#include "label.h"
+#include "widget.h"
+#include "spacerw.h"
+
+int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVESpacerSpec *spec) {
+ eve_spacerw_init(widget, g);
+
+ return EVE_OK;
+}
+
+void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g) {
+ EVEWidget *_widget = &widget->w;
+
+ memset(widget, 0, sizeof(EVESpacerWidget));
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_SPACER, g, eve_spacerw_touch, eve_spacerw_draw, NULL);
+}
+
+int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) {
+ return 0;
+}
+
+uint8_t eve_spacerw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
+ return tag0;
+}
diff --git a/fw/fe310/eos/eve/widget/spacerw.h b/fw/fe310/eos/eve/widget/spacerw.h
new file mode 100644
index 0000000..cbde4e8
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/spacerw.h
@@ -0,0 +1,14 @@
+#include <stdint.h>
+
+typedef struct EVESpacerWidget {
+ EVEWidget w;
+} EVESpacerWidget;
+
+typedef struct EVESpacerSpec {
+} EVESpacerSpec;
+
+int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVESpacerSpec *spec);
+void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g);
+
+int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
+uint8_t eve_spacerw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c
index 2a80a28..e973575 100644
--- a/fw/fe310/eos/eve/widget/strw.c
+++ b/fw/fe310/eos/eve/widget/strw.c
@@ -8,9 +8,9 @@
#include "screen/screen.h"
#include "screen/window.h"
#include "screen/page.h"
-#include "screen/font.h"
#include "clipb.h"
+#include "font.h"
#include "label.h"
#include "widget.h"
#include "strw.h"
@@ -29,22 +29,47 @@
#define CHAR_VALID_INPUT(c) ((c >= 0x20) && (c < 0x7f))
+int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEStrSpec *spec) {
+ utf8_t *str;
+ uint16_t *line;
+
+ str = eve_malloc(spec->str_size);
+ if (str == NULL) return EVE_ERR_NOMEM;
+ str[0] = '\0';
+
+ eve_strw_init(widget, g, spec->font, str, spec->str_size);
+
+ return EVE_OK;
+}
+
+void eve_strw_destroy(EVEStrWidget *widget) {
+ eve_free(widget->str);
+}
+
void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEFont *font, utf8_t *str, uint16_t str_size) {
- int rv, str_len;
EVEWidget *_widget = &widget->w;
memset(widget, 0, sizeof(EVEStrWidget));
eve_widget_init(_widget, EVE_WIDGET_TYPE_STR, g, eve_strw_touch, eve_strw_draw, eve_strw_putc);
- widget->font = font;
- widget->str = str;
- widget->str_size = str_size;
- rv = utf8_verify(str, str_size, &str_len);
- if (rv != UTF_OK) {
- if (str_len >= str_size) str_len = 0;
- widget->str[str_len] = '\0';
+ eve_strw_update(widget, font, str, str_size);
+}
+
+void eve_strw_update(EVEStrWidget *widget, EVEFont *font, utf8_t *str, uint16_t str_size) {
+ int rv, str_len;
+ EVEWidget *_widget = &widget->w;
+
+ if (font) widget->font = font;
+ if (str) {
+ widget->str = str;
+ widget->str_size = str_size;
+ rv = utf8_verify(str, str_size, &str_len);
+ if (rv != UTF_OK) {
+ if (str_len >= str_size) str_len = 0;
+ widget->str[str_len] = '\0';
+ }
+ widget->str_len = str_len;
+ widget->str_g.w = eve_font_str_w(font, str);
}
- widget->str_len = str_len;
- widget->str_g.w = eve_font_str_w(font, str);
if (_widget->g.h == 0) _widget->g.h = eve_font_h(font);
}
diff --git a/fw/fe310/eos/eve/widget/strw.h b/fw/fe310/eos/eve/widget/strw.h
index 72fc6aa..9456603 100644
--- a/fw/fe310/eos/eve/widget/strw.h
+++ b/fw/fe310/eos/eve/widget/strw.h
@@ -27,7 +27,16 @@ typedef struct EVEStrWidget {
} track;
} EVEStrWidget;
+typedef struct EVEStrSpec {
+ EVEFont *font;
+ uint16_t str_size;
+} EVEStrSpec;
+
+int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEStrSpec *spec);
+void eve_strw_destroy(EVEStrWidget *widget);
void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEFont *font, utf8_t *str, uint16_t str_size);
+void eve_strw_update(EVEStrWidget *widget, EVEFont *font, utf8_t *str, uint16_t str_size);
+
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);
diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c
index bf075cf..5835a57 100644
--- a/fw/fe310/eos/eve/widget/textw.c
+++ b/fw/fe310/eos/eve/widget/textw.c
@@ -8,9 +8,9 @@
#include "screen/screen.h"
#include "screen/window.h"
#include "screen/page.h"
-#include "screen/font.h"
#include "clipb.h"
+#include "font.h"
#include "label.h"
#include "widget.h"
#include "textw.h"
@@ -35,25 +35,59 @@
#define DIVC(x,y) ((x) / (y) + ((x) % (y) != 0))
+int eve_textw_create(EVETextWidget *widget, EVERect *g, EVETextSpec *spec) {
+ utf8_t *text;
+ uint16_t *line;
+
+ text = eve_malloc(spec->text_size);
+ if (text == NULL) {
+ return EVE_ERR_NOMEM;
+ }
+ text[0] = '\0';
+ line = eve_malloc(sizeof(uint16_t) * spec->line_size);
+ if (line == NULL) {
+ free(text);
+ return EVE_ERR_NOMEM;
+ }
+
+ eve_textw_init(widget, g, spec->font, text, spec->text_size, line, spec->line_size);
+
+ return EVE_OK;
+}
+
+void eve_textw_destroy(EVETextWidget *widget) {
+ eve_free(widget->line);
+ eve_free(widget->text);
+}
+
void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size) {
- int rv, text_len;
EVEWidget *_widget = &widget->w;
memset(widget, 0, sizeof(EVETextWidget));
eve_widget_init(_widget, EVE_WIDGET_TYPE_TEXT, g, eve_textw_touch, eve_textw_draw, eve_textw_putc);
- widget->font = font;
- widget->text = text;
- widget->text_size = text_size;
- rv = utf8_verify(text, text_size, &text_len);
- if (rv != UTF_OK) {
- if (text_len >= text_size) text_len = 0;
- widget->text[text_len] = '\0';
+ eve_textw_update(widget, font, text, text_size, line, line_size);
+}
+
+void eve_textw_update(EVETextWidget *widget, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size) {
+ int rv, text_len;
+
+ if (font) widget->font = font;
+ if (text) {
+ widget->text = text;
+ widget->text_size = text_size;
+ rv = utf8_verify(text, text_size, &text_len);
+ if (rv != UTF_OK) {
+ if (text_len >= text_size) text_len = 0;
+ widget->text[text_len] = '\0';
+ }
+ widget->text_len = text_len;
+ }
+ if (line) {
+ widget->line = line;
+ widget->line_size = line_size;
}
- widget->text_len = text_len;
- widget->line = line;
- widget->line_size = line_size;
memset(widget->line, 0xff, line_size * sizeof(uint16_t));
- eve_textw_update(widget, NULL, 0);
+ eve_textw_text_update(widget, NULL, 0);
}
static void set_focus(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page) {
@@ -87,7 +121,6 @@ int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i
EVETextWidget *widget = (EVETextWidget *)_widget;
EVETouch *t;
uint16_t evt;
- int ret = 0;
if (touch_idx > 0) return 0;
@@ -121,7 +154,9 @@ int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i
break;
case TEXTW_TMODE_CURSOR:
- if (evt & EVE_TOUCH_ETYPE_TRACK) eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, eve_page_x(page, t->x) + widget->track.dx);
+ if (evt & EVE_TOUCH_ETYPE_TRACK) {
+ eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, eve_page_x(page, t->x) + widget->track.dx);
+ }
break;
default:
@@ -153,10 +188,10 @@ int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_i
widget->track.dl = 0;
}
- ret = 1;
+ return 1;
}
- return ret;
+ return 0;
}
static void _draw_line(EVETextWidget *widget, EVEWindow *window, uint16_t l, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
@@ -387,8 +422,8 @@ void eve_textw_putc(void *_page, int c) {
}
r = cursor1->line;
- if (cursor1->line) r = eve_textw_update(widget, page, cursor1->line - 1);
- if ((cursor1->line == 0) || (r == cursor1->line - 1)) r = eve_textw_update(widget, page, cursor1->line);
+ if (cursor1->line) r = eve_textw_text_update(widget, page, cursor1->line - 1);
+ if ((cursor1->line == 0) || (r == cursor1->line - 1)) r = eve_textw_text_update(widget, page, cursor1->line);
if (cursor1->line && (cursor1->ch < LINE_START(widget, cursor1->line))) {
cursor1->line--;
@@ -403,7 +438,7 @@ void eve_textw_putc(void *_page, int c) {
}
}
-uint16_t eve_textw_update(EVETextWidget *widget, EVEPage *page, uint16_t line) {
+uint16_t eve_textw_text_update(EVETextWidget *widget, EVEPage *page, uint16_t line) {
int i;
utf32_t ch;
uint8_t ch_w;
diff --git a/fw/fe310/eos/eve/widget/textw.h b/fw/fe310/eos/eve/widget/textw.h
index cd46ea3..36ab466 100644
--- a/fw/fe310/eos/eve/widget/textw.h
+++ b/fw/fe310/eos/eve/widget/textw.h
@@ -29,11 +29,21 @@ typedef struct EVETextWidget {
} track;
} EVETextWidget;
+typedef struct EVETextSpec {
+ EVEFont *font;
+ uint16_t text_size;
+ uint16_t line_size;
+} EVETextSpec;
+
+int eve_textw_create(EVETextWidget *widget, EVERect *g, EVETextSpec *spec);
+void eve_textw_destroy(EVETextWidget *widget);
void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size);
+void eve_textw_update(EVETextWidget *widget, EVEFont *font, utf8_t *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);
uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
void eve_textw_putc(void *_w, int c);
-uint16_t eve_textw_update(EVETextWidget *widget, EVEPage *page, uint16_t line);
+uint16_t eve_textw_text_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(EVETextWidget *widget, EVETextCursor *cursor);
diff --git a/fw/fe310/eos/eve/widget/widget.c b/fw/fe310/eos/eve/widget/widget.c
index ab121d8..7c1fcad 100644
--- a/fw/fe310/eos/eve/widget/widget.c
+++ b/fw/fe310/eos/eve/widget/widget.c
@@ -8,19 +8,34 @@
#include "screen/screen.h"
#include "screen/window.h"
#include "screen/page.h"
-#include "screen/font.h"
-#include "label.h"
-#include "widget.h"
-#include "pagew.h"
-#include "strw.h"
-#include "textw.h"
+#include "widgets.h"
-static const size_t _eve_wsize[] = {
+static const size_t _widget_size[] = {
0,
+ sizeof(EVEFreeWidget),
+ sizeof(EVESpacerWidget),
sizeof(EVEPageWidget),
sizeof(EVEStrWidget),
- sizeof(EVETextWidget)
+ sizeof(EVETextWidget),
+};
+
+static const eve_widget_create_t _widget_create[] = {
+ NULL,
+ (eve_widget_create_t)eve_freew_create,
+ (eve_widget_create_t)eve_spacerw_create,
+ (eve_widget_create_t)eve_pagew_create,
+ (eve_widget_create_t)eve_strw_create,
+ (eve_widget_create_t)eve_textw_create,
+};
+
+static const eve_widget_destroy_t _widget_destroy[] = {
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ (eve_widget_destroy_t)eve_strw_destroy,
+ (eve_widget_destroy_t)eve_textw_destroy,
};
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) {
@@ -31,11 +46,23 @@ void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, eve_widget_tou
widget->type = type;
}
+size_t eve_widget_size(uint8_t type) {
+ return _widget_size[type];
+}
+
void eve_widget_set_label(EVEWidget *widget, EVELabel *label) {
widget->label = label;
}
EVEWidget *eve_widget_next(EVEWidget *widget) {
char *_w = (char *)widget;
- return (EVEWidget *)(_w + _eve_wsize[widget->type]);
+ return (EVEWidget *)(_w + _widget_size[widget->type]);
+}
+
+int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEWidgetSpec *spec) {
+ return _widget_create[type](widget, g, spec);
}
+
+void eve_widget_destroy(EVEWidget *widget) {
+ if (_widget_destroy[widget->type]) _widget_destroy[widget->type](widget);
+} \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/widget.h b/fw/fe310/eos/eve/widget/widget.h
index 1aa2cd7..cff5c1d 100644
--- a/fw/fe310/eos/eve/widget/widget.h
+++ b/fw/fe310/eos/eve/widget/widget.h
@@ -1,8 +1,10 @@
#include <stdint.h>
-#define EVE_WIDGET_TYPE_PAGE 1
-#define EVE_WIDGET_TYPE_STR 2
-#define EVE_WIDGET_TYPE_TEXT 3
+#define EVE_WIDGET_TYPE_FREE 1
+#define EVE_WIDGET_TYPE_SPACER 2
+#define EVE_WIDGET_TYPE_PAGE 3
+#define EVE_WIDGET_TYPE_STR 4
+#define EVE_WIDGET_TYPE_TEXT 5
struct EVEWidget;
@@ -19,5 +21,6 @@ typedef struct EVEWidget {
} 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);
+size_t eve_widget_size(uint8_t type);
void eve_widget_set_label(EVEWidget *widget, EVELabel *label);
EVEWidget *eve_widget_next(EVEWidget *widget);
diff --git a/fw/fe310/eos/eve/widget/widgets.h b/fw/fe310/eos/eve/widget/widgets.h
new file mode 100644
index 0000000..4206894
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/widgets.h
@@ -0,0 +1,23 @@
+#include "font.h"
+#include "label.h"
+#include "widget.h"
+
+#include "freew.h"
+#include "spacerw.h"
+#include "pagew.h"
+#include "strw.h"
+#include "textw.h"
+
+typedef union EVEWidgetSpec {
+ EVEFreeSpec free;
+ EVESpacerSpec spacer;
+ EVEPageSpec page;
+ EVEStrSpec str;
+ EVETextSpec text;
+} EVEWidgetSpec;
+
+typedef int (*eve_widget_create_t) (EVEWidget *, EVERect *g, EVEWidgetSpec *);
+typedef void (*eve_widget_destroy_t) (EVEWidget *);
+
+int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEWidgetSpec *spec);
+void eve_widget_destroy(EVEWidget *widget);
diff --git a/fw/fe310/test/Makefile b/fw/fe310/test/Makefile
index f6b619c..24efa2f 100644
--- a/fw/fe310/test/Makefile
+++ b/fw/fe310/test/Makefile
@@ -1,6 +1,6 @@
include ../common.mk
-CFLAGS += -I.. -I../bsp/include -I../bsp/drivers
+CFLAGS += -I../eos -I../bsp/include -I../bsp/drivers
LDFLAGS = $(CFLAGS) -L.. -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -Wl,--end-group -T../bsp/default.lds
TARGET = modem
diff --git a/fw/fe310/test/modem.c b/fw/fe310/test/modem.c
index e89112b..736b8e0 100644
--- a/fw/fe310/test/modem.c
+++ b/fw/fe310/test/modem.c
@@ -2,17 +2,17 @@
#include <stdlib.h>
#include <unistd.h>
-#include <eos/eos.h>
-#include <eos/event.h>
-#include <eos/timer.h>
-#include <eos/uart.h>
-#include <eos/i2s.h>
-#include <eos/spi.h>
-#include <eos/net.h>
-#include <eos/cell.h>
-#include <eos/eve/eve.h>
-#include <eos/eve/eve_kbd.h>
-#include <eos/eve/eve_text.h>
+#include <eos.h>
+#include <event.h>
+#include <timer.h>
+#include <uart.h>
+#include <i2s.h>
+#include <spi.h>
+#include <net.h>
+#include <cell.h>
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_text.h>
#define ABUF_SIZE 512
#define MIC_WM 128