Browse Source

lvgl build redesign

master
Martin Vladic 2 years ago
parent
commit
aede7f8a87
  1. 2
      eez
  2. 10
      src/flow.cpp
  3. 4
      src/ui/flow_def.c
  4. 23
      src/ui/flow_def.h
  5. 60
      src/ui/screens.c
  6. 29
      src/ui/screens.h

2
eez

@ -1 +1 @@
Subproject commit fb7c4d556883c8171083e4c6393e886235ff8289
Subproject commit 8edf48aa91160dbb0ebc7421661ff7932d6b8e24

10
src/flow.cpp

@ -26,7 +26,7 @@ static lv_obj_t *getLvglObjectFromIndex(int32_t index) {
if (index == -1) {
return 0;
}
return get_screen(currentScreen)[index];
return ((lv_obj_t **)&objects)[index];
}
static const void *getLvglImageByName(const char *name) {
@ -40,14 +40,14 @@ static const void *getLvglImageByName(const char *name) {
extern "C" void loadScreen(int index) {
currentScreen = index;
lv_obj_t *screen = getLvglObjectFromIndex(0);
lv_obj_t *screen = getLvglObjectFromIndex(index);
lv_scr_load_anim(screen, LV_SCR_LOAD_ANIM_FADE_IN, 200, 0, false);
}
extern "C" void flowInit() {
#if HAS_FLOW_SUPPORT
eez::initAssetsMemory();
eez::loadMainAssets(eez::assets, sizeof(eez::assets));
eez::loadMainAssets(assets, sizeof(assets));
eez::initOtherMemory();
eez::initAllocHeap(eez::ALLOC_BUFFER, eez::ALLOC_BUFFER_SIZE);
@ -57,8 +57,10 @@ extern "C" void flowInit() {
eez::flow::start(eez::g_mainAssets);
create_screens();
replacePageHook(1, 0, 0, 0);
#else
create_screens();
loadScreen(0);
#endif
}
@ -79,7 +81,7 @@ ActionExecFunc g_actionExecFunctions[] = { 0 };
void replacePageHook(int16_t pageId, uint32_t animType, uint32_t speed, uint32_t delay) {
eez::flow::onPageChanged(currentScreen + 1, pageId);
currentScreen = pageId - 1;
lv_scr_load_anim(get_screen(currentScreen)[0], (lv_scr_load_anim_t)animType, speed, delay, false);
lv_scr_load_anim(getLvglObjectFromIndex(currentScreen), (lv_scr_load_anim_t)animType, speed, delay, false);
}
extern "C" void flowOnPageLoaded(int pageIndex) {

4
src/ui/flow_def.cpp → src/ui/flow_def.c

@ -1,7 +1,5 @@
#include "flow_def.h"
namespace eez {
// ASSETS DEFINITION
const uint8_t assets[508] = {
0x7E, 0x65, 0x65, 0x7A, 0x03, 0x00, 0x06, 0x00, 0xB8, 0x03, 0x00, 0x00, 0x6E, 0x24, 0x00, 0x00,
@ -37,5 +35,3 @@ const uint8_t assets[508] = {
0x98, 0x03, 0x00, 0x00, 0xA8, 0x03, 0x00, 0x00, 0x03, 0x03, 0x68, 0x00, 0x03, 0x08, 0x01, 0x00,
0x04, 0xB0, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
} // namespace eez

23
src/ui/flow_def.h

@ -1,23 +1,8 @@
#pragma once
#ifndef EEZ_LVGL_UI_FLOW_DEF_H
#define EEZ_LVGL_UI_FLOW_DEF_H
#include <eez/gui/data.h>
#include <eez/gui/widget.h>
#include "lvgl/lvgl.h"
namespace eez {
enum ThemesEnum {
THEME_ID_DEFAULT = 0
};
enum ColorsEnum {
COLOR_ID_TRANSPARENT = 65535,
COLOR_ID_COLOR = 0,
COLOR_ID_BACKGROUND_COLOR = 1,
COLOR_ID_CUSTOM_UNDEFINED = 2
};
#include <stdint.h>
extern const uint8_t assets[508];
} // namespace eez
#endif /*EEZ_LVGL_UI_FLOW_DEF_H*/

60
src/ui/screens.c

@ -4,6 +4,8 @@
#include "actions.h"
#include "../flow.h"
objects_t objects;
static void event_handler_cb_main_button_1(lv_event_t *e) {
lv_event_code_t event = lv_event_get_code(e);
if (event == LV_EVENT_PRESSED) {
@ -18,18 +20,15 @@ static void event_handler_cb_main_button_2(lv_event_t *e) {
}
}
main_t *create_screen_main() {
main_t *screen = (main_t *)lv_mem_alloc(sizeof(main_t));
void create_screen_main() {
lv_obj_t *obj = lv_obj_create(0);
screen->screen_obj = obj;
objects.main = obj;
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, 800, 480);
{
lv_obj_t *parent_obj = obj;
{
// image_1
lv_obj_t *obj = lv_img_create(parent_obj);
screen->obj_image_1 = obj;
lv_obj_set_pos(obj, 130, 79);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_img_set_src(obj, &img_log_eez);
@ -37,9 +36,7 @@ main_t *create_screen_main() {
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
}
{
// image_2
lv_obj_t *obj = lv_img_create(parent_obj);
screen->obj_image_2 = obj;
lv_obj_set_pos(obj, 457, 79);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_img_set_src(obj, &img_logo_lvgl);
@ -47,29 +44,24 @@ main_t *create_screen_main() {
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
}
{
// label_1
lv_obj_t *obj = lv_label_create(parent_obj);
screen->obj_label_1 = obj;
objects.label_1 = obj;
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_style_align(obj, LV_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_font(obj, &lv_font_montserrat_32, LV_PART_MAIN | LV_STATE_DEFAULT);
}
{
// button_1
lv_obj_t *obj = lv_btn_create(parent_obj);
screen->obj_button_1 = obj;
lv_obj_set_pos(obj, 268, 348);
lv_obj_set_size(obj, 100, 40);
lv_obj_add_event_cb(obj, event_handler_cb_main_button_1, LV_EVENT_ALL, screen);
lv_obj_add_event_cb(obj, event_handler_cb_main_button_1, LV_EVENT_ALL, 0);
lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
{
lv_obj_t *parent_obj = obj;
{
// label_2
lv_obj_t *obj = lv_label_create(parent_obj);
screen->obj_label_2 = obj;
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_label_set_text(obj, "+");
@ -79,20 +71,16 @@ main_t *create_screen_main() {
}
}
{
// button_2
lv_obj_t *obj = lv_btn_create(parent_obj);
screen->obj_button_2 = obj;
lv_obj_set_pos(obj, 408, 348);
lv_obj_set_size(obj, 100, 40);
lv_obj_add_event_cb(obj, event_handler_cb_main_button_2, LV_EVENT_ALL, screen);
lv_obj_add_event_cb(obj, event_handler_cb_main_button_2, LV_EVENT_ALL, 0);
lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
{
lv_obj_t *parent_obj = obj;
{
// label_3
lv_obj_t *obj = lv_label_create(parent_obj);
screen->obj_label_3 = obj;
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_label_set_text(obj, "-");
@ -102,43 +90,27 @@ main_t *create_screen_main() {
}
}
}
return screen;
}
void tick_screen_main(main_t *screen) {
void tick_screen_main() {
{
const char *new_val = evalTextProperty(0, 2, 2, "Failed to evaluate Text in Label widget");
const char *cur_val = lv_label_get_text(screen->obj_label_1);
if (strcmp(new_val, cur_val) != 0) lv_label_set_text(screen->obj_label_1, new_val);
const char *cur_val = lv_label_get_text(objects.label_1);
if (strcmp(new_val, cur_val) != 0) lv_label_set_text(objects.label_1, new_val);
}
}
#include <assert.h>
typedef screen_t (*create_screen_func_t)();
create_screen_func_t create_screen_funcs[] = {
(create_screen_func_t)create_screen_main,
};
void create_screens() {
create_screen_main();
}
typedef void (*tick_screen_func_t)(screen_t);
typedef void (*tick_screen_func_t)();
tick_screen_func_t tick_screen_funcs[] = {
(tick_screen_func_t)tick_screen_main,
tick_screen_main,
};
screen_t screens[NUM_SCREENS];
screen_t get_screen(int screen_index) {
assert(screen_index >= 0 && screen_index < NUM_SCREENS);
if (!screens[screen_index]) {
screens[screen_index] = create_screen_funcs[screen_index]();
}
return screens[screen_index];
}
void tick_screen(int screen_index) {
assert(screen_index >= 0 && screen_index < NUM_SCREENS);
tick_screen_funcs[screen_index](get_screen(screen_index));
tick_screen_funcs[screen_index]();
}

29
src/ui/screens.h

@ -7,30 +7,17 @@
extern "C" {
#endif
typedef struct _main_t {
lv_obj_t *screen_obj;
lv_obj_t *obj_image_1;
lv_obj_t *obj_image_2;
lv_obj_t *obj_label_1;
lv_obj_t *obj_button_1;
lv_obj_t *obj_label_2;
lv_obj_t *obj_button_2;
lv_obj_t *obj_label_3;
} main_t;
typedef struct _objects_t {
lv_obj_t *main;
lv_obj_t *label_1;
} objects_t;
main_t *create_screen_main();
void tick_screen_main(main_t *screen);
extern objects_t objects;
void create_screen_main();
void tick_screen_main();
typedef lv_obj_t **screen_t;
enum {
SCREEN_MAIN,
NUM_SCREENS
};
screen_t get_screen(int screen_index);
void create_screens();
void tick_screen(int screen_index);

Loading…
Cancel
Save