1 /**
2  *@file lv_themes.h
3  *
4  */
5 
6 #ifndef LV_THEMES_H
7 #define LV_THEMES_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *    INCLUDES
15  *********************/
16 #include "../lv_conf_internal.h"
17 #include "../lv_core/lv_style.h"
18 #include "../lv_core/lv_obj.h"
19 
20 /*********************
21  *    DEFINES
22  *********************/
23 
24 /**********************
25  *    TYPEDEFS
26  **********************/
27 
28 /**
29  * A theme in LVGL consists of many styles bound together.
30  *
31  * There is a style for each object type, as well as a generic style for
32  * backgrounds and panels.
33  */
34 typedef enum {
35     LV_THEME_NONE = 0,
36     LV_THEME_SCR,
37     LV_THEME_OBJ,
38 #if LV_USE_ARC
39     LV_THEME_ARC,
40 #endif
41 #if LV_USE_BAR
42     LV_THEME_BAR,
43 #endif
44 #if LV_USE_BTN
45     LV_THEME_BTN,
46 #endif
47 #if LV_USE_BTNMATRIX
48     LV_THEME_BTNMATRIX,
49 #endif
50 #if LV_USE_CALENDAR
51     LV_THEME_CALENDAR,
52 #endif
53 #if LV_USE_CANVAS
54     LV_THEME_CANVAS,
55 #endif
56 #if LV_USE_CHECKBOX
57     LV_THEME_CHECKBOX,
58 #endif
59 #if LV_USE_CHART
60     LV_THEME_CHART,
61 #endif
62 #if LV_USE_CONT
63     LV_THEME_CONT,
64 #endif
65 #if LV_USE_CPICKER
66     LV_THEME_CPICKER,
67 #endif
68 #if LV_USE_DROPDOWN
69     LV_THEME_DROPDOWN,
70 #endif
71 #if LV_USE_GAUGE
72     LV_THEME_GAUGE,
73 #endif
74 #if LV_USE_IMG
75     LV_THEME_IMAGE,
76 #endif
77 #if LV_USE_IMGBTN
78     LV_THEME_IMGBTN,
79 #endif
80 #if LV_USE_KEYBOARD
81     LV_THEME_KEYBOARD,
82 #endif
83 #if LV_USE_LABEL
84     LV_THEME_LABEL,
85 #endif
86 #if LV_USE_LED
87     LV_THEME_LED,
88 #endif
89 #if LV_USE_LINE
90     LV_THEME_LINE,
91 #endif
92 #if LV_USE_LIST
93     LV_THEME_LIST,
94     LV_THEME_LIST_BTN,
95 #endif
96 #if LV_USE_LINEMETER
97     LV_THEME_LINEMETER,
98 #endif
99 #if LV_USE_MSGBOX
100     LV_THEME_MSGBOX,
101     LV_THEME_MSGBOX_BTNS,   /*The button matrix of the buttons are initialized separately*/
102 #endif
103 #if LV_USE_OBJMASK
104     LV_THEME_OBJMASK,
105 #endif
106 #if LV_USE_PAGE
107     LV_THEME_PAGE,
108 #endif
109 #if LV_USE_ROLLER
110     LV_THEME_ROLLER,
111 #endif
112 #if LV_USE_SLIDER
113     LV_THEME_SLIDER,
114 #endif
115 #if LV_USE_SPINBOX
116     LV_THEME_SPINBOX,
117     LV_THEME_SPINBOX_BTN,   /*Control button for the spinbox*/
118 #endif
119 #if LV_USE_SPINNER
120     LV_THEME_SPINNER,
121 #endif
122 #if LV_USE_SWITCH
123     LV_THEME_SWITCH,
124 #endif
125 #if LV_USE_TABLE
126     LV_THEME_TABLE,
127 #endif
128 #if LV_USE_TABVIEW
129     LV_THEME_TABVIEW,
130     LV_THEME_TABVIEW_PAGE,  /*The tab pages are initialized separately*/
131 #endif
132 #if LV_USE_TEXTAREA
133     LV_THEME_TEXTAREA,
134 #endif
135 #if LV_USE_TILEVIEW
136     LV_THEME_TILEVIEW,
137 #endif
138 #if LV_USE_WIN
139     LV_THEME_WIN,
140     LV_THEME_WIN_BTN,   /*The buttons are initialized separately*/
141 #endif
142 
143     _LV_THEME_BUILTIN_LAST,
144     LV_THEME_CUSTOM_START = _LV_THEME_BUILTIN_LAST,
145     _LV_THEME_CUSTOM_LAST = 0xFFFF,
146 
147 } lv_theme_style_t;
148 
149 struct _lv_theme_t;
150 
151 typedef void (*lv_theme_apply_cb_t)(struct _lv_theme_t *, lv_obj_t *, lv_theme_style_t);
152 typedef void (*lv_theme_apply_xcb_t)(lv_obj_t *, lv_theme_style_t); /*Deprecated: use `apply_cb` instead*/
153 
154 typedef struct _lv_theme_t {
155     lv_theme_apply_cb_t apply_cb;
156     lv_theme_apply_xcb_t apply_xcb; /*Deprecated: use `apply_cb` instead*/
157     struct _lv_theme_t * base;    /**< Apply the current theme's style on top of this theme.*/
158     lv_color_t color_primary;
159     lv_color_t color_secondary;
160     const lv_font_t * font_small;
161     const lv_font_t * font_normal;
162     const lv_font_t * font_subtitle;
163     const lv_font_t * font_title;
164     uint32_t flags;
165     void * user_data;
166 } lv_theme_t;
167 
168 /**********************
169  *  GLOBAL PROTOTYPES
170  **********************/
171 
172 /**
173  * Set a theme for the system.
174  * From now, all the created objects will use styles from this theme by default
175  * @param th pointer to theme (return value of: 'lv_theme_init_xxx()')
176  */
177 void lv_theme_set_act(lv_theme_t * th);
178 
179 /**
180  * Get the current system theme.
181  * @return pointer to the current system theme. NULL if not set.
182  */
183 lv_theme_t * lv_theme_get_act(void);
184 
185 /**
186  * Apply the active theme on an object
187  * @param obj pointer to an object
188  * @param name the name of the theme element to apply. E.g. `LV_THEME_BTN`
189  */
190 void lv_theme_apply(lv_obj_t * obj, lv_theme_style_t name);
191 
192 /**
193  * Copy a theme to an other or initialize a theme
194  * @param theme pointer to a theme to initialize
195  * @param copy pointer to a theme to copy
196  *             or `NULL` to initialize `theme` to empty
197  */
198 void lv_theme_copy(lv_theme_t * theme, const lv_theme_t * copy);
199 
200 /**
201  * Set a base theme for a theme.
202  * The styles from the base them will be added before the styles of the current theme.
203  * Arbitrary long chain of themes can be created by setting base themes.
204  * @param new_theme pointer to theme which base should be set
205  * @param base pointer to the base theme
206  */
207 void lv_theme_set_base(lv_theme_t * new_theme, lv_theme_t * base);
208 
209 /**
210  * Set an apply callback for a theme.
211  * The apply callback is used to add styles to different objects
212  * @param theme pointer to theme which callback should be set
213  * @param apply_cb pointer to the callback
214  */
215 void lv_theme_set_apply_cb(lv_theme_t * theme, lv_theme_apply_cb_t apply_cb);
216 
217 /**
218  * Get the small font of the theme
219  * @return pointer to the font
220  */
221 const lv_font_t * lv_theme_get_font_small(void);
222 
223 /**
224  * Get the normal font of the theme
225  * @return pointer to the font
226  */
227 const lv_font_t * lv_theme_get_font_normal(void);
228 
229 /**
230  * Get the subtitle font of the theme
231  * @return pointer to the font
232  */
233 const lv_font_t * lv_theme_get_font_subtitle(void);
234 
235 /**
236  * Get the title font of the theme
237  * @return pointer to the font
238  */
239 const lv_font_t * lv_theme_get_font_title(void);
240 
241 /**
242  * Get the primary color of the theme
243  * @return the color
244  */
245 lv_color_t lv_theme_get_color_primary(void);
246 
247 /**
248  * Get the secondary color of the theme
249  * @return the color
250  */
251 lv_color_t lv_theme_get_color_secondary(void);
252 
253 /**
254  * Get the flags of the theme
255  * @return the flags
256  */
257 uint32_t lv_theme_get_flags(void);
258 
259 /**********************
260  *    MACROS
261  **********************/
262 
263 /**********************
264  *     POST INCLUDE
265  *********************/
266 #include "lv_theme_empty.h"
267 #include "lv_theme_template.h"
268 #include "lv_theme_material.h"
269 #include "lv_theme_mono.h"
270 
271 #ifdef __cplusplus
272 } /* extern "C" */
273 #endif
274 
275 #endif /*LV_THEMES_H*/
276