1 /**
2  * @file lv_theme_empty.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include <stdint.h>
10 #include "../../lvgl.h" /*To see all the widgets*/
11 
12 #if LV_USE_THEME_EMPTY
13 
14 #include "../lv_misc/lv_gc.h"
15 
16 #if defined(LV_GC_INCLUDE)
17     #include LV_GC_INCLUDE
18 #endif /* LV_ENABLE_GC */
19 
20 /*********************
21  *      DEFINES
22  *********************/
23 
24 /**********************
25  *      TYPEDEFS
26  **********************/
27 typedef struct {
28     lv_style_t opa_cover;
29 } theme_styles_t;
30 
31 /**********************
32  *  STATIC PROTOTYPES
33  **********************/
34 static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name);
35 static void style_init_reset(lv_style_t * style);
36 
37 /**********************
38  *  STATIC VARIABLES
39  **********************/
40 static lv_theme_t theme;
41 static theme_styles_t * styles;
42 
43 static bool inited;
44 
45 /**********************
46  *      MACROS
47  **********************/
48 
49 /**********************
50  *   STATIC FUNCTIONS
51  **********************/
52 
53 /**********************
54  *   GLOBAL FUNCTIONS
55  **********************/
56 
57 /**
58  * Initialize the default
59  * @param color_primary the primary color of the theme
60  * @param color_secondary the secondary color for the theme
61  * @param flags ORed flags starting with `LV_THEME_DEF_FLAG_...`
62  * @param font_small pointer to a small font
63  * @param font_normal pointer to a normal font
64  * @param font_subtitle pointer to a large font
65  * @param font_title pointer to a extra large font
66  * @return a pointer to reference this theme later
67  */
lv_theme_empty_init(lv_color_t color_primary,lv_color_t color_secondary,uint32_t flags,const lv_font_t * font_small,const lv_font_t * font_normal,const lv_font_t * font_subtitle,const lv_font_t * font_title)68 lv_theme_t * lv_theme_empty_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags,
69                                  const lv_font_t * font_small, const lv_font_t * font_normal, const lv_font_t * font_subtitle,
70                                  const lv_font_t * font_title)
71 {
72     /* This trick is required only to avoid the garbage collection of
73      * styles' data if LVGL is used in a binding (e.g. Micropython)
74      * In a general case styles could be simple `static lv_style_t my style` variables*/
75     if(!inited) {
76         LV_GC_ROOT(_lv_theme_empty_styles) = lv_mem_alloc(sizeof(theme_styles_t));
77         styles = (theme_styles_t *)LV_GC_ROOT(_lv_theme_empty_styles);
78     }
79 
80 
81     theme.color_primary = color_primary;
82     theme.color_secondary = color_secondary;
83     theme.font_small = font_small;
84     theme.font_normal = font_normal;
85     theme.font_subtitle = font_subtitle;
86     theme.font_title = font_title;
87     theme.flags = flags;
88 
89     style_init_reset(&styles->opa_cover);
90     lv_style_set_bg_opa(&styles->opa_cover, LV_STATE_DEFAULT, LV_OPA_COVER);
91 
92     theme.apply_xcb = NULL;
93     theme.apply_cb = theme_apply;
94     return &theme;
95 }
96 
97 
theme_apply(lv_theme_t * th,lv_obj_t * obj,lv_theme_style_t name)98 static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name)
99 {
100     LV_UNUSED(th);
101     if(name == LV_THEME_SCR) {
102         lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN);
103         lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &styles->opa_cover);
104     }
105 }
106 
107 /**********************
108  *   STATIC FUNCTIONS
109  **********************/
110 
style_init_reset(lv_style_t * style)111 static void style_init_reset(lv_style_t * style)
112 {
113     if(inited) lv_style_reset(style);
114     else lv_style_init(style);
115 }
116 
117 #endif
118