1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

fix(theme) simplify the default theme

This commit is contained in:
Gabor Kiss-Vamosi 2021-04-28 10:11:26 +02:00
parent 5dc0e37ce3
commit 4f46336a54
8 changed files with 32 additions and 59 deletions

View File

@ -463,8 +463,8 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
#define LV_USE_THEME_DEFAULT 1
#if LV_USE_THEME_DEFAULT
/*1: Light mode; 0: Dark mode*/
# define LV_THEME_DEFAULT_PALETTE_LIGHT 1
/*0: Light mode; 1: Dark mode*/
# define LV_THEME_DEFAULT_DARK 0
/*1: Enable grow on press*/
# define LV_THEME_DEFAULT_GROW 1

View File

@ -95,18 +95,6 @@ const lv_font_t * lv_theme_get_font_large(lv_obj_t * obj)
return th ? th->font_large : LV_FONT_DEFAULT;
}
lv_palette_t lv_theme_get_palette_primary(lv_obj_t * obj)
{
lv_theme_t * th = lv_theme_get_from_obj(obj);
return th ? th->palette_primary : LV_PALETTE_BLUE_GREY;
}
lv_palette_t lv_theme_get_palette_secondary(lv_obj_t * obj)
{
lv_theme_t * th = lv_theme_get_from_obj(obj);
return th ? th->palette_secondary : LV_PALETTE_BLUE;
}
lv_color_t lv_theme_get_color_primary(lv_obj_t * obj)
{
lv_theme_t * th = lv_theme_get_from_obj(obj);

View File

@ -33,8 +33,6 @@ typedef struct _lv_theme_t {
struct _lv_theme_t * parent; /**< Apply the current theme's style on top of this theme.*/
void * user_data;
struct _lv_disp_t * disp;
lv_palette_t palette_primary;
lv_palette_t palette_secondary;
lv_color_t color_primary;
lv_color_t color_secondary;
const lv_font_t * font_small;
@ -94,10 +92,6 @@ const lv_font_t * lv_theme_get_font_normal(lv_obj_t * obj);
*/
const lv_font_t * lv_theme_get_font_large(lv_obj_t * obj);
lv_palette_t lv_theme_get_palette_primary(lv_obj_t * obj);
lv_palette_t lv_theme_get_palette_secondary(lv_obj_t * obj);
/**
* Get the primary color of the theme
* @return the color

View File

@ -33,8 +33,8 @@
#define BORDER_WIDTH LV_DPX(2)
#define OUTLINE_WIDTH LV_DPX(3)
#define PAD_DEF (disp_size == DISP_LARGE ? LV_DPX(24) : disp_size == DISP_MEDIUM ? LV_DPX(20) : LV_DPX(20))
#define PAD_SMALL (disp_size == DISP_LARGE ? LV_DPX(14) : disp_size == DISP_MEDIUM ? LV_DPX(12) : LV_DPX(12))
#define PAD_DEF (disp_size == DISP_LARGE ? LV_DPX(24) : disp_size == DISP_MEDIUM ? LV_DPX(20) : LV_DPX(16))
#define PAD_SMALL (disp_size == DISP_LARGE ? LV_DPX(14) : disp_size == DISP_MEDIUM ? LV_DPX(12) : LV_DPX(10))
#define PAD_TINY (disp_size == DISP_LARGE ? LV_DPX(8) : disp_size == DISP_MEDIUM ? LV_DPX(6) : LV_DPX(2))
/**********************
@ -165,8 +165,6 @@ static my_theme_styles_t * styles;
static lv_theme_t theme;
static disp_size_t disp_size;
static bool inited;
static lv_color_t color_primary;
static lv_color_t color_secondary;
static lv_color_t color_scr;
static lv_color_t color_text;
static lv_color_t color_card;
@ -206,17 +204,11 @@ static void style_init(void)
0
};
color_primary = lv_palette_main(theme.palette_primary);
color_secondary = lv_palette_main(theme.palette_secondary);
color_scr = theme.flags & MODE_DARK ? DARK_COLOR_SCR : LIGHT_COLOR_SCR;
color_text = theme.flags & MODE_DARK ? DARK_COLOR_TEXT : LIGHT_COLOR_TEXT;
color_card = theme.flags & MODE_DARK ? DARK_COLOR_CARD : LIGHT_COLOR_CARD;
color_grey = theme.flags & MODE_DARK ? DARK_COLOR_GREY : LIGHT_COLOR_GREY;
theme.color_primary = color_primary;
theme.color_secondary = color_secondary;
static lv_style_transition_dsc_t trans_delayed;
lv_style_transition_dsc_init(&trans_delayed, trans_props, lv_anim_path_linear, TRANSITION_TIME, 70);
@ -263,13 +255,13 @@ static void style_init(void)
lv_style_set_line_width(&styles->card, LV_DPX(1));
style_init_reset(&styles->outline_primary);
lv_style_set_outline_color(&styles->outline_primary, color_primary);
lv_style_set_outline_color(&styles->outline_primary, theme.color_primary);
lv_style_set_outline_width(&styles->outline_primary, OUTLINE_WIDTH);
lv_style_set_outline_pad(&styles->outline_primary, OUTLINE_WIDTH);
lv_style_set_outline_opa(&styles->outline_primary, LV_OPA_50);
style_init_reset(&styles->outline_secondary);
lv_style_set_outline_color(&styles->outline_secondary, color_secondary);
lv_style_set_outline_color(&styles->outline_secondary, theme.color_secondary);
lv_style_set_outline_width(&styles->outline_secondary, OUTLINE_WIDTH);
lv_style_set_outline_opa(&styles->outline_secondary, LV_OPA_50);
@ -338,23 +330,23 @@ static void style_init(void)
lv_style_set_pad_column(&styles->pad_tiny, PAD_TINY);
style_init_reset(&styles->bg_color_primary);
lv_style_set_bg_color(&styles->bg_color_primary, color_primary);
lv_style_set_bg_color(&styles->bg_color_primary, theme.color_primary);
lv_style_set_text_color(&styles->bg_color_primary, lv_color_white());
lv_style_set_bg_opa(&styles->bg_color_primary, LV_OPA_COVER);
style_init_reset(&styles->bg_color_primary_muted);
lv_style_set_bg_color(&styles->bg_color_primary_muted, color_primary);
lv_style_set_text_color(&styles->bg_color_primary_muted, color_primary);
lv_style_set_bg_color(&styles->bg_color_primary_muted, theme.color_primary);
lv_style_set_text_color(&styles->bg_color_primary_muted, theme.color_primary);
lv_style_set_bg_opa(&styles->bg_color_primary_muted, LV_OPA_20);
style_init_reset(&styles->bg_color_secondary);
lv_style_set_bg_color(&styles->bg_color_secondary, color_secondary);
lv_style_set_bg_color(&styles->bg_color_secondary, theme.color_secondary);
lv_style_set_text_color(&styles->bg_color_secondary, lv_color_white());
lv_style_set_bg_opa(&styles->bg_color_secondary, LV_OPA_COVER);
style_init_reset(&styles->bg_color_secondary_muted);
lv_style_set_bg_color(&styles->bg_color_secondary_muted, color_secondary);
lv_style_set_text_color(&styles->bg_color_secondary_muted, color_secondary);
lv_style_set_bg_color(&styles->bg_color_secondary_muted, theme.color_secondary);
lv_style_set_text_color(&styles->bg_color_secondary_muted, theme.color_secondary);
lv_style_set_bg_opa(&styles->bg_color_secondary_muted, LV_OPA_20);
style_init_reset(&styles->bg_color_grey);
@ -380,7 +372,7 @@ static void style_init(void)
#endif
style_init_reset(&styles->knob);
lv_style_set_bg_color(&styles->knob, color_primary);
lv_style_set_bg_color(&styles->knob, theme.color_primary);
lv_style_set_bg_opa(&styles->knob, LV_OPA_COVER);
lv_style_set_pad_all(&styles->knob, LV_DPX(6));
lv_style_set_radius(&styles->knob, LV_RADIUS_CIRCLE);
@ -395,14 +387,14 @@ static void style_init(void)
lv_style_set_arc_rounded(&styles->arc_indic, true);
style_init_reset(&styles->arc_indic_primary);
lv_style_set_arc_color(&styles->arc_indic_primary, color_primary);
lv_style_set_arc_color(&styles->arc_indic_primary, theme.color_primary);
#endif
#if LV_USE_CHECKBOX
style_init_reset(&styles->cb_marker);
lv_style_set_pad_all(&styles->cb_marker, LV_DPX(3));
lv_style_set_border_width(&styles->cb_marker, BORDER_WIDTH);
lv_style_set_border_color(&styles->cb_marker, color_primary);
lv_style_set_border_color(&styles->cb_marker, theme.color_primary);
lv_style_set_bg_color(&styles->cb_marker, color_card);
lv_style_set_bg_opa(&styles->cb_marker, LV_OPA_COVER);
lv_style_set_radius(&styles->cb_marker, RADIUS_DEFAULT / 2);
@ -514,7 +506,7 @@ static void style_init(void)
#if LV_USE_TABVIEW
style_init_reset(&styles->tab_btn);
lv_style_set_border_color(&styles->tab_btn, color_primary);
lv_style_set_border_color(&styles->tab_btn, theme.color_primary);
lv_style_set_border_width(&styles->tab_btn, BORDER_WIDTH * 2);
lv_style_set_border_side(&styles->tab_btn, LV_BORDER_SIDE_BOTTOM);
#endif
@ -557,8 +549,7 @@ static void style_init(void)
* GLOBAL FUNCTIONS
**********************/
lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_palette_t palette_primary, lv_palette_t palette_secondary, bool dark,
const lv_font_t * font_small, const lv_font_t * font_normal, const lv_font_t * font_large)
lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_color_t color_primary, lv_color_t color_secondary, bool dark, const lv_font_t * font)
{
/*This trick is required only to avoid the garbage collection of
@ -574,11 +565,11 @@ lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_palette_t palette_primar
else disp_size = DISP_LARGE;
theme.disp = disp;
theme.palette_primary = palette_primary;
theme.palette_secondary = palette_secondary;
theme.font_small = font_small;
theme.font_normal = font_normal;
theme.font_large = font_large;
theme.color_primary = color_primary;
theme.color_secondary = color_secondary;
theme.font_small = font;
theme.font_normal = font;
theme.font_large = font;
theme.apply_cb = theme_apply;
theme.flags = dark ? MODE_DARK : 0;
@ -938,6 +929,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
#if LV_USE_TABVIEW
if(lv_obj_check_type(obj, &lv_tabview_class)) {
lv_obj_add_style(obj, &styles->scr, 0);
lv_obj_add_style(obj, &styles->pad_zero, 0);
return;
}
#endif

View File

@ -36,8 +36,7 @@ extern "C" {
* @param font pointer to a font to use.
* @return a pointer to reference this theme later
*/
lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_palette_t palette_primary, lv_palette_t palette_secondary,
bool dark, const lv_font_t * font_small, const lv_font_t * font_normal, const lv_font_t * font_large);
lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_color_t color_primary, lv_color_t color_secondary, bool dark, const lv_font_t * font);
bool lv_theme_default_is_inited(void);

