lvgl-template-web/src/ui/screens.c
2024-10-08 12:18:46 +02:00

143 lines
4.9 KiB
C

#include <string.h>
#include "screens.h"
#include "images.h"
#include "fonts.h"
#include "actions.h"
#include "vars.h"
#include "styles.h"
#include "ui.h"
#include <string.h>
objects_t objects;
lv_obj_t *tick_value_change_obj;
static void event_handler_cb_main_obj1(lv_event_t *e) {
lv_event_code_t event = lv_event_get_code(e);
void *flowState = lv_event_get_user_data(e);
if (event == LV_EVENT_PRESSED) {
e->user_data = (void *)0;
flowPropagateValueLVGLEvent(flowState, 6, 0, e);
}
}
static void event_handler_cb_main_obj2(lv_event_t *e) {
lv_event_code_t event = lv_event_get_code(e);
void *flowState = lv_event_get_user_data(e);
if (event == LV_EVENT_PRESSED) {
e->user_data = (void *)0;
flowPropagateValueLVGLEvent(flowState, 8, 0, e);
}
}
void create_screen_main() {
void *flowState = getFlowState(0, 0);
lv_obj_t *obj = lv_obj_create(0);
objects.main = obj;
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, 800, 480);
{
lv_obj_t *parent_obj = obj;
{
lv_obj_t *obj = lv_img_create(parent_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);
lv_img_set_pivot(obj, 0, 0);
}
{
lv_obj_t *obj = lv_img_create(parent_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);
lv_img_set_pivot(obj, 0, 0);
}
{
lv_obj_t *obj = lv_label_create(parent_obj);
objects.obj0 = obj;
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_label_set_text(obj, "");
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);
}
{
lv_obj_t *obj = lv_btn_create(parent_obj);
objects.obj1 = 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_obj1, LV_EVENT_ALL, flowState);
{
lv_obj_t *parent_obj = obj;
{
lv_obj_t *obj = lv_label_create(parent_obj);
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_label_set_text(obj, "+");
lv_obj_set_style_text_font(obj, &lv_font_montserrat_48, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_align(obj, LV_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
}
}
}
{
lv_obj_t *obj = lv_btn_create(parent_obj);
objects.obj2 = 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_obj2, LV_EVENT_ALL, flowState);
{
lv_obj_t *parent_obj = obj;
{
lv_obj_t *obj = lv_label_create(parent_obj);
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_label_set_text(obj, "-");
lv_obj_set_style_text_font(obj, &lv_font_montserrat_48, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_align(obj, LV_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
}
}
}
}
}
void tick_screen_main() {
void *flowState = getFlowState(0, 0);
{
const char *new_val = evalTextProperty(flowState, 5, 3, "Failed to evaluate Text in Label widget");
const char *cur_val = lv_label_get_text(objects.obj0);
if (strcmp(new_val, cur_val) != 0) {
tick_value_change_obj = objects.obj0;
lv_label_set_text(objects.obj0, new_val);
tick_value_change_obj = NULL;
}
}
}
static const char *screen_names[] = { "Main" };
static const char *object_names[] = { "main", "obj0", "obj1", "obj2" };
void create_screens() {
eez_flow_init_screen_names(screen_names, sizeof(screen_names) / sizeof(const char *));
eez_flow_init_object_names(object_names, sizeof(object_names) / sizeof(const char *));
lv_disp_t *dispp = lv_disp_get_default();
lv_theme_t *theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), false, LV_FONT_DEFAULT);
lv_disp_set_theme(dispp, theme);
create_screen_main();
}
typedef void (*tick_screen_func_t)();
tick_screen_func_t tick_screen_funcs[] = {
tick_screen_main,
};
void tick_screen(int screen_index) {
tick_screen_funcs[screen_index]();
}