mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(theme):add ability to inhrit theme from base class (#3770)
Signed-off-by: wangxuedong <wangxuedong@xiaomi.com>
This commit is contained in:
parent
6e62fcfd08
commit
532a3ebbc7
@ -41,6 +41,11 @@ typedef enum {
|
||||
LV_OBJ_CLASS_GROUP_DEF_FALSE,
|
||||
} lv_obj_class_group_def_t;
|
||||
|
||||
typedef enum {
|
||||
LV_OBJ_CLASS_THEME_INHERITABLE_FALSE, /**< Do not inherit theme from base class. */
|
||||
LV_OBJ_CLASS_THEME_INHERITABLE_TRUE,
|
||||
} lv_obj_class_theme_inheritable_t;
|
||||
|
||||
typedef void (*lv_obj_class_event_cb_t)(struct _lv_obj_class_t * class_p, struct _lv_event_t * e);
|
||||
/**
|
||||
* Describe the common methods of every object.
|
||||
@ -60,6 +65,7 @@ typedef struct _lv_obj_class_t {
|
||||
uint32_t editable : 2; /**< Value from ::lv_obj_class_editable_t*/
|
||||
uint32_t group_def : 2; /**< Value from ::lv_obj_class_group_def_t*/
|
||||
uint32_t instance_size : 16;
|
||||
uint32_t theme_inheritable : 1; /**< Value from ::lv_obj_class_theme_inheritable_t*/
|
||||
} lv_obj_class_t;
|
||||
|
||||
/**********************
|
||||
|
@ -20,6 +20,7 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void apply_theme(lv_theme_t * th, lv_obj_t * obj);
|
||||
static void apply_theme_recursion(lv_theme_t * th, lv_obj_t * obj);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -51,7 +52,7 @@ void lv_theme_apply(lv_obj_t * obj)
|
||||
|
||||
lv_obj_remove_style_all(obj);
|
||||
|
||||
apply_theme(th, obj); /*Apply the theme including the base theme(s)*/
|
||||
apply_theme_recursion(th, obj); /*Apply the theme including the base theme(s)*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,3 +117,21 @@ static void apply_theme(lv_theme_t * th, lv_obj_t * obj)
|
||||
if(th->parent) apply_theme(th->parent, obj);
|
||||
if(th->apply_cb) th->apply_cb(th, obj);
|
||||
}
|
||||
|
||||
static void apply_theme_recursion(lv_theme_t * th, lv_obj_t * obj)
|
||||
{
|
||||
const lv_obj_class_t * original_class_p = obj->class_p;
|
||||
|
||||
if(obj->class_p->base_class && obj->class_p->theme_inheritable == LV_OBJ_CLASS_THEME_INHERITABLE_TRUE) {
|
||||
/*Apply the base class theme in obj*/
|
||||
obj->class_p = obj->class_p->base_class;
|
||||
|
||||
/*apply the base first*/
|
||||
apply_theme_recursion(th, obj);
|
||||
}
|
||||
|
||||
/*Restore the original class*/
|
||||
obj->class_p = original_class_p;
|
||||
|
||||
apply_theme(th, obj);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user