View File

@ -132,7 +132,7 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver)
#if LV_USE_THEME_DEFAULT
if(lv_theme_default_is_inited() == false) {
disp->theme = lv_theme_default_init(disp, LV_PALETTE_BLUE, LV_PALETTE_CYAN, !LV_THEME_DEFAULT_PALETTE_LIGHT, LV_FONT_DEFAULT, LV_FONT_DEFAULT, LV_FONT_DEFAULT);
disp->theme = lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT);
}
#endif

View File

@ -1398,12 +1398,12 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
#endif
#if LV_USE_THEME_DEFAULT
/*1: Light mode; 0: Dark mode*/
#ifndef LV_THEME_DEFAULT_PALETTE_LIGHT
# ifdef CONFIG_LV_THEME_DEFAULT_PALETTE_LIGHT
# define LV_THEME_DEFAULT_PALETTE_LIGHT CONFIG_LV_THEME_DEFAULT_PALETTE_LIGHT
/*0: Light mode; 1: Dark mode*/
#ifndef LV_THEME_DEFAULT_DARK
# ifdef CONFIG_LV_THEME_DEFAULT_DARK
# define LV_THEME_DEFAULT_DARK CONFIG_LV_THEME_DEFAULT_DARK
# else
# define LV_THEME_DEFAULT_PALETTE_LIGHT 1
# define LV_THEME_DEFAULT_DARK 0
# endif
#endif

View File

@ -43,8 +43,8 @@ static void draw_main(lv_event_t * e);
const lv_obj_class_t lv_switch_class = {
.constructor_cb = lv_switch_constructor,
.event_cb = lv_switch_event,
.width_def = (5 * LV_DPI_DEF) / 11,
.height_def = LV_DPI_DEF / 4,
.width_def = (4 * LV_DPI_DEF) / 10,
.height_def = (4 * LV_DPI_DEF) / 17,
.group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE,
.instance_size = sizeof(lv_switch_t),
.base_class = &lv_obj_class