diff --git a/lv_themes/lv_theme.c b/lv_themes/lv_theme.c index bbdca6e4c..4b76c8b78 100644 --- a/lv_themes/lv_theme.c +++ b/lv_themes/lv_theme.c @@ -35,7 +35,7 @@ static lv_theme_t * current_theme; * (The pointers in the theme points to the styles declared by the theme itself) */ /* Store the styles in this array. */ -static lv_style_t th_styles[sizeof(((lv_theme_t *)0)->style) / sizeof(lv_style_t *)]; +static lv_style_t th_styles[LV_THEME_STYLE_COUNT]; static bool inited = false; static lv_theme_t current_theme; #endif diff --git a/lv_themes/lv_theme.h b/lv_themes/lv_theme.h index cdb0771f8..24db3d5e6 100644 --- a/lv_themes/lv_theme.h +++ b/lv_themes/lv_theme.h @@ -314,6 +314,9 @@ lv_theme_t * lv_theme_get_current(void); * MACROS **********************/ +/* Returns number of styles within the `lv_theme_t` structure. */ +#define LV_THEME_STYLE_COUNT (sizeof(((lv_theme_t *)0)->style) / sizeof(lv_style_t *)) + /********************** * POST INCLUDE *********************/ diff --git a/lv_themes/lv_theme_alien.c b/lv_themes/lv_theme_alien.c index 8b5f469a9..c3dc48dac 100644 --- a/lv_themes/lv_theme_alien.c +++ b/lv_themes/lv_theme_alien.c @@ -817,8 +817,8 @@ lv_theme_t * lv_theme_alien_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } diff --git a/lv_themes/lv_theme_default.c b/lv_themes/lv_theme_default.c index 9a972571a..f16e47a9d 100644 --- a/lv_themes/lv_theme_default.c +++ b/lv_themes/lv_theme_default.c @@ -376,8 +376,8 @@ lv_theme_t * lv_theme_default_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } diff --git a/lv_themes/lv_theme_material.c b/lv_themes/lv_theme_material.c index 6cfe50104..e5d5d5d42 100644 --- a/lv_themes/lv_theme_material.c +++ b/lv_themes/lv_theme_material.c @@ -801,8 +801,8 @@ lv_theme_t * lv_theme_material_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } diff --git a/lv_themes/lv_theme_mono.c b/lv_themes/lv_theme_mono.c index 44c02754f..babfc4998 100644 --- a/lv_themes/lv_theme_mono.c +++ b/lv_themes/lv_theme_mono.c @@ -435,8 +435,8 @@ lv_theme_t * lv_theme_mono_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } diff --git a/lv_themes/lv_theme_nemo.c b/lv_themes/lv_theme_nemo.c index 339682ad2..c10fc303f 100644 --- a/lv_themes/lv_theme_nemo.c +++ b/lv_themes/lv_theme_nemo.c @@ -800,8 +800,8 @@ lv_theme_t * lv_theme_nemo_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } diff --git a/lv_themes/lv_theme_night.c b/lv_themes/lv_theme_night.c index 4f86bd032..c65efba97 100644 --- a/lv_themes/lv_theme_night.c +++ b/lv_themes/lv_theme_night.c @@ -710,8 +710,8 @@ lv_theme_t * lv_theme_night_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } diff --git a/lv_themes/lv_theme_templ.c b/lv_themes/lv_theme_templ.c index eb2e0747c..906ec52a2 100644 --- a/lv_themes/lv_theme_templ.c +++ b/lv_themes/lv_theme_templ.c @@ -385,8 +385,8 @@ lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } diff --git a/lv_themes/lv_theme_zen.c b/lv_themes/lv_theme_zen.c index f04be7bcc..3f3f29923 100644 --- a/lv_themes/lv_theme_zen.c +++ b/lv_themes/lv_theme_zen.c @@ -767,8 +767,8 @@ lv_theme_t * lv_theme_zen_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; }