287 lines
8.3 KiB
C
287 lines
8.3 KiB
C
#include "lvgl.h"
|
|
|
|
#include "ui.h"
|
|
|
|
static const char* M_VAL_TIME = "VAL TIME?";
|
|
|
|
static const lv_font_t *font_normal = &lv_font_montserrat_24;
|
|
|
|
static lv_color_t color_primary, color_secondary;
|
|
static lv_color_t color_text_hero, color_text_subtitle;
|
|
|
|
static lv_style_t s_hero, s_subtitle;
|
|
|
|
static lv_obj_t *o_container = NULL;
|
|
|
|
static lv_anim_timeline_t *at_active = NULL;
|
|
static lv_obj_t *o_active = NULL;
|
|
static bool state_ready = true;
|
|
|
|
static const void* imgfont_get_path(
|
|
const lv_font_t *font, uint32_t unicode, uint32_t unicode_next, int32_t *offset_y, void *user_data) {
|
|
LV_UNUSED(font);
|
|
LV_UNUSED(unicode_next);
|
|
LV_UNUSED(offset_y);
|
|
LV_UNUSED(user_data);
|
|
|
|
switch (unicode) {
|
|
case 0x1F319:
|
|
return &ui_img_moon;
|
|
case 0x2B50:
|
|
return &ui_img_star;
|
|
case 0x1F634:
|
|
return &ui_img_sleep;
|
|
default:
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
static void b_cfg_cb(lv_event_t *e) {
|
|
lv_obj_t *box = lv_msgbox_create(NULL);
|
|
lv_msgbox_add_title(box, "Hello");
|
|
lv_msgbox_add_text(box, "test message");
|
|
lv_msgbox_add_close_button(box);
|
|
}
|
|
|
|
static void setup_next_state() {
|
|
assert(state_ready);
|
|
state_ready = false;
|
|
|
|
if (at_active) {
|
|
lv_anim_timeline_delete(at_active);
|
|
at_active = NULL;
|
|
}
|
|
if (o_active) {
|
|
lv_obj_delete(o_active);
|
|
o_active = NULL;
|
|
}
|
|
|
|
o_active = lv_obj_create(o_container);
|
|
lv_obj_center(o_active);
|
|
lv_obj_set_style_bg_opa(o_active, LV_OPA_0, 0);
|
|
lv_obj_set_style_border_width(o_active, 0, 0);
|
|
lv_obj_set_size(o_active, lv_pct(100), lv_pct(100));
|
|
|
|
at_active = lv_anim_timeline_create();
|
|
}
|
|
|
|
bool val_ui_state_ready() {
|
|
return state_ready;
|
|
}
|
|
|
|
static void anim_state_ready_cb(lv_anim_t *anim) {
|
|
state_ready = true;
|
|
}
|
|
static void anim_x_cb(void *var, int32_t v) {
|
|
lv_obj_set_x(var, v);
|
|
}
|
|
static void anim_y_cb(void *var, int32_t v) {
|
|
lv_obj_set_y(var, v);
|
|
}
|
|
static void anim_opa_cb(void *var, int32_t v) {
|
|
lv_obj_set_style_opa(var, v, 0);
|
|
}
|
|
static void anim_val_time_text(lv_anim_t *anim) {
|
|
lv_label_set_text_static(anim->var, M_VAL_TIME);
|
|
}
|
|
|
|
void val_ui_none() {
|
|
setup_next_state();
|
|
|
|
// Widgets
|
|
lv_obj_t *l_main = lv_label_create(o_active);
|
|
lv_obj_add_style(l_main, &s_hero, 0);
|
|
lv_obj_center(l_main);
|
|
lv_label_set_text_static(l_main, M_VAL_TIME);
|
|
|
|
lv_obj_t *l_subtitle = lv_label_create(o_active);
|
|
lv_obj_add_style(l_subtitle, &s_subtitle, 0);
|
|
lv_obj_center(l_subtitle);
|
|
lv_label_set_text_static(l_subtitle, "SOME VAL IS ALWAYS ON THE MENU...");
|
|
|
|
lv_obj_update_layout(o_active);
|
|
lv_obj_set_pos(
|
|
l_subtitle,
|
|
-(lv_obj_get_width(l_main) - lv_obj_get_width(l_subtitle)) / 2,
|
|
(lv_obj_get_height(l_main) + lv_obj_get_height(l_subtitle)) / 2 + 5);
|
|
|
|
lv_label_set_text_static(l_main, "HELLO \U0001F319\u2B50!");
|
|
lv_obj_update_layout(o_active);
|
|
|
|
// Animations
|
|
lv_anim_t a_hello_in;
|
|
lv_anim_init(&a_hello_in);
|
|
lv_anim_set_var(&a_hello_in, l_main);
|
|
lv_anim_set_values(
|
|
&a_hello_in,
|
|
(lv_obj_get_height(o_container) - lv_obj_get_height(l_main)) / 2, 0);
|
|
lv_anim_set_exec_cb(&a_hello_in, anim_y_cb);
|
|
lv_anim_set_path_cb(&a_hello_in, lv_anim_path_ease_in);
|
|
lv_anim_set_duration(&a_hello_in, 500);
|
|
|
|
lv_anim_t a_hello_out;
|
|
lv_anim_init(&a_hello_out);
|
|
lv_anim_set_var(&a_hello_out, l_main);
|
|
lv_anim_set_values(&a_hello_out, 255, 0);
|
|
lv_anim_set_exec_cb(&a_hello_out, anim_opa_cb);
|
|
lv_anim_set_path_cb(&a_hello_out, lv_anim_path_linear);
|
|
lv_anim_set_duration(&a_hello_out, 500);
|
|
|
|
lv_anim_t a_val;
|
|
lv_anim_init(&a_val);
|
|
lv_anim_set_early_apply(&a_val, false);
|
|
lv_anim_set_var(&a_val, l_main);
|
|
lv_anim_set_values(&a_val, 0, 255);
|
|
lv_anim_set_start_cb(&a_val, anim_val_time_text);
|
|
lv_anim_set_exec_cb(&a_val, anim_opa_cb);
|
|
lv_anim_set_path_cb(&a_val, lv_anim_path_linear);
|
|
lv_anim_set_duration(&a_val, 500);
|
|
|
|
lv_anim_t a_sub;
|
|
lv_anim_init(&a_sub);
|
|
lv_anim_set_var(&a_sub, l_subtitle);
|
|
lv_anim_set_values(&a_sub, 0, 255);
|
|
lv_anim_set_exec_cb(&a_sub, anim_opa_cb);
|
|
lv_anim_set_path_cb(&a_sub, lv_anim_path_linear);
|
|
lv_anim_set_completed_cb(&a_sub, anim_state_ready_cb);
|
|
lv_anim_set_duration(&a_sub, 750);
|
|
|
|
lv_anim_timeline_add(at_active, 0, &a_hello_in);
|
|
lv_anim_timeline_add(at_active, 3000, &a_hello_out);
|
|
lv_anim_timeline_add(at_active, 3250, &a_val);
|
|
lv_anim_timeline_add(at_active, 3750, &a_sub);
|
|
lv_anim_timeline_start(at_active);
|
|
}
|
|
|
|
void val_ui_menu(bool was_idle) {
|
|
setup_next_state();
|
|
|
|
// Widgets
|
|
lv_obj_t *l_main = lv_label_create(o_active);
|
|
lv_obj_add_style(l_main, &s_hero, 0);
|
|
lv_obj_center(l_main);
|
|
lv_label_set_text_static(l_main, "LET'S GO");
|
|
|
|
lv_obj_t *l_subtitle = lv_label_create(o_active);
|
|
lv_obj_add_style(l_subtitle, &s_subtitle, 0);
|
|
lv_obj_center(l_subtitle);
|
|
lv_label_set_text_static(l_subtitle, was_idle ? "WELCOME BACK!" : "GET QUEUEING!");
|
|
|
|
lv_obj_update_layout(o_active);
|
|
|
|
// Animations
|
|
lv_anim_t a_title;
|
|
lv_anim_init(&a_title);
|
|
lv_anim_set_var(&a_title, l_main);
|
|
lv_anim_set_values(
|
|
&a_title,
|
|
-(lv_obj_get_height(o_container) - lv_obj_get_height(l_main)) / 2, 0);
|
|
lv_anim_set_exec_cb(&a_title, anim_y_cb);
|
|
lv_anim_set_path_cb(&a_title, lv_anim_path_ease_in);
|
|
lv_anim_set_duration(&a_title, 500);
|
|
|
|
lv_anim_t a_sub;
|
|
lv_anim_init(&a_sub);
|
|
lv_anim_set_var(&a_sub, l_subtitle);
|
|
lv_anim_set_values(
|
|
&a_sub,
|
|
(lv_obj_get_height(o_container) - lv_obj_get_height(l_main)) / 2,
|
|
(lv_obj_get_height(l_main) + lv_obj_get_height(l_subtitle)) / 2 + 5);
|
|
lv_anim_set_exec_cb(&a_sub, anim_y_cb);
|
|
lv_anim_set_path_cb(&a_sub, lv_anim_path_ease_in);
|
|
lv_anim_set_completed_cb(&a_sub, anim_state_ready_cb);
|
|
lv_anim_set_duration(&a_sub, 500);
|
|
|
|
lv_anim_timeline_add(at_active, 0, &a_title);
|
|
lv_anim_timeline_add(at_active, 0, &a_sub);
|
|
lv_anim_timeline_start(at_active);
|
|
}
|
|
|
|
void val_ui_idle() {
|
|
setup_next_state();
|
|
|
|
// Widgets
|
|
lv_obj_t *l_main = lv_label_create(o_active);
|
|
lv_obj_add_style(l_main, &s_hero, 0);
|
|
lv_obj_center(l_main);
|
|
lv_label_set_text_static(l_main, "\U0001F634");
|
|
|
|
lv_obj_t *l_subtitle = lv_label_create(o_active);
|
|
lv_obj_add_style(l_subtitle, &s_subtitle, 0);
|
|
lv_obj_center(l_subtitle);
|
|
lv_label_set_text_static(l_subtitle, "COME BACK SOON...");
|
|
|
|
lv_obj_update_layout(o_active);
|
|
lv_obj_set_y(
|
|
l_subtitle,
|
|
(lv_obj_get_height(l_main) + lv_obj_get_height(l_subtitle)) / 2 + 5);
|
|
|
|
// Animations
|
|
lv_anim_t a_fade_in;
|
|
lv_anim_init(&a_fade_in);
|
|
lv_anim_set_values(&a_fade_in, 0, 255);
|
|
lv_anim_set_exec_cb(&a_fade_in, anim_opa_cb);
|
|
lv_anim_set_path_cb(&a_fade_in, lv_anim_path_ease_in);
|
|
lv_anim_set_duration(&a_fade_in, 1000);
|
|
|
|
lv_anim_set_var(&a_fade_in, l_main);
|
|
lv_anim_timeline_add(at_active, 0, &a_fade_in);
|
|
|
|
lv_anim_set_var(&a_fade_in, l_subtitle);
|
|
lv_anim_set_completed_cb(&a_fade_in, anim_state_ready_cb);
|
|
lv_anim_timeline_add(at_active, 0, &a_fade_in);
|
|
|
|
lv_anim_timeline_start(at_active);
|
|
}
|
|
|
|
void val_lvgl_ui(lv_display_t *disp) {
|
|
color_primary = lv_color_hex(0xff4655);
|
|
color_secondary = lv_color_hex(0xf7518f);
|
|
|
|
color_text_hero = lv_palette_lighten(LV_PALETTE_GREY, 2);
|
|
color_text_subtitle = lv_palette_darken(LV_PALETTE_GREY, 2);
|
|
|
|
// init default theme
|
|
lv_theme_default_init(
|
|
disp, color_primary, color_secondary,
|
|
true, // dark theme
|
|
font_normal);
|
|
// lv_sysmon_hide_performance(disp);
|
|
|
|
lv_font_t *f_hero_emoji = lv_imgfont_create(120, imgfont_get_path, NULL);
|
|
assert(f_hero_emoji);
|
|
f_hero_emoji->fallback = &lv_font_tungsten_180;
|
|
|
|
lv_style_init(&s_hero);
|
|
lv_style_set_text_font(&s_hero, f_hero_emoji);
|
|
lv_style_set_text_color(&s_hero, color_text_hero);
|
|
|
|
lv_style_init(&s_subtitle);
|
|
lv_style_set_text_font(&s_subtitle, &lv_font_tungsten_40);
|
|
lv_style_set_text_color(&s_subtitle, color_text_subtitle);
|
|
|
|
// Background
|
|
lv_obj_t *i_bg = lv_image_create(lv_screen_active());
|
|
lv_image_set_src(i_bg, &ui_img_bg);
|
|
|
|
// Content container
|
|
o_container = lv_obj_create(lv_screen_active());
|
|
lv_obj_set_style_bg_opa(o_container, LV_OPA_0, 0);
|
|
lv_obj_set_style_border_width(o_container, 0, 0);
|
|
lv_obj_set_style_pad_all(o_container, 0, 0);
|
|
lv_obj_set_size(o_container, lv_pct(100), lv_pct(100));
|
|
|
|
// Settings button
|
|
lv_obj_t *b_cfg = lv_button_create(lv_screen_active());
|
|
lv_obj_align(b_cfg, LV_ALIGN_BOTTOM_RIGHT, -10, -10);
|
|
lv_obj_add_event_cb(b_cfg, b_cfg_cb, LV_EVENT_CLICKED, NULL);
|
|
|
|
lv_obj_t *l_cfg = lv_label_create(b_cfg);
|
|
lv_label_set_text(l_cfg, LV_SYMBOL_SETTINGS);
|
|
lv_obj_center(l_cfg);
|
|
|
|
// val_ui_none();
|
|
// val_ui_menu(true);
|
|
val_ui_idle();
|
|
}
|