fix(themes): load & apply properly

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 158e2550b9
commit 181e8ad77a
7 changed files with 65 additions and 141 deletions
+7 -122
View File
@@ -23,6 +23,8 @@
#include "LvglWrapper.h"
#include "themes/etx_lv_theme.h"
#include "widgets/field_edit.h"
#include "view_main.h"
LvglWrapper* LvglWrapper::_instance = nullptr;
@@ -220,137 +222,20 @@ static void init_lvgl_drivers()
keyboardDevice = lv_indev_drv_register(&keyboard_drv);
}
// The theme code needs to go somewhere else (gui/colorlcd/themes/default.cpp?)
static lv_style_t menu_line_style;
static lv_style_t menu_checked_style;
static lv_style_t textedit_style_main;
static lv_style_t textedit_style_focused;
static lv_style_t textedit_style_cursor;
static lv_style_t textedit_style_cursor_edit;
static lv_style_t numberedit_style_main;
static lv_style_t numberedit_style_focused;
static lv_style_t numberedit_style_cursor;
static lv_style_t numberedit_style_cursor_edit;
static void theme_apply_cb(lv_theme_t * th, lv_obj_t * obj)
void initLvglTheme()
{
LV_UNUSED(th);
if (lv_obj_check_type(obj, &lv_obj_class)) {
// lv_obj_add_style(obj, &generic_style, LV_PART_MAIN);
return;
}
lv_obj_t* parent = lv_obj_get_parent(obj);
if (parent == NULL) {
// main screen
return;
}
if (lv_obj_check_type(obj, &lv_numberedit_class)) {
lv_obj_add_style(obj, &numberedit_style_main, LV_PART_MAIN);
lv_obj_add_style(obj, &numberedit_style_focused, LV_PART_MAIN | LV_STATE_FOCUSED);
lv_obj_add_style(obj, &numberedit_style_cursor, LV_PART_CURSOR);
lv_obj_add_style(obj, &numberedit_style_cursor_edit, LV_PART_CURSOR | LV_STATE_EDITED);
return;
}
if (lv_obj_check_type(obj, &lv_textarea_class)) {
lv_obj_add_style(obj, &textedit_style_main, LV_PART_MAIN);
lv_obj_add_style(obj, &textedit_style_focused, LV_PART_MAIN | LV_STATE_FOCUSED);
lv_obj_add_style(obj, &textedit_style_cursor, LV_PART_CURSOR);
lv_obj_add_style(obj, &textedit_style_cursor_edit, LV_PART_CURSOR | LV_STATE_EDITED);
return;
}
}
static void init_theme()
{
/*Initialize the styles*/
// numberedit
// LV_PART_MAIN
lv_style_init(&numberedit_style_main);
lv_style_init(&numberedit_style_focused);
lv_style_init(&numberedit_style_cursor);
lv_style_init(&numberedit_style_cursor_edit);
lv_style_set_border_width(&numberedit_style_main, 1);
lv_style_set_border_color(&numberedit_style_main, makeLvColor(COLOR_THEME_SECONDARY2));
lv_style_set_bg_color(&numberedit_style_main, makeLvColor(COLOR_THEME_PRIMARY2));
lv_style_set_bg_opa(&numberedit_style_main, LV_OPA_COVER);
lv_style_set_text_color(&numberedit_style_main, makeLvColor(COLOR_THEME_SECONDARY1));
lv_style_set_pad_left(&numberedit_style_main, FIELD_PADDING_LEFT);
lv_style_set_pad_top(&numberedit_style_main, FIELD_PADDING_TOP);
// LV_STATE_FOCUSED
lv_style_set_bg_color(&numberedit_style_focused, makeLvColor(COLOR_THEME_FOCUS));
lv_style_set_text_color(&numberedit_style_focused, makeLvColor(COLOR_THEME_PRIMARY2));
// Hide cursor when not editing
lv_style_set_opa(&numberedit_style_cursor, LV_OPA_0);
// Show Cursor in "Edit" mode
lv_style_set_opa(&numberedit_style_cursor_edit, LV_OPA_COVER);
lv_style_set_bg_opa(&numberedit_style_cursor_edit, LV_OPA_50);
// textedit
lv_style_init(&textedit_style_main);
lv_style_init(&textedit_style_focused);
lv_style_init(&textedit_style_cursor);
lv_style_init(&textedit_style_cursor_edit);
// textedit style main
lv_style_set_border_width(&textedit_style_main, 1);
lv_style_set_border_color(&textedit_style_main, makeLvColor(COLOR_THEME_SECONDARY2));
lv_style_set_bg_color(&textedit_style_main, makeLvColor(COLOR_THEME_PRIMARY2));
lv_style_set_bg_opa(&textedit_style_main, LV_OPA_COVER);
lv_style_set_text_color(&textedit_style_main, makeLvColor(COLOR_THEME_SECONDARY1));
lv_style_set_pad_left(&textedit_style_main, FIELD_PADDING_LEFT);
lv_style_set_pad_top(&textedit_style_main, FIELD_PADDING_TOP);
//textedit style focused
lv_style_set_bg_color(&textedit_style_focused, makeLvColor(COLOR_THEME_FOCUS));
lv_style_set_text_color(&textedit_style_focused, makeLvColor(COLOR_THEME_PRIMARY2));
// hide cursor when not editing
lv_style_set_opa(&textedit_style_cursor, LV_OPA_0);
// Show Cursor in "Edit" mode
lv_style_set_opa(&textedit_style_cursor_edit, LV_OPA_COVER);
lv_style_set_bg_opa(&textedit_style_cursor_edit, LV_OPA_50);
// Menus
lv_style_init(&menu_line_style);
lv_style_set_bg_opa(&menu_line_style, LV_OPA_100);
lv_style_set_bg_color(&menu_line_style, makeLvColor(COLOR_THEME_PRIMARY2));
lv_style_init(&menu_checked_style);
lv_style_set_border_width(&menu_checked_style, 1);
lv_style_set_border_color(&menu_checked_style, makeLvColor(COLOR_THEME_FOCUS));
lv_style_set_text_color(&menu_checked_style, makeLvColor(COLOR_THEME_PRIMARY2));
lv_style_set_bg_color(&menu_checked_style, makeLvColor(COLOR_THEME_FOCUS));
/*Initialize the new theme from the current theme*/
lv_theme_t *th_act = etx_lv_theme_init(
/* Initialize the ETX theme */
lv_theme_t* th = etx_lv_theme_init(
NULL, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
false, LV_FONT_DEFAULT);
static lv_theme_t th_new;
th_new = *th_act;
/*Set the parent theme and the style apply callback for the new theme*/
lv_theme_set_parent(&th_new, th_act);
lv_theme_set_apply_cb(&th_new, theme_apply_cb);
/*Assign the new theme to the current display*/
lv_disp_set_theme(NULL, &th_new);
/* Assign the theme to the current display*/
lv_disp_set_theme(NULL, th);
}
LvglWrapper::LvglWrapper()
{
init_lvgl_drivers();
init_theme();
// Create main window and load that screen
auto window = MainWindow::instance();
+2
View File
@@ -80,4 +80,6 @@ class LvglWrapper
static void runNested();
};
void initLvglTheme();
#endif // _LVGLWRAPPER_H_
+1 -1
View File
@@ -42,7 +42,7 @@ void InputMixButton::value_changed(lv_event_t* e)
}
InputMixButton::InputMixButton(Window* parent, uint8_t index) :
Button(parent, rect_t{}, nullptr, 0, COLOR_THEME_PRIMARY1,
Button(parent, rect_t{}, nullptr, 0, 0/*COLOR_THEME_PRIMARY1*/,
input_mix_line_create),
index(index)
{
-3
View File
@@ -212,9 +212,6 @@ void loadTheme()
loadTheme(newTheme);
else
loadTheme(defaultTheme);
// else {
// loadTheme(theme);
// }
}
MenuWindowContent * createMenuWindow(Menu * menu)
@@ -177,6 +177,7 @@ class Theme480: public OpenTxTheme
{
loadIcons(reload);
if (reload) loadBuiltinBitmaps();
initLvglTheme();
}
void drawBackground(BitmapBuffer * dc) const override
+53 -14
View File
@@ -11,6 +11,8 @@
#include "font.h"
#include "libopenui_config.h"
#include "widgets/field_edit.h"
#include "lvgl_widgets/input_mix_line.h"
#include "lvgl_widgets/input_mix_group.h"
@@ -23,10 +25,10 @@ extern lv_color_t makeLvColor(uint32_t colorFlags);
#define RADIUS_DEFAULT (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 12) : lv_disp_dpx(theme.disp, 8))
/*SCREEN*/
#define LIGHT_COLOR_SCR lv_palette_lighten(LV_PALETTE_GREY, 4)
#define LIGHT_COLOR_CARD lv_color_white()
#define LIGHT_COLOR_TEXT lv_palette_darken(LV_PALETTE_GREY, 4)
#define LIGHT_COLOR_GREY lv_palette_lighten(LV_PALETTE_GREY, 2)
#define LIGHT_COLOR_SCR makeLvColor(COLOR_THEME_SECONDARY3)
#define LIGHT_COLOR_CARD makeLvColor(COLOR_THEME_PRIMARY2)
#define LIGHT_COLOR_TEXT makeLvColor(COLOR_THEME_PRIMARY1)
#define LIGHT_COLOR_GREY makeLvColor(COLOR_THEME_SECONDARY2)
#define DARK_COLOR_SCR lv_color_hex(0x15171A)
#define DARK_COLOR_CARD lv_color_hex(0x282b30)
#define DARK_COLOR_TEXT lv_palette_lighten(LV_PALETTE_GREY, 5)
@@ -50,6 +52,7 @@ typedef struct {
lv_style_t card;
lv_style_t btn;
lv_style_t line_btn;
lv_style_t field;
/*Utility*/
lv_style_t bg_color_primary;
@@ -60,6 +63,7 @@ typedef struct {
lv_style_t bg_color_white;
lv_style_t bg_color_active;
lv_style_t bg_color_focus;
lv_style_t bg_color_edit;
lv_style_t pressed;
lv_style_t disabled;
lv_style_t focus_border;
@@ -123,6 +127,7 @@ typedef struct {
#if LV_USE_TEXTAREA
lv_style_t ta_cursor, ta_placeholder;
lv_style_t field_cursor, edit_cursor;
#endif
#if LV_USE_CALENDAR
@@ -314,6 +319,18 @@ static void style_init(void)
lv_style_set_border_width(&styles.line_btn, BORDER_WIDTH);
lv_style_set_border_color(&styles.line_btn, makeLvColor(COLOR_THEME_SECONDARY2));
style_init_reset(&styles.field);
lv_style_set_border_width(&styles.field, lv_dpx(1));
lv_style_set_border_color(&styles.field, makeLvColor(COLOR_THEME_SECONDARY2));
lv_style_set_bg_color(&styles.field, makeLvColor(COLOR_THEME_PRIMARY2));
lv_style_set_bg_opa(&styles.field, LV_OPA_COVER);
lv_style_set_text_color(&styles.field, makeLvColor(COLOR_THEME_SECONDARY1));
lv_style_set_pad_left(&styles.field, lv_dpx(3));
lv_style_set_pad_top(&styles.field, lv_dpx(3));
static lv_color_filter_dsc_t dark_filter;
lv_color_filter_dsc_init(&dark_filter, dark_color_filter_cb);
@@ -392,9 +409,9 @@ static void style_init(void)
lv_style_set_text_color(&styles.bg_color_grey, color_text);
style_init_reset(&styles.bg_color_white);
lv_style_set_bg_color(&styles.bg_color_white, color_card);
lv_style_set_bg_color(&styles.bg_color_white, makeLvColor(COLOR_THEME_PRIMARY2));
lv_style_set_bg_opa(&styles.bg_color_white, LV_OPA_COVER);
lv_style_set_text_color(&styles.bg_color_white, color_text);
lv_style_set_text_color(&styles.bg_color_white, makeLvColor(COLOR_THEME_PRIMARY1));
style_init_reset(&styles.bg_color_active);
lv_style_set_bg_color(&styles.bg_color_active, makeLvColor(COLOR_THEME_ACTIVE));
@@ -406,6 +423,11 @@ static void style_init(void)
lv_style_set_bg_opa(&styles.bg_color_focus, LV_OPA_COVER);
lv_style_set_text_color(&styles.bg_color_focus, makeLvColor(COLOR_THEME_PRIMARY2));
style_init_reset(&styles.bg_color_edit);
lv_style_set_bg_color(&styles.bg_color_edit, makeLvColor(COLOR_THEME_EDIT));
lv_style_set_bg_opa(&styles.bg_color_edit, LV_OPA_COVER);
lv_style_set_text_color(&styles.bg_color_edit, makeLvColor(COLOR_THEME_PRIMARY2));
style_init_reset(&styles.circle);
lv_style_set_radius(&styles.circle, LV_RADIUS_CIRCLE);
@@ -596,6 +618,15 @@ static void style_init(void)
style_init_reset(&styles.ta_placeholder);
lv_style_set_text_color(&styles.ta_placeholder, (theme.flags & MODE_DARK) ? lv_palette_darken(LV_PALETTE_GREY,
2) : lv_palette_lighten(LV_PALETTE_GREY, 1));
// field_cursor, edit_cursor
style_init_reset(&styles.field_cursor);
lv_style_set_opa(&styles.field_cursor, LV_OPA_0);
style_init_reset(&styles.edit_cursor);
lv_style_set_opa(&styles.edit_cursor, LV_OPA_COVER);
lv_style_set_bg_opa(&styles.edit_cursor, LV_OPA_50);
#endif
#if LV_USE_CALENDAR
@@ -802,7 +833,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
else if(lv_obj_check_type(obj, &input_mix_line_class)) {
lv_obj_add_style(obj, &styles.line_btn, 0);
lv_obj_add_style(obj, &styles.pad_small, 0);
lv_obj_add_style(obj, &styles.bg_color_active, LV_STATE_CHECKED);
lv_obj_set_style_bg_color(obj, makeLvColor(COLOR_THEME_SECONDARY3), LV_STATE_CHECKED);
lv_obj_add_style(obj, &styles.focus_border, LV_STATE_FOCUSED);
}
#endif
@@ -980,15 +1011,23 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
#if LV_USE_TEXTAREA
else if(lv_obj_check_type(obj, &lv_textarea_class)) {
// lv_obj_add_style(obj, &styles.card, 0);
// lv_obj_add_style(obj, &styles.pad_small, 0);
// lv_obj_add_style(obj, &styles.outline_primary, LV_STATE_FOCUS_KEY);
// lv_obj_add_style(obj, &styles.outline_secondary, LV_STATE_EDITED);
lv_obj_add_style(obj, &styles.card, 0);
lv_obj_add_style(obj, &styles.pad_small, 0);
lv_obj_add_style(obj, &styles.outline_primary, LV_STATE_FOCUS_KEY);
lv_obj_add_style(obj, &styles.outline_secondary, LV_STATE_EDITED);
lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR);
lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
lv_obj_add_style(obj, &styles.ta_cursor, LV_PART_CURSOR | LV_STATE_FOCUSED);
lv_obj_add_style(obj, &styles.ta_placeholder, LV_PART_TEXTAREA_PLACEHOLDER);
}
else if(lv_obj_check_type(obj, &field_edit_class)) {
lv_obj_add_style(obj, &styles.field, 0);
lv_obj_add_style(obj, &styles.bg_color_focus, LV_STATE_FOCUSED);
lv_obj_add_style(obj, &styles.bg_color_edit, LV_STATE_EDITED);
lv_obj_add_style(obj, &styles.field_cursor, LV_PART_CURSOR);
lv_obj_add_style(obj, &styles.edit_cursor, LV_PART_CURSOR | LV_STATE_EDITED);
}
#endif
#if LV_USE_CALENDAR
@@ -1021,9 +1060,9 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
lv_obj_add_style(obj, &styles.bg_color_white, LV_PART_ITEMS);
lv_obj_add_style(obj, &styles.keyboard_btn_bg, LV_PART_ITEMS);
lv_obj_add_style(obj, &styles.pressed, LV_PART_ITEMS | LV_STATE_PRESSED);
lv_obj_add_style(obj, &styles.bg_color_grey, LV_PART_ITEMS | LV_STATE_CHECKED);
lv_obj_add_style(obj, &styles.bg_color_primary_muted, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
lv_obj_add_style(obj, &styles.bg_color_secondary_muted, LV_PART_ITEMS | LV_STATE_EDITED);
lv_obj_add_style(obj, &styles.bg_color_active, LV_PART_ITEMS | LV_STATE_CHECKED);
lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_ITEMS | LV_STATE_EDITED);
}
#endif
#if LV_USE_LIST