177 lines
4.0 KiB
C
177 lines
4.0 KiB
C
/**
|
|
* @file lv_theme_simple.c
|
|
*
|
|
*/
|
|
|
|
#define LV_USE_THEME_SIMPLE_DOMOTIC 1
|
|
/*********************
|
|
* INCLUDES
|
|
*********************/
|
|
#if LV_USE_THEME_SIMPLE_DOMOTIC
|
|
#include "lv_theme_domotic.h"
|
|
/*********************
|
|
* DEFINES
|
|
*********************/
|
|
LV_FONT_DECLARE(montserrat_medium_12)
|
|
LV_FONT_DECLARE(montserrat_medium_18)
|
|
LV_FONT_DECLARE(montserrat_medium_24)
|
|
|
|
|
|
struct _my_theme_t;
|
|
typedef struct _my_theme_t my_theme_t;
|
|
|
|
#define theme_def (*(my_theme_t **)(&LV_GLOBAL_DEFAULT()->theme_simple))
|
|
|
|
#define COLOR_SCR lv_palette_lighten(LV_PALETTE_GREY, 4)
|
|
#define COLOR_WHITE lv_color_white()
|
|
#define COLOR_LIGHT lv_palette_lighten(LV_PALETTE_GREY, 2)
|
|
#define COLOR_DARK lv_palette_main(LV_PALETTE_GREY)
|
|
#define COLOR_DIM lv_palette_darken(LV_PALETTE_GREY, 2)
|
|
#define SCROLLBAR_WIDTH 2
|
|
|
|
/**********************
|
|
* TYPEDEFS
|
|
**********************/
|
|
typedef struct {
|
|
lv_style_t scr;
|
|
lv_style_t transp;
|
|
lv_style_t white;
|
|
lv_style_t light;
|
|
lv_style_t dark;
|
|
lv_style_t dim;
|
|
lv_style_t scrollbar;
|
|
#if LV_USE_ARC
|
|
lv_style_t arc_line;
|
|
lv_style_t arc_knob;
|
|
#endif
|
|
#if LV_USE_TEXTAREA
|
|
lv_style_t ta_cursor;
|
|
#endif
|
|
} my_theme_styles_t;
|
|
|
|
struct _my_theme_t {
|
|
lv_theme_t base;
|
|
my_theme_styles_t styles;
|
|
bool inited;
|
|
};
|
|
|
|
/**********************
|
|
* STATIC PROTOTYPES
|
|
**********************/
|
|
static void style_init_reset(lv_style_t * style);
|
|
static void theme_apply(lv_theme_t * th, lv_obj_t * obj);
|
|
|
|
/**********************
|
|
* STATIC VARIABLES
|
|
**********************/
|
|
|
|
/**********************
|
|
* MACROS
|
|
**********************/
|
|
|
|
/**********************
|
|
* STATIC FUNCTIONS
|
|
**********************/
|
|
|
|
static void style_init(my_theme_t * theme)
|
|
{
|
|
}
|
|
|
|
/**********************
|
|
* GLOBAL FUNCTIONS
|
|
**********************/
|
|
|
|
bool lv_theme_domotic_is_inited(void)
|
|
{
|
|
my_theme_t * theme = theme_def;
|
|
if(theme == NULL) return false;
|
|
return theme->inited;
|
|
}
|
|
|
|
lv_theme_t * lv_theme_domotic_get(void)
|
|
{
|
|
if(!lv_theme_domotic_is_inited()) {
|
|
return NULL;
|
|
}
|
|
|
|
return (lv_theme_t *)theme_def;
|
|
}
|
|
|
|
void lv_theme_domotic_deinit(void)
|
|
{
|
|
my_theme_t * theme = theme_def;
|
|
if(theme) {
|
|
if(theme->inited) {
|
|
lv_style_t * theme_styles = (lv_style_t *)(&(theme->styles));
|
|
uint32_t i;
|
|
for(i = 0; i < sizeof(my_theme_styles_t) / sizeof(lv_style_t); i++) {
|
|
lv_style_reset(theme_styles + i);
|
|
}
|
|
}
|
|
lv_free(theme_def);
|
|
theme_def = NULL;
|
|
}
|
|
}
|
|
|
|
lv_theme_t * lv_theme_domotic_init(lv_display_t * disp)
|
|
{
|
|
/*This trick is required only to avoid the garbage collection of
|
|
*styles' data if LVGL is used in a binding (e.g. MicroPython)
|
|
*In a general case styles could be in simple `static lv_style_t my_style...` variables*/
|
|
if(!lv_theme_domotic_is_inited()) {
|
|
theme_def = lv_malloc_zeroed(sizeof(my_theme_t));
|
|
}
|
|
|
|
my_theme_t * theme = theme_def;
|
|
|
|
theme->base.disp = disp;
|
|
theme->base.font_small = &montserrat_medium_12;
|
|
theme->base.font_normal = &montserrat_medium_18;
|
|
theme->base.font_large = &montserrat_medium_24;
|
|
theme->base.apply_cb = theme_apply;
|
|
|
|
lv_theme_t * th_act = lv_display_get_theme(NULL);
|
|
lv_theme_set_parent((lv_theme_t *)theme, th_act);
|
|
|
|
style_init(theme);
|
|
|
|
if(disp == NULL || lv_display_get_theme(disp) == (lv_theme_t *)theme) {
|
|
lv_obj_report_style_change(NULL);
|
|
}
|
|
|
|
theme->inited = true;
|
|
|
|
return (lv_theme_t *)theme_def;
|
|
}
|
|
|
|
static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
|
{
|
|
LV_UNUSED(th);
|
|
|
|
my_theme_t * theme = theme_def;
|
|
lv_obj_t * parent = lv_obj_get_parent(obj);
|
|
|
|
if(parent == NULL) {
|
|
lv_obj_add_style(obj, &theme->styles.scr, 0);
|
|
lv_obj_add_style(obj, &theme->styles.scrollbar, LV_PART_SCROLLBAR);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
/**********************
|
|
* STATIC FUNCTIONS
|
|
**********************/
|
|
|
|
static void style_init_reset(lv_style_t * style)
|
|
{
|
|
if(lv_theme_simple_is_inited()) {
|
|
lv_style_reset(style);
|
|
}
|
|
else {
|
|
lv_style_init(style);
|
|
}
|
|
}
|
|
|
|
#endif
|