From 6971d603d2da561afd49c7d02665ecf8d4280497 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 27 Jun 2020 06:53:19 +0200 Subject: [PATCH] add lv_theme_copy --- src/lv_themes/lv_theme.c | 30 +++++++++++++++++++++++++++--- src/lv_themes/lv_theme.h | 19 ++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/lv_themes/lv_theme.c b/src/lv_themes/lv_theme.c index 276e21d12..365fe3aa4 100644 --- a/src/lv_themes/lv_theme.c +++ b/src/lv_themes/lv_theme.c @@ -69,6 +69,30 @@ void lv_theme_apply(lv_obj_t * obj, lv_theme_style_t name) apply_theme(act_theme, obj, name); } +/** + * Copy a theme to an other or initialize a theme + * @param theme pointer to a theme to initialize + * @param copy pointer to a theme to copy + * or `NULL` to initialize `theme` to empty + */ +void lv_theme_copy(lv_theme_t * theme, const lv_theme_t * copy) +{ + _lv_memset_00(theme, sizeof(lv_theme_t)); + + if(copy) { + theme->font_small = copy->font_small; + theme->font_normal = copy->font_normal; + theme->font_subtitle = copy->font_subtitle; + theme->font_title = copy->font_title; + theme->color_primary = copy->color_primary; + theme->color_secondary = copy->color_secondary; + theme->flags = copy->flags; + theme->base = copy->base; + theme->apply_cb = copy->apply_cb; + theme->apply_xcb = copy->apply_xcb; + } + +} /** * Set a base theme for a theme. @@ -79,7 +103,7 @@ void lv_theme_apply(lv_obj_t * obj, lv_theme_style_t name) */ void lv_theme_set_base(lv_theme_t * new, lv_theme_t * base) { - new->base_theme = base; + new->base = base; } /** @@ -151,8 +175,8 @@ uint32_t lv_theme_get_flags(void) static void apply_theme(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) { - if(th->base_theme) { - apply_theme(th->base_theme, obj, name); + if(th->base) { + apply_theme(th->base, obj, name); } /*apply_xcb is deprecated, use apply_cb instead*/ diff --git a/src/lv_themes/lv_theme.h b/src/lv_themes/lv_theme.h index 9941d2c99..0a24f5e7d 100644 --- a/src/lv_themes/lv_theme.h +++ b/src/lv_themes/lv_theme.h @@ -146,10 +146,15 @@ typedef enum { } lv_theme_style_t; +struct _lv_theme_t; + +typedef void (*lv_theme_apply_cb_t)(struct _lv_theme_t *, lv_obj_t *, lv_theme_style_t); +typedef void (*lv_theme_apply_xcb_t)(lv_obj_t *, lv_theme_style_t); /*Deprecated: use `apply_cb` instead*/ + typedef struct _lv_theme_t { - void (*apply_xcb)(lv_obj_t *, lv_theme_style_t); /*Deprecated: use `apply_cb` instead*/ - void (*apply_cb)(struct _lv_theme_t *, lv_obj_t *, lv_theme_style_t); - struct _lv_theme_t * base_theme; /**< Apply the current theme's style on top of this theme.*/ + lv_theme_apply_cb_t apply_cb; + lv_theme_apply_xcb_t apply_xcb; /*Deprecated: use `apply_cb` instead*/ + struct _lv_theme_t * base; /**< Apply the current theme's style on top of this theme.*/ lv_color_t color_primary; lv_color_t color_secondary; const lv_font_t * font_small; @@ -184,6 +189,14 @@ lv_theme_t * lv_theme_get_act(void); */ void lv_theme_apply(lv_obj_t * obj, lv_theme_style_t name); +/** + * Copy a theme to an other or initialize a theme + * @param theme pointer to a theme to initialize + * @param copy pointer to a theme to copy + * or `NULL` to initialize `theme` to empty + */ +void lv_theme_copy(lv_theme_t * theme, const lv_theme_t * copy); + /** * Set a base theme for a theme. * The styles from the base them will be added before the styles of the current theme.