summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/app
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-02-28 21:00:13 +0100
committerUros Majstorovic <majstor@majstor.org>2021-02-28 21:00:13 +0100
commit82a6206422ed658a99716fbd18e33942cebc833b (patch)
treef849699cd7a31175c57c3d9583d2162786138e3c /fw/fe310/eos/app
parent6a4c8a1f11f6a7bd57b0fd618f455bcdecbfe538 (diff)
font property moved to widget base
Diffstat (limited to 'fw/fe310/eos/app')
-rw-r--r--fw/fe310/eos/app/root.c15
-rw-r--r--fw/fe310/eos/app/root.h17
2 files changed, 11 insertions, 21 deletions
diff --git a/fw/fe310/eos/app/root.c b/fw/fe310/eos/app/root.c
index 43bab11..ec0e4ea 100644
--- a/fw/fe310/eos/app/root.c
+++ b/fw/fe310/eos/app/root.c
@@ -5,6 +5,7 @@
#include "eve/eve.h"
#include "eve/eve_kbd.h"
+#include "eve/eve_font.h"
#include "eve/screen/screen.h"
#include "eve/screen/window.h"
@@ -17,8 +18,6 @@
#include "status.h"
#include "root.h"
-EVEFont *_app_font_default;
-
static EVEKbd kbd;
static EVEFont font;
static EVEScreen screen;
@@ -49,7 +48,6 @@ static uint8_t kbd_draw(EVEView *v, uint8_t tag0) {
void app_screen_init(eve_view_constructor_t home_page) {
EVERect g;
- _app_font_default = &font;
eve_spi_start();
eve_brightness(0x40);
@@ -107,11 +105,12 @@ static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) {
}
}
-EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor) {
+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;
@@ -131,7 +130,8 @@ EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec s
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);
+ _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);
@@ -139,6 +139,7 @@ EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec s
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);
@@ -147,9 +148,11 @@ EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec s
eve_free(form);
return NULL;
}
- eve_label_init(label, &spec[i].label.g, spec[i].label.font, spec[i].label.title);
+ 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);
}
diff --git a/fw/fe310/eos/app/root.h b/fw/fe310/eos/app/root.h
index 69624e7..9468e6e 100644
--- a/fw/fe310/eos/app/root.h
+++ b/fw/fe310/eos/app/root.h
@@ -6,24 +6,11 @@
#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;
+#define APP_LABEL_MARGIN 10
EVEScreen *app_screen(void);
void app_screen_init(eve_view_constructor_t home_page);
void app_screen_refresh(void);
-EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor);
+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);