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

theme: allow live theme update

This commit is contained in:
Gabor Kiss-Vamosi 2020-03-31 13:54:06 +02:00
parent 8bf1cc6f6b
commit 7d5acdcf33
5 changed files with 56 additions and 55 deletions

View File

@ -140,7 +140,7 @@ void lv_init(void)
lv_ll_init(&LV_GC_ROOT(_lv_obj_style_trans_ll), sizeof(lv_style_trans_t)); lv_ll_init(&LV_GC_ROOT(_lv_obj_style_trans_ll), sizeof(lv_style_trans_t));
lv_theme_t * th = LV_THEME_DEFAULT_INIT(LV_THEME_DEFAULT_COLOR_PRIMARY, LV_THEME_DEFAULT_COLOR_SECONDARY, lv_theme_t * th = LV_THEME_DEFAULT_INIT(LV_THEME_DEFAULT_COLOR_PRIMARY, LV_THEME_DEFAULT_COLOR_SECONDARY,
0, LV_THEME_DEFAULT_FLAG,
LV_THEME_DEFAULT_FONT_SMALL, LV_THEME_DEFAULT_FONT_NORMAL, LV_THEME_DEFAULT_FONT_SUBTITLE, LV_THEME_DEFAULT_FONT_TITLE); LV_THEME_DEFAULT_FONT_SMALL, LV_THEME_DEFAULT_FONT_NORMAL, LV_THEME_DEFAULT_FONT_SUBTITLE, LV_THEME_DEFAULT_FONT_TITLE);
lv_theme_set_act(th); lv_theme_set_act(th);

View File

@ -563,6 +563,7 @@ static inline lv_color_t grad_get(lv_draw_rect_dsc_t * dsc, lv_coord_t s, lv_coo
lv_opa_t mix = (i * 255) / d; lv_opa_t mix = (i * 255) / d;
return lv_color_mix(dsc->bg_grad_color, dsc->bg_color, mix); return lv_color_mix(dsc->bg_grad_color, dsc->bg_color, mix);
} }
#if LV_USE_SHADOW #if LV_USE_SHADOW
static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc) static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc)
{ {

View File

@ -145,6 +145,13 @@ typedef enum {
typedef struct { typedef struct {
void (*apply_cb)(lv_obj_t *, lv_theme_style_t); void (*apply_cb)(lv_obj_t *, lv_theme_style_t);
lv_color_t color_primary;
lv_color_t color_secondary;
const lv_font_t * font_small;
const lv_font_t * font_normal;
const lv_font_t * font_subtitle;
const lv_font_t * font_title;
uint32_t flags;
} lv_theme_t; } lv_theme_t;
/********************** /**********************

View File

@ -24,22 +24,22 @@
/*BUTTON*/ /*BUTTON*/
#define COLOR_BTN (IS_LIGHT ? lv_color_hex(0xffffff) : lv_color_hex(0x303439)) #define COLOR_BTN (IS_LIGHT ? lv_color_hex(0xffffff) : lv_color_hex(0x303439))
#define COLOR_BTN_PR (IS_LIGHT ? lv_color_mix(_color_primary, COLOR_BTN, LV_OPA_10) : lv_color_mix(_color_primary, COLOR_BTN, LV_OPA_10)) #define COLOR_BTN_PR (IS_LIGHT ? lv_color_mix(theme.color_primary, COLOR_BTN, LV_OPA_10) : lv_color_mix(theme.color_primary, COLOR_BTN, LV_OPA_10))
#define COLOR_BTN_CHK (_color_primary) #define COLOR_BTN_CHK (theme.color_primary)
#define COLOR_BTN_CHK_PR (lv_color_darken(_color_primary, LV_OPA_30)) #define COLOR_BTN_CHK_PR (lv_color_darken(theme.color_primary, LV_OPA_30))
#define COLOR_BTN_DIS (IS_LIGHT ? lv_color_hex3(0x888) : lv_color_hex3(0x888)) #define COLOR_BTN_DIS (IS_LIGHT ? lv_color_hex3(0x888) : lv_color_hex3(0x888))
#define COLOR_BTN_BORDER _color_primary #define COLOR_BTN_BORDER theme.color_primary
#define COLOR_BTN_BORDER_PR _color_primary #define COLOR_BTN_BORDER_PR theme.color_primary
#define COLOR_BTN_BORDER_CHK _color_primary #define COLOR_BTN_BORDER_CHK theme.color_primary
#define COLOR_BTN_BORDER_CHK_PR _color_primary #define COLOR_BTN_BORDER_CHK_PR theme.color_primary
#define COLOR_BTN_BORDER_INA (IS_LIGHT ? lv_color_hex(0x606060) : lv_color_hex(0x404040)) #define COLOR_BTN_BORDER_INA (IS_LIGHT ? lv_color_hex(0x606060) : lv_color_hex(0x404040))
/*BACKGROUND*/ /*BACKGROUND*/
#define COLOR_BG (IS_LIGHT ? lv_color_hex(0xffffff) : lv_color_hex(0x303439)) #define COLOR_BG (IS_LIGHT ? lv_color_hex(0xffffff) : lv_color_hex(0x303439))
#define COLOR_BG_PR (IS_LIGHT ? lv_color_hex(0xeeeeee) : lv_color_hex(0x494f57)) #define COLOR_BG_PR (IS_LIGHT ? lv_color_hex(0xeeeeee) : lv_color_hex(0x494f57))
#define COLOR_BG_CHK _color_primary #define COLOR_BG_CHK theme.color_primary
#define COLOR_BG_PR_CHK lv_color_darken(_color_primary, LV_OPA_20) #define COLOR_BG_PR_CHK lv_color_darken(theme.color_primary, LV_OPA_20)
#define COLOR_BG_DIS COLOR_BG #define COLOR_BG_DIS COLOR_BG
#define COLOR_BG_BORDER (IS_LIGHT ? lv_color_hex(0xdfe7ed) : lv_color_hex(0x404040)) #define COLOR_BG_BORDER (IS_LIGHT ? lv_color_hex(0xdfe7ed) : lv_color_hex(0x404040))
@ -62,7 +62,7 @@
#define TRANSITION_TIME 150 #define TRANSITION_TIME 150
#define IS_LIGHT palette == LV_THEME_MATERIAL_PALETTE_LIGHT #define IS_LIGHT (theme.flags & LV_THEME_MATERIAL_FLAG_LIGHT)
/********************** /**********************
* TYPEDEFS * TYPEDEFS
@ -77,13 +77,6 @@ static void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name);
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
static lv_theme_t theme; static lv_theme_t theme;
static lv_color_t _color_primary;
static lv_color_t _color_secondary;
static lv_font_t * _font_small;
static lv_font_t * _font_normal;
static lv_font_t * _font_subtitle;
static lv_font_t * _font_title;
static lv_theme_material_palette_t palette = LV_THEME_MATERIAL_PALETTE_LIGHT;
static lv_style_t scr; static lv_style_t scr;
static lv_style_t bg; static lv_style_t bg;
@ -199,10 +192,10 @@ static void basic_init(void)
lv_style_set_bg_opa(&bg, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&bg, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&bg, LV_STATE_DEFAULT, COLOR_BG); lv_style_set_bg_color(&bg, LV_STATE_DEFAULT, COLOR_BG);
lv_style_set_border_color(&bg, LV_STATE_DEFAULT, COLOR_BG_BORDER); lv_style_set_border_color(&bg, LV_STATE_DEFAULT, COLOR_BG_BORDER);
lv_style_set_border_color(&bg, LV_STATE_FOCUSED, _color_primary); lv_style_set_border_color(&bg, LV_STATE_FOCUSED, theme.color_primary);
lv_style_set_border_width(&bg, LV_STATE_DEFAULT, (LV_DPI / 60 > 0 ? LV_DPI / 60 : 1)); lv_style_set_border_width(&bg, LV_STATE_DEFAULT, (LV_DPI / 60 > 0 ? LV_DPI / 60 : 1));
lv_style_set_border_post(&bg, LV_STATE_DEFAULT, true); lv_style_set_border_post(&bg, LV_STATE_DEFAULT, true);
lv_style_set_text_font(&bg, LV_STATE_DEFAULT, _font_normal); lv_style_set_text_font(&bg, LV_STATE_DEFAULT, theme.font_normal);
lv_style_set_text_color(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT); lv_style_set_text_color(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT);
lv_style_set_value_color(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT); lv_style_set_value_color(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT);
lv_style_set_image_recolor(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT); lv_style_set_image_recolor(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT);
@ -231,7 +224,7 @@ static void basic_init(void)
lv_style_set_bg_color(&bg_click, LV_STATE_PRESSED | LV_STATE_CHECKED, COLOR_BG_PR_CHK); lv_style_set_bg_color(&bg_click, LV_STATE_PRESSED | LV_STATE_CHECKED, COLOR_BG_PR_CHK);
lv_style_set_bg_color(&bg_click, LV_STATE_DISABLED, COLOR_BG_DIS); lv_style_set_bg_color(&bg_click, LV_STATE_DISABLED, COLOR_BG_DIS);
lv_style_set_border_width(&bg_click, LV_STATE_CHECKED, 0); lv_style_set_border_width(&bg_click, LV_STATE_CHECKED, 0);
lv_style_set_border_color(&bg_click, LV_STATE_FOCUSED | LV_STATE_PRESSED, lv_color_darken(_color_primary, LV_OPA_20)); lv_style_set_border_color(&bg_click, LV_STATE_FOCUSED | LV_STATE_PRESSED, lv_color_darken(theme.color_primary, LV_OPA_20));
lv_style_set_border_color(&bg_click, LV_STATE_PRESSED, COLOR_BG_BORDER_PR); lv_style_set_border_color(&bg_click, LV_STATE_PRESSED, COLOR_BG_BORDER_PR);
lv_style_set_border_color(&bg_click, LV_STATE_CHECKED, COLOR_BG_BORDER_CHK); lv_style_set_border_color(&bg_click, LV_STATE_CHECKED, COLOR_BG_BORDER_CHK);
lv_style_set_border_color(&bg_click, LV_STATE_PRESSED | LV_STATE_CHECKED, COLOR_BG_BORDER_CHK_PR); lv_style_set_border_color(&bg_click, LV_STATE_PRESSED | LV_STATE_CHECKED, COLOR_BG_BORDER_CHK_PR);
@ -286,7 +279,7 @@ static void basic_init(void)
lv_style_set_outline_width(&btn, LV_STATE_DEFAULT, 3); lv_style_set_outline_width(&btn, LV_STATE_DEFAULT, 3);
lv_style_set_outline_opa(&btn, LV_STATE_DEFAULT, LV_OPA_0); lv_style_set_outline_opa(&btn, LV_STATE_DEFAULT, LV_OPA_0);
lv_style_set_outline_opa(&btn, LV_STATE_FOCUSED, LV_OPA_50); lv_style_set_outline_opa(&btn, LV_STATE_FOCUSED, LV_OPA_50);
lv_style_set_outline_color(&btn, LV_STATE_DEFAULT, _color_primary); lv_style_set_outline_color(&btn, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_transition_time(&btn, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_time(&btn, LV_STATE_DEFAULT, TRANSITION_TIME);
lv_style_set_transition_prop_5(&btn, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); lv_style_set_transition_prop_5(&btn, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR);
lv_style_set_transition_prop_6(&btn, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA); lv_style_set_transition_prop_6(&btn, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA);
@ -333,7 +326,7 @@ static void bar_init(void)
lv_style_set_bg_opa(&bar_bg, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&bar_bg, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&bar_bg, LV_STATE_DEFAULT, COLOR_BG_SEC); lv_style_set_bg_color(&bar_bg, LV_STATE_DEFAULT, COLOR_BG_SEC);
lv_style_set_value_color(&bar_bg, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); lv_style_set_value_color(&bar_bg, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE);
lv_style_set_outline_color(&bar_bg, LV_STATE_DEFAULT, _color_primary); lv_style_set_outline_color(&bar_bg, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_outline_opa(&bar_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_outline_opa(&bar_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_style_set_outline_opa(&bar_bg, LV_STATE_FOCUSED, LV_OPA_50); lv_style_set_outline_opa(&bar_bg, LV_STATE_FOCUSED, LV_OPA_50);
lv_style_set_outline_width(&bar_bg, LV_STATE_DEFAULT, 3); lv_style_set_outline_width(&bar_bg, LV_STATE_DEFAULT, 3);
@ -343,7 +336,7 @@ static void bar_init(void)
lv_style_init(&bar_indic); lv_style_init(&bar_indic);
lv_style_set_bg_opa(&bar_indic, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&bar_indic, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_radius(&bar_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_radius(&bar_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_bg_color(&bar_indic, LV_STATE_DEFAULT, _color_primary); lv_style_set_bg_color(&bar_indic, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_bg_color(&bar_indic, LV_STATE_DISABLED, lv_color_hex3(0x888)); lv_style_set_bg_color(&bar_indic, LV_STATE_DISABLED, lv_color_hex3(0x888));
lv_style_set_value_color(&bar_indic, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); lv_style_set_value_color(&bar_indic, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE);
#endif #endif
@ -368,13 +361,13 @@ static void led_init(void)
#if LV_USE_LED != 0 #if LV_USE_LED != 0
lv_style_init(&led); lv_style_init(&led);
lv_style_set_bg_opa(&led, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&led, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&led, LV_STATE_DEFAULT, _color_primary); lv_style_set_bg_color(&led, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_border_width(&led, LV_STATE_DEFAULT, 2); lv_style_set_border_width(&led, LV_STATE_DEFAULT, 2);
lv_style_set_border_opa(&led, LV_STATE_DEFAULT, LV_OPA_50); lv_style_set_border_opa(&led, LV_STATE_DEFAULT, LV_OPA_50);
lv_style_set_border_color(&led, LV_STATE_DEFAULT, lv_color_lighten(_color_primary, LV_OPA_30)); lv_style_set_border_color(&led, LV_STATE_DEFAULT, lv_color_lighten(theme.color_primary, LV_OPA_30));
lv_style_set_radius(&led, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_radius(&led, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_shadow_width(&led, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_shadow_width(&led, LV_STATE_DEFAULT, LV_DPI / 10);
lv_style_set_shadow_color(&led, LV_STATE_DEFAULT, _color_primary); lv_style_set_shadow_color(&led, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_shadow_spread(&led, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_shadow_spread(&led, LV_STATE_DEFAULT, LV_DPI / 20);
#endif #endif
} }
@ -384,7 +377,7 @@ static void slider_init(void)
#if LV_USE_SLIDER != 0 #if LV_USE_SLIDER != 0
lv_style_init(&slider_knob); lv_style_init(&slider_knob);
lv_style_set_bg_opa(&slider_knob, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&slider_knob, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&slider_knob, LV_STATE_DEFAULT, IS_LIGHT ? _color_primary : LV_COLOR_WHITE); lv_style_set_bg_color(&slider_knob, LV_STATE_DEFAULT, IS_LIGHT ? theme.color_primary : LV_COLOR_WHITE);
lv_style_set_value_color(&slider_knob, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); lv_style_set_value_color(&slider_knob, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE);
lv_style_set_radius(&slider_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_radius(&slider_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_pad_left(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_pad_left(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20);
@ -420,8 +413,8 @@ static void linemeter_init(void)
lv_style_set_pad_inner(&lmeter, LV_STATE_DEFAULT, LV_DPI / 6); lv_style_set_pad_inner(&lmeter, LV_STATE_DEFAULT, LV_DPI / 6);
lv_style_set_scale_width(&lmeter, LV_STATE_DEFAULT, LV_DPI / 8); lv_style_set_scale_width(&lmeter, LV_STATE_DEFAULT, LV_DPI / 8);
lv_style_set_line_color(&lmeter, LV_STATE_DEFAULT, _color_primary); lv_style_set_line_color(&lmeter, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_scale_grad_color(&lmeter, LV_STATE_DEFAULT, _color_primary); lv_style_set_scale_grad_color(&lmeter, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_scale_end_color(&lmeter, LV_STATE_DEFAULT, lv_color_hex3(0x666)); lv_style_set_scale_end_color(&lmeter, LV_STATE_DEFAULT, lv_color_hex3(0x666));
lv_style_set_line_rounded(&lmeter, LV_STATE_DEFAULT, true); lv_style_set_line_rounded(&lmeter, LV_STATE_DEFAULT, true);
lv_style_set_line_width(&lmeter, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_line_width(&lmeter, LV_STATE_DEFAULT, LV_DPI / 20);
@ -435,7 +428,7 @@ static void gauge_init(void)
lv_style_init(&gauge_main); lv_style_init(&gauge_main);
lv_style_set_line_color(&gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_line_color(&gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888));
lv_style_set_scale_grad_color(&gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_scale_grad_color(&gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888));
lv_style_set_scale_end_color(&gauge_main, LV_STATE_DEFAULT, _color_primary); lv_style_set_scale_end_color(&gauge_main, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_line_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 40); lv_style_set_line_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 40);
lv_style_set_scale_end_line_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_scale_end_line_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 50);
lv_style_set_scale_end_border_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_scale_end_border_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 25);
@ -450,7 +443,7 @@ static void gauge_init(void)
lv_style_init(&gauge_strong); lv_style_init(&gauge_strong);
lv_style_set_line_color(&gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_line_color(&gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888));
lv_style_set_scale_grad_color(&gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_scale_grad_color(&gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888));
lv_style_set_scale_end_color(&gauge_strong, LV_STATE_DEFAULT, _color_primary); lv_style_set_scale_end_color(&gauge_strong, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25);
lv_style_set_scale_end_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_scale_end_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25);
lv_style_set_scale_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 6); lv_style_set_scale_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 6);
@ -470,7 +463,7 @@ static void arc_init(void)
{ {
#if LV_USE_ARC != 0 #if LV_USE_ARC != 0
lv_style_init(&arc_indic); lv_style_init(&arc_indic);
lv_style_set_line_color(&arc_indic, LV_STATE_DEFAULT, _color_primary); lv_style_set_line_color(&arc_indic, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_line_width(&arc_indic, LV_STATE_DEFAULT, LV_DPI / 8); lv_style_set_line_width(&arc_indic, LV_STATE_DEFAULT, LV_DPI / 8);
lv_style_set_line_rounded(&arc_indic, LV_STATE_DEFAULT, true); lv_style_set_line_rounded(&arc_indic, LV_STATE_DEFAULT, true);
@ -529,16 +522,16 @@ static void calendar_init(void)
lv_style_init(&calendar_date_nums); lv_style_init(&calendar_date_nums);
lv_style_set_radius(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_radius(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 50);
lv_style_set_text_color(&calendar_date_nums, LV_STATE_CHECKED, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); lv_style_set_text_color(&calendar_date_nums, LV_STATE_CHECKED, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE);
lv_style_set_text_color(&calendar_date_nums, LV_STATE_FOCUSED, _color_primary); lv_style_set_text_color(&calendar_date_nums, LV_STATE_FOCUSED, theme.color_primary);
lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_CHECKED, LV_OPA_20); lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_CHECKED, LV_OPA_20);
lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED, LV_OPA_20); lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED, LV_OPA_20);
lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED | LV_STATE_CHECKED, LV_OPA_40); lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED | LV_STATE_CHECKED, LV_OPA_40);
lv_style_set_bg_color(&calendar_date_nums, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x666666) : LV_COLOR_WHITE); lv_style_set_bg_color(&calendar_date_nums, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x666666) : LV_COLOR_WHITE);
lv_style_set_bg_color(&calendar_date_nums, LV_STATE_CHECKED, IS_LIGHT ? _color_primary : LV_COLOR_WHITE); lv_style_set_bg_color(&calendar_date_nums, LV_STATE_CHECKED, IS_LIGHT ? theme.color_primary : LV_COLOR_WHITE);
lv_style_set_border_width(&calendar_date_nums, LV_STATE_CHECKED, 2); lv_style_set_border_width(&calendar_date_nums, LV_STATE_CHECKED, 2);
lv_style_set_border_side(&calendar_date_nums, LV_STATE_CHECKED, LV_BORDER_SIDE_LEFT); lv_style_set_border_side(&calendar_date_nums, LV_STATE_CHECKED, LV_BORDER_SIDE_LEFT);
lv_style_set_border_color(&calendar_date_nums, LV_STATE_CHECKED, _color_primary); lv_style_set_border_color(&calendar_date_nums, LV_STATE_CHECKED, theme.color_primary);
lv_style_set_pad_inner(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 40); lv_style_set_pad_inner(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 40);
lv_style_set_pad_left(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 9); lv_style_set_pad_left(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 9);
lv_style_set_pad_right(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 9); lv_style_set_pad_right(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 9);
@ -575,7 +568,7 @@ static void checkbox_init(void)
lv_style_init(&cb_bg); lv_style_init(&cb_bg);
lv_style_set_radius(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_radius(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 50);
lv_style_set_pad_inner(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_pad_inner(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_outline_color(&cb_bg, LV_STATE_DEFAULT, _color_primary); lv_style_set_outline_color(&cb_bg, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_outline_opa(&cb_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_outline_opa(&cb_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_style_set_outline_opa(&cb_bg, LV_STATE_FOCUSED, LV_OPA_50); lv_style_set_outline_opa(&cb_bg, LV_STATE_FOCUSED, LV_OPA_50);
lv_style_set_outline_width(&cb_bg, LV_STATE_DEFAULT, 3); lv_style_set_outline_width(&cb_bg, LV_STATE_DEFAULT, 3);
@ -588,7 +581,7 @@ static void checkbox_init(void)
lv_style_set_radius(&cb_bullet, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_radius(&cb_bullet, LV_STATE_DEFAULT, LV_DPI / 50);
lv_style_set_pattern_image(&cb_bullet, LV_STATE_CHECKED, LV_SYMBOL_OK); lv_style_set_pattern_image(&cb_bullet, LV_STATE_CHECKED, LV_SYMBOL_OK);
lv_style_set_pattern_recolor(&cb_bullet, LV_STATE_CHECKED, LV_COLOR_WHITE); lv_style_set_pattern_recolor(&cb_bullet, LV_STATE_CHECKED, LV_COLOR_WHITE);
lv_style_set_text_font(&cb_bullet, LV_STATE_CHECKED, _font_small); lv_style_set_text_font(&cb_bullet, LV_STATE_CHECKED, theme.font_small);
lv_style_set_transition_time(&cb_bullet, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_time(&cb_bullet, LV_STATE_DEFAULT, TRANSITION_TIME);
lv_style_set_transition_prop_5(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); lv_style_set_transition_prop_5(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR);
lv_style_set_transition_prop_6(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BORDER_COLOR); lv_style_set_transition_prop_6(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BORDER_COLOR);
@ -651,7 +644,7 @@ static void spinbox_init(void)
lv_style_init(&spinbox_cursor); lv_style_init(&spinbox_cursor);
lv_style_set_bg_opa(&spinbox_cursor, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&spinbox_cursor, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&spinbox_cursor, LV_STATE_DEFAULT, _color_primary); lv_style_set_bg_color(&spinbox_cursor, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_text_color(&spinbox_cursor, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_text_color(&spinbox_cursor, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_style_set_pad_top(&spinbox_cursor, LV_STATE_DEFAULT, LV_DPI); lv_style_set_pad_top(&spinbox_cursor, LV_STATE_DEFAULT, LV_DPI);
lv_style_set_pad_bottom(&spinbox_cursor, LV_STATE_DEFAULT, LV_DPI); lv_style_set_pad_bottom(&spinbox_cursor, LV_STATE_DEFAULT, LV_DPI);
@ -715,7 +708,7 @@ static void ddlist_init(void)
lv_style_init(&ddlist_sel); lv_style_init(&ddlist_sel);
lv_style_set_bg_opa(&ddlist_sel, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&ddlist_sel, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&ddlist_sel, LV_STATE_DEFAULT, _color_primary); lv_style_set_bg_color(&ddlist_sel, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_text_color(&ddlist_sel, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex3(0x333) : lv_color_hex3(0xfff)); lv_style_set_text_color(&ddlist_sel, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex3(0x333) : lv_color_hex3(0xfff));
lv_style_set_bg_color(&ddlist_sel, LV_STATE_PRESSED, COLOR_BG_PR); lv_style_set_bg_color(&ddlist_sel, LV_STATE_PRESSED, COLOR_BG_PR);
#endif #endif
@ -729,7 +722,7 @@ static void roller_init(void)
lv_style_init(&roller_sel); lv_style_init(&roller_sel);
lv_style_set_bg_opa(&roller_sel, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&roller_sel, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&roller_sel, LV_STATE_DEFAULT, _color_primary); lv_style_set_bg_color(&roller_sel, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_text_color(&roller_sel, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_text_color(&roller_sel, LV_STATE_DEFAULT, LV_COLOR_WHITE);
#endif #endif
} }
@ -745,7 +738,7 @@ static void tabview_init(void)
lv_style_set_border_width(&tabview_btns_bg, LV_STATE_DEFAULT, LV_DPI / 30 > 0 ? LV_DPI / 30 : 1); lv_style_set_border_width(&tabview_btns_bg, LV_STATE_DEFAULT, LV_DPI / 30 > 0 ? LV_DPI / 30 : 1);
lv_style_set_border_side(&tabview_btns_bg, LV_STATE_DEFAULT, LV_BORDER_SIDE_BOTTOM); lv_style_set_border_side(&tabview_btns_bg, LV_STATE_DEFAULT, LV_BORDER_SIDE_BOTTOM);
lv_style_set_text_color(&tabview_btns_bg, LV_STATE_DEFAULT, COLOR_SCR_TEXT); lv_style_set_text_color(&tabview_btns_bg, LV_STATE_DEFAULT, COLOR_SCR_TEXT);
lv_style_set_text_font(&tabview_btns_bg, LV_STATE_DEFAULT, _font_normal); lv_style_set_text_font(&tabview_btns_bg, LV_STATE_DEFAULT, theme.font_normal);
lv_style_set_image_recolor(&tabview_btns_bg, LV_STATE_DEFAULT, lv_color_hex(0x979a9f)); lv_style_set_image_recolor(&tabview_btns_bg, LV_STATE_DEFAULT, lv_color_hex(0x979a9f));
lv_style_set_pad_top(&tabview_btns_bg, LV_STATE_DEFAULT, LV_DPI / 7); lv_style_set_pad_top(&tabview_btns_bg, LV_STATE_DEFAULT, LV_DPI / 7);
@ -759,7 +752,7 @@ static void tabview_init(void)
lv_style_init(&tabview_indic); lv_style_init(&tabview_indic);
lv_style_set_bg_opa(&tabview_indic, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&tabview_indic, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&tabview_indic, LV_STATE_DEFAULT, _color_primary); lv_style_set_bg_color(&tabview_indic, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_size(&tabview_indic, LV_STATE_DEFAULT, LV_DPI / 25 > 0 ? LV_DPI / 25 : 1); lv_style_set_size(&tabview_indic, LV_STATE_DEFAULT, LV_DPI / 25 > 0 ? LV_DPI / 25 : 1);
lv_style_set_radius(&tabview_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_radius(&tabview_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
@ -821,12 +814,13 @@ lv_theme_t * lv_theme_material_init(lv_color_t color_primary, lv_color_t color_s
lv_font_t * font_small, lv_font_t * font_normal, lv_font_t * font_subtitle, lv_font_t * font_title) lv_font_t * font_small, lv_font_t * font_normal, lv_font_t * font_subtitle, lv_font_t * font_title)
{ {
_color_primary = color_primary; theme.color_primary = color_primary;
_color_secondary = color_secondary; theme.color_secondary= color_secondary;
_font_small = font_small; theme.font_small = font_small;
_font_normal = font_normal; theme.font_normal = font_normal;
_font_subtitle = font_subtitle; theme.font_subtitle = font_subtitle;
_font_title = font_title; theme.font_title = font_title;
theme.flags = flags;
basic_init(); basic_init();
cont_init(); cont_init();

View File

@ -20,17 +20,16 @@ extern "C" {
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
typedef enum {
LV_THEME_MATERIAL_FLAG_DARK = 0x01,
LV_THEME_MATERIAL_FLAG_LIGHT = 0x02,
LV_THEME_MATERIAL_FLAG_NO_TRANSITION = 0x10,
}lv_theme_material_flag_t;
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
typedef enum {
LV_THEME_MATERIAL_PALETTE_LIGHT,
LV_THEME_MATERIAL_PALETTE_DARK,
} lv_theme_material_palette_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
**********************/ **********************/