1 /**
2  * @file lv_theme_default.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "../../../lvgl.h" /*To see all the widgets*/
10 
11 #if LV_USE_THEME_DEFAULT
12 
13 #include "lv_theme_default.h"
14 #include "../../../misc/lv_gc.h"
15 
16 /*********************
17  *      DEFINES
18  *********************/
19 #define MODE_DARK 1
20 #define RADIUS_DEFAULT (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 12) : lv_disp_dpx(theme.disp, 8))
21 
22 /*SCREEN*/
23 #define LIGHT_COLOR_SCR        lv_palette_lighten(LV_PALETTE_GREY, 4)
24 #define LIGHT_COLOR_CARD       lv_color_white()
25 #define LIGHT_COLOR_TEXT       lv_palette_darken(LV_PALETTE_GREY, 4)
26 #define LIGHT_COLOR_GREY       lv_palette_lighten(LV_PALETTE_GREY, 2)
27 #define DARK_COLOR_SCR         lv_color_hex(0x15171A)
28 #define DARK_COLOR_CARD        lv_color_hex(0x282b30)
29 #define DARK_COLOR_TEXT        lv_palette_lighten(LV_PALETTE_GREY, 5)
30 #define DARK_COLOR_GREY        lv_color_hex(0x2f3237)
31 
32 #define TRANSITION_TIME         LV_THEME_DEFAULT_TRANSITION_TIME
33 #define BORDER_WIDTH            lv_disp_dpx(theme.disp, 2)
34 #define OUTLINE_WIDTH           lv_disp_dpx(theme.disp, 3)
35 
36 #define PAD_DEF     (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 24) : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 20) : lv_disp_dpx(theme.disp, 16))
37 #define PAD_SMALL   (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 14) : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 12) : lv_disp_dpx(theme.disp, 10))
38 #define PAD_TINY   (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 8) : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 6) : lv_disp_dpx(theme.disp, 2))
39 
40 /**********************
41  *      TYPEDEFS
42  **********************/
43 typedef struct {
44     lv_style_t scr;
45     lv_style_t scrollbar;
46     lv_style_t scrollbar_scrolled;
47     lv_style_t card;
48     lv_style_t btn;
49 
50     /*Utility*/
51     lv_style_t bg_color_primary;
52     lv_style_t bg_color_primary_muted;
53     lv_style_t bg_color_secondary;
54     lv_style_t bg_color_secondary_muted;
55     lv_style_t bg_color_grey;
56     lv_style_t bg_color_white;
57     lv_style_t pressed;
58     lv_style_t disabled;
59     lv_style_t pad_zero;
60     lv_style_t pad_tiny;
61     lv_style_t pad_small;
62     lv_style_t pad_normal;
63     lv_style_t pad_gap;
64     lv_style_t line_space_large;
65     lv_style_t text_align_center;
66     lv_style_t outline_primary;
67     lv_style_t outline_secondary;
68     lv_style_t circle;
69     lv_style_t no_radius;
70     lv_style_t clip_corner;
71 #if LV_THEME_DEFAULT_GROW
72     lv_style_t grow;
73 #endif
74     lv_style_t transition_delayed;
75     lv_style_t transition_normal;
76     lv_style_t anim;
77     lv_style_t anim_fast;
78 
79     /*Parts*/
80     lv_style_t knob;
81     lv_style_t indic;
82 
83 #if LV_USE_ARC
84     lv_style_t arc_indic;
85     lv_style_t arc_indic_primary;
86 #endif
87 
88 #if LV_USE_CHART
89     lv_style_t chart_series, chart_indic, chart_ticks, chart_bg;
90 #endif
91 
92 #if LV_USE_DROPDOWN
93     lv_style_t dropdown_list;
94 #endif
95 
96 #if LV_USE_CHECKBOX
97     lv_style_t cb_marker, cb_marker_checked;
98 #endif
99 
100 #if LV_USE_SWITCH
101     lv_style_t switch_knob;
102 #endif
103 
104 #if LV_USE_LINE
105     lv_style_t line;
106 #endif
107 
108 #if LV_USE_TABLE
109     lv_style_t table_cell;
110 #endif
111 
112 #if LV_USE_METER
113     lv_style_t meter_marker, meter_indic;
114 #endif
115 
116 #if LV_USE_TEXTAREA
117     lv_style_t ta_cursor, ta_placeholder;
118 #endif
119 
120 #if LV_USE_CALENDAR
121     lv_style_t calendar_btnm_bg, calendar_btnm_day, calendar_header;
122 #endif
123 
124 #if LV_USE_COLORWHEEL
125     lv_style_t colorwheel_main;
126 #endif
127 
128 #if LV_USE_MENU
129     lv_style_t menu_bg, menu_cont, menu_sidebar_cont, menu_main_cont, menu_page, menu_header_cont, menu_header_btn,
130                menu_section, menu_pressed, menu_separator;
131 #endif
132 
133 #if LV_USE_MSGBOX
134     lv_style_t msgbox_bg, msgbox_btn_bg, msgbox_backdrop_bg;
135 #endif
136 
137 #if LV_USE_KEYBOARD
138     lv_style_t keyboard_btn_bg;
139 #endif
140 
141 #if LV_USE_LIST
142     lv_style_t list_bg, list_btn, list_item_grow, list_label;
143 #endif
144 
145 #if LV_USE_TABVIEW
146     lv_style_t tab_bg_focus, tab_btn;
147 #endif
148 #if LV_USE_LED
149     lv_style_t led;
150 #endif
151 } my_theme_styles_t;
152 
153 typedef struct {
154     lv_theme_t base;
155     uint8_t light : 1;
156 } my_theme_t;
157 
158 typedef enum {
159     DISP_SMALL = 3,
160     DISP_MEDIUM = 2,
161     DISP_LARGE = 1,
162 } disp_size_t;
163 
164 /**********************
165  *  STATIC PROTOTYPES
166  **********************/
167 static void theme_apply(lv_theme_t * th, lv_obj_t * obj);
168 static void style_init_reset(lv_style_t * style);
169 
170 /**********************
171  *  STATIC VARIABLES
172  **********************/
173 static my_theme_styles_t * styles;
174 static lv_theme_t theme;
175 static disp_size_t disp_size;
176 static lv_color_t color_scr;
177 static lv_color_t color_text;
178 static lv_color_t color_card;
179 static lv_color_t color_grey;
180 static bool inited = false;
181 
182 
183 /**********************
184  *      MACROS
185  **********************/
186 
187 /**********************
188  *   STATIC FUNCTIONS
189  **********************/
190 
191 
dark_color_filter_cb(const lv_color_filter_dsc_t * f,lv_color_t c,lv_opa_t opa)192 static lv_color_t dark_color_filter_cb(const lv_color_filter_dsc_t * f, lv_color_t c, lv_opa_t opa)
193 {
194     LV_UNUSED(f);
195     return lv_color_darken(c, opa);
196 }
197 
grey_filter_cb(const lv_color_filter_dsc_t * f,lv_color_t color,lv_opa_t opa)198 static lv_color_t grey_filter_cb(const lv_color_filter_dsc_t * f, lv_color_t color, lv_opa_t opa)
199 {
200     LV_UNUSED(f);
201     if(theme.flags & MODE_DARK) return lv_color_mix(lv_palette_darken(LV_PALETTE_GREY, 2), color, opa);
202     else return lv_color_mix(lv_palette_lighten(LV_PALETTE_GREY, 2), color, opa);
203 }
204 
style_init(void)205 static void style_init(void)
206 {
207     static const lv_style_prop_t trans_props[] = {
208         LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR,
209         LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_TRANSFORM_HEIGHT,
210         LV_STYLE_TRANSLATE_Y, LV_STYLE_TRANSLATE_X,
211         LV_STYLE_TRANSFORM_ZOOM, LV_STYLE_TRANSFORM_ANGLE,
212         LV_STYLE_COLOR_FILTER_OPA, LV_STYLE_COLOR_FILTER_DSC,
213         0
214     };
215 
216     color_scr = theme.flags & MODE_DARK ? DARK_COLOR_SCR : LIGHT_COLOR_SCR;
217     color_text = theme.flags & MODE_DARK ? DARK_COLOR_TEXT : LIGHT_COLOR_TEXT;
218     color_card = theme.flags & MODE_DARK ? DARK_COLOR_CARD : LIGHT_COLOR_CARD;
219     color_grey = theme.flags & MODE_DARK ? DARK_COLOR_GREY : LIGHT_COLOR_GREY;
220 
221     style_init_reset(&styles->transition_delayed);
222     style_init_reset(&styles->transition_normal);
223 #if TRANSITION_TIME
224     static lv_style_transition_dsc_t trans_delayed;
225     lv_style_transition_dsc_init(&trans_delayed, trans_props, lv_anim_path_linear, TRANSITION_TIME, 70, NULL);
226 
227     static lv_style_transition_dsc_t trans_normal;
228     lv_style_transition_dsc_init(&trans_normal, trans_props, lv_anim_path_linear, TRANSITION_TIME, 0, NULL);
229 
230     lv_style_set_transition(&styles->transition_delayed, &trans_delayed); /*Go back to default state with delay*/
231 
232     lv_style_set_transition(&styles->transition_normal, &trans_normal); /*Go back to default state with delay*/
233 #endif
234 
235     style_init_reset(&styles->scrollbar);
236     lv_color_t sb_color = (theme.flags & MODE_DARK) ? lv_palette_darken(LV_PALETTE_GREY,
237                                                                         2) : lv_palette_main(LV_PALETTE_GREY);
238     lv_style_set_bg_color(&styles->scrollbar, sb_color);
239 
240     lv_style_set_radius(&styles->scrollbar, LV_RADIUS_CIRCLE);
241     lv_style_set_pad_all(&styles->scrollbar, lv_disp_dpx(theme.disp, 7));
242     lv_style_set_width(&styles->scrollbar,  lv_disp_dpx(theme.disp, 5));
243     lv_style_set_bg_opa(&styles->scrollbar,  LV_OPA_40);
244 #if TRANSITION_TIME
245     lv_style_set_transition(&styles->scrollbar, &trans_normal);
246 #endif
247 
248     style_init_reset(&styles->scrollbar_scrolled);
249     lv_style_set_bg_opa(&styles->scrollbar_scrolled,  LV_OPA_COVER);
250 
251     style_init_reset(&styles->scr);
252     lv_style_set_bg_opa(&styles->scr, LV_OPA_COVER);
253     lv_style_set_bg_color(&styles->scr, color_scr);
254     lv_style_set_text_color(&styles->scr, color_text);
255     lv_style_set_pad_row(&styles->scr, PAD_SMALL);
256     lv_style_set_pad_column(&styles->scr, PAD_SMALL);
257 
258     style_init_reset(&styles->card);
259     lv_style_set_radius(&styles->card, RADIUS_DEFAULT);
260     lv_style_set_bg_opa(&styles->card, LV_OPA_COVER);
261     lv_style_set_bg_color(&styles->card, color_card);
262     lv_style_set_border_color(&styles->card, color_grey);
263     lv_style_set_border_width(&styles->card, BORDER_WIDTH);
264     lv_style_set_border_post(&styles->card, true);
265     lv_style_set_text_color(&styles->card, color_text);
266     lv_style_set_pad_all(&styles->card, PAD_DEF);
267     lv_style_set_pad_row(&styles->card, PAD_SMALL);
268     lv_style_set_pad_column(&styles->card, PAD_SMALL);
269     lv_style_set_line_color(&styles->card, lv_palette_main(LV_PALETTE_GREY));
270     lv_style_set_line_width(&styles->card, lv_disp_dpx(theme.disp, 1));
271 
272     style_init_reset(&styles->outline_primary);
273     lv_style_set_outline_color(&styles->outline_primary, theme.color_primary);
274     lv_style_set_outline_width(&styles->outline_primary, OUTLINE_WIDTH);
275     lv_style_set_outline_pad(&styles->outline_primary, OUTLINE_WIDTH);
276     lv_style_set_outline_opa(&styles->outline_primary, LV_OPA_50);
277 
278     style_init_reset(&styles->outline_secondary);
279     lv_style_set_outline_color(&styles->outline_secondary, theme.color_secondary);
280     lv_style_set_outline_width(&styles->outline_secondary, OUTLINE_WIDTH);
281     lv_style_set_outline_opa(&styles->outline_secondary, LV_OPA_50);
282 
283     style_init_reset(&styles->btn);
284     lv_style_set_radius(&styles->btn, (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp,
285                                                                              16) : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 12) : lv_disp_dpx(theme.disp, 8)));
286     lv_style_set_bg_opa(&styles->btn, LV_OPA_COVER);
287     lv_style_set_bg_color(&styles->btn, color_grey);
288     if(!(theme.flags & MODE_DARK)) {
289         lv_style_set_shadow_color(&styles->btn, lv_palette_main(LV_PALETTE_GREY));
290         lv_style_set_shadow_width(&styles->btn, LV_DPX(3));
291         lv_style_set_shadow_opa(&styles->btn, LV_OPA_50);
292         lv_style_set_shadow_ofs_y(&styles->btn, lv_disp_dpx(theme.disp, LV_DPX(4)));
293     }
294     lv_style_set_text_color(&styles->btn, color_text);
295     lv_style_set_pad_hor(&styles->btn, PAD_DEF);
296     lv_style_set_pad_ver(&styles->btn, PAD_SMALL);
297     lv_style_set_pad_column(&styles->btn, lv_disp_dpx(theme.disp, 5));
298     lv_style_set_pad_row(&styles->btn, lv_disp_dpx(theme.disp, 5));
299 
300     static lv_color_filter_dsc_t dark_filter;
301     lv_color_filter_dsc_init(&dark_filter, dark_color_filter_cb);
302 
303     static lv_color_filter_dsc_t grey_filter;
304     lv_color_filter_dsc_init(&grey_filter, grey_filter_cb);
305 
306     style_init_reset(&styles->pressed);
307     lv_style_set_color_filter_dsc(&styles->pressed, &dark_filter);
308     lv_style_set_color_filter_opa(&styles->pressed, 35);
309 
310     style_init_reset(&styles->disabled);
311     lv_style_set_color_filter_dsc(&styles->disabled, &grey_filter);
312     lv_style_set_color_filter_opa(&styles->disabled, LV_OPA_50);
313 
314     style_init_reset(&styles->clip_corner);
315     lv_style_set_clip_corner(&styles->clip_corner, true);
316     lv_style_set_border_post(&styles->clip_corner, true);
317 
318     style_init_reset(&styles->pad_normal);
319     lv_style_set_pad_all(&styles->pad_normal, PAD_DEF);
320     lv_style_set_pad_row(&styles->pad_normal, PAD_DEF);
321     lv_style_set_pad_column(&styles->pad_normal, PAD_DEF);
322 
323     style_init_reset(&styles->pad_small);
324     lv_style_set_pad_all(&styles->pad_small, PAD_SMALL);
325     lv_style_set_pad_gap(&styles->pad_small, PAD_SMALL);
326 
327     style_init_reset(&styles->pad_gap);
328     lv_style_set_pad_row(&styles->pad_gap, lv_disp_dpx(theme.disp, 10));
329     lv_style_set_pad_column(&styles->pad_gap, lv_disp_dpx(theme.disp, 10));
330 
331     style_init_reset(&styles->line_space_large);
332     lv_style_set_text_line_space(&styles->line_space_large, lv_disp_dpx(theme.disp, 20));
333 
334     style_init_reset(&styles->text_align_center);
335     lv_style_set_text_align(&styles->text_align_center, LV_TEXT_ALIGN_CENTER);
336 
337     style_init_reset(&styles->pad_zero);
338     lv_style_set_pad_all(&styles->pad_zero, 0);
339     lv_style_set_pad_row(&styles->pad_zero, 0);
340     lv_style_set_pad_column(&styles->pad_zero, 0);
341 
342     style_init_reset(&styles->pad_tiny);
343     lv_style_set_pad_all(&styles->pad_tiny, PAD_TINY);
344     lv_style_set_pad_row(&styles->pad_tiny, PAD_TINY);
345     lv_style_set_pad_column(&styles->pad_tiny, PAD_TINY);
346 
347     style_init_reset(&styles->bg_color_primary);
348     lv_style_set_bg_color(&styles->bg_color_primary, theme.color_primary);
349     lv_style_set_text_color(&styles->bg_color_primary, lv_color_white());
350     lv_style_set_bg_opa(&styles->bg_color_primary, LV_OPA_COVER);
351 
352     style_init_reset(&styles->bg_color_primary_muted);
353     lv_style_set_bg_color(&styles->bg_color_primary_muted, theme.color_primary);
354     lv_style_set_text_color(&styles->bg_color_primary_muted, theme.color_primary);
355     lv_style_set_bg_opa(&styles->bg_color_primary_muted, LV_OPA_20);
356 
357     style_init_reset(&styles->bg_color_secondary);
358     lv_style_set_bg_color(&styles->bg_color_secondary, theme.color_secondary);
359     lv_style_set_text_color(&styles->bg_color_secondary, lv_color_white());
360     lv_style_set_bg_opa(&styles->bg_color_secondary, LV_OPA_COVER);
361 
362     style_init_reset(&styles->bg_color_secondary_muted);
363     lv_style_set_bg_color(&styles->bg_color_secondary_muted, theme.color_secondary);
364     lv_style_set_text_color(&styles->bg_color_secondary_muted, theme.color_secondary);
365     lv_style_set_bg_opa(&styles->bg_color_secondary_muted, LV_OPA_20);
366 
367     style_init_reset(&styles->bg_color_grey);
368     lv_style_set_bg_color(&styles->bg_color_grey, color_grey);
369     lv_style_set_bg_opa(&styles->bg_color_grey, LV_OPA_COVER);
370     lv_style_set_text_color(&styles->bg_color_grey, color_text);
371 
372     style_init_reset(&styles->bg_color_white);
373     lv_style_set_bg_color(&styles->bg_color_white, color_card);
374     lv_style_set_bg_opa(&styles->bg_color_white, LV_OPA_COVER);
375     lv_style_set_text_color(&styles->bg_color_white, color_text);
376 
377     style_init_reset(&styles->circle);
378     lv_style_set_radius(&styles->circle, LV_RADIUS_CIRCLE);
379 
380     style_init_reset(&styles->no_radius);
381     lv_style_set_radius(&styles->no_radius, 0);
382 
383 #if LV_THEME_DEFAULT_GROW
384     style_init_reset(&styles->grow);
385     lv_style_set_transform_width(&styles->grow, lv_disp_dpx(theme.disp, 3));
386     lv_style_set_transform_height(&styles->grow, lv_disp_dpx(theme.disp, 3));
387 #endif
388 
389     style_init_reset(&styles->knob);
390     lv_style_set_bg_color(&styles->knob, theme.color_primary);
391     lv_style_set_bg_opa(&styles->knob, LV_OPA_COVER);
392     lv_style_set_pad_all(&styles->knob, lv_disp_dpx(theme.disp, 6));
393     lv_style_set_radius(&styles->knob, LV_RADIUS_CIRCLE);
394 
395     style_init_reset(&styles->anim);
396     lv_style_set_anim_time(&styles->anim, 200);
397 
398     style_init_reset(&styles->anim_fast);
399     lv_style_set_anim_time(&styles->anim_fast, 120);
400 
401 #if LV_USE_ARC
402     style_init_reset(&styles->arc_indic);
403     lv_style_set_arc_color(&styles->arc_indic, color_grey);
404     lv_style_set_arc_width(&styles->arc_indic, lv_disp_dpx(theme.disp, 15));
405     lv_style_set_arc_rounded(&styles->arc_indic, true);
406 
407     style_init_reset(&styles->arc_indic_primary);
408     lv_style_set_arc_color(&styles->arc_indic_primary, theme.color_primary);
409 #endif
410 
411 #if LV_USE_DROPDOWN
412     style_init_reset(&styles->dropdown_list);
413     lv_style_set_max_height(&styles->dropdown_list, LV_DPI_DEF * 2);
414 #endif
415 #if LV_USE_CHECKBOX
416     style_init_reset(&styles->cb_marker);
417     lv_style_set_pad_all(&styles->cb_marker, lv_disp_dpx(theme.disp, 3));
418     lv_style_set_border_width(&styles->cb_marker, BORDER_WIDTH);
419     lv_style_set_border_color(&styles->cb_marker, theme.color_primary);
420     lv_style_set_bg_color(&styles->cb_marker, color_card);
421     lv_style_set_bg_opa(&styles->cb_marker, LV_OPA_COVER);
422     lv_style_set_radius(&styles->cb_marker, RADIUS_DEFAULT / 2);
423 
424     style_init_reset(&styles->cb_marker_checked);
425     lv_style_set_bg_img_src(&styles->cb_marker_checked, LV_SYMBOL_OK);
426     lv_style_set_text_color(&styles->cb_marker_checked, lv_color_white());
427     lv_style_set_text_font(&styles->cb_marker_checked, theme.font_small);
428 #endif
429 
430 #if LV_USE_SWITCH
431     style_init_reset(&styles->switch_knob);
432     lv_style_set_pad_all(&styles->switch_knob, - lv_disp_dpx(theme.disp, 4));
433     lv_style_set_bg_color(&styles->switch_knob, lv_color_white());
434 #endif
435 
436 #if LV_USE_LINE
437     style_init_reset(&styles->line);
438     lv_style_set_line_width(&styles->line, 1);
439     lv_style_set_line_color(&styles->line, color_text);
440 #endif
441 
442 #if LV_USE_CHART
443     style_init_reset(&styles->chart_bg);
444     lv_style_set_border_post(&styles->chart_bg, false);
445     lv_style_set_pad_column(&styles->chart_bg, lv_disp_dpx(theme.disp, 10));
446     lv_style_set_line_color(&styles->chart_bg, color_grey);
447 
448     style_init_reset(&styles->chart_series);
449     lv_style_set_line_width(&styles->chart_series, lv_disp_dpx(theme.disp, 3));
450     lv_style_set_radius(&styles->chart_series, lv_disp_dpx(theme.disp, 3));
451     lv_style_set_size(&styles->chart_series, lv_disp_dpx(theme.disp, 8));
452     lv_style_set_pad_column(&styles->chart_series, lv_disp_dpx(theme.disp, 2));
453 
454     style_init_reset(&styles->chart_indic);
455     lv_style_set_radius(&styles->chart_indic, LV_RADIUS_CIRCLE);
456     lv_style_set_size(&styles->chart_indic, lv_disp_dpx(theme.disp, 8));
457     lv_style_set_bg_color(&styles->chart_indic, theme.color_primary);
458     lv_style_set_bg_opa(&styles->chart_indic, LV_OPA_COVER);
459 
460     style_init_reset(&styles->chart_ticks);
461     lv_style_set_line_width(&styles->chart_ticks, lv_disp_dpx(theme.disp, 1));
462     lv_style_set_line_color(&styles->chart_ticks, color_text);
463     lv_style_set_pad_all(&styles->chart_ticks, lv_disp_dpx(theme.disp, 2));
464     lv_style_set_text_color(&styles->chart_ticks, lv_palette_main(LV_PALETTE_GREY));
465 #endif
466 
467 #if LV_USE_MENU
468     style_init_reset(&styles->menu_bg);
469     lv_style_set_pad_all(&styles->menu_bg, 0);
470     lv_style_set_pad_gap(&styles->menu_bg, 0);
471     lv_style_set_radius(&styles->menu_bg, 0);
472     lv_style_set_clip_corner(&styles->menu_bg, true);
473     lv_style_set_border_side(&styles->menu_bg, LV_BORDER_SIDE_NONE);
474 
475     style_init_reset(&styles->menu_section);
476     lv_style_set_radius(&styles->menu_section, RADIUS_DEFAULT);
477     lv_style_set_clip_corner(&styles->menu_section, true);
478     lv_style_set_bg_opa(&styles->menu_section, LV_OPA_COVER);
479     lv_style_set_bg_color(&styles->menu_section, color_card);
480     lv_style_set_text_color(&styles->menu_section, color_text);
481 
482     style_init_reset(&styles->menu_cont);
483     lv_style_set_pad_hor(&styles->menu_cont, PAD_SMALL);
484     lv_style_set_pad_ver(&styles->menu_cont, PAD_SMALL);
485     lv_style_set_pad_gap(&styles->menu_cont, PAD_SMALL);
486     lv_style_set_border_width(&styles->menu_cont, lv_disp_dpx(theme.disp, 1));
487     lv_style_set_border_opa(&styles->menu_cont, LV_OPA_10);
488     lv_style_set_border_color(&styles->menu_cont, color_text);
489     lv_style_set_border_side(&styles->menu_cont, LV_BORDER_SIDE_NONE);
490 
491     style_init_reset(&styles->menu_sidebar_cont);
492     lv_style_set_pad_all(&styles->menu_sidebar_cont, 0);
493     lv_style_set_pad_gap(&styles->menu_sidebar_cont, 0);
494     lv_style_set_border_width(&styles->menu_sidebar_cont, lv_disp_dpx(theme.disp, 1));
495     lv_style_set_border_opa(&styles->menu_sidebar_cont, LV_OPA_10);
496     lv_style_set_border_color(&styles->menu_sidebar_cont, color_text);
497     lv_style_set_border_side(&styles->menu_sidebar_cont, LV_BORDER_SIDE_RIGHT);
498 
499     style_init_reset(&styles->menu_main_cont);
500     lv_style_set_pad_all(&styles->menu_main_cont, 0);
501     lv_style_set_pad_gap(&styles->menu_main_cont, 0);
502 
503     style_init_reset(&styles->menu_header_cont);
504     lv_style_set_pad_hor(&styles->menu_header_cont, PAD_SMALL);
505     lv_style_set_pad_ver(&styles->menu_header_cont, PAD_TINY);
506     lv_style_set_pad_gap(&styles->menu_header_cont, PAD_SMALL);
507 
508     style_init_reset(&styles->menu_header_btn);
509     lv_style_set_pad_hor(&styles->menu_header_btn, PAD_TINY);
510     lv_style_set_pad_ver(&styles->menu_header_btn, PAD_TINY);
511     lv_style_set_shadow_opa(&styles->menu_header_btn, LV_OPA_TRANSP);
512     lv_style_set_bg_opa(&styles->menu_header_btn, LV_OPA_TRANSP);
513     lv_style_set_text_color(&styles->menu_header_btn, color_text);
514 
515     style_init_reset(&styles->menu_page);
516     lv_style_set_pad_hor(&styles->menu_page, 0);
517     lv_style_set_pad_gap(&styles->menu_page, 0);
518 
519     style_init_reset(&styles->menu_pressed);
520     lv_style_set_bg_opa(&styles->menu_pressed, LV_OPA_20);
521     lv_style_set_bg_color(&styles->menu_pressed, lv_palette_main(LV_PALETTE_GREY));
522 
523     style_init_reset(&styles->menu_separator);
524     lv_style_set_bg_opa(&styles->menu_separator, LV_OPA_TRANSP);
525     lv_style_set_pad_ver(&styles->menu_separator, PAD_TINY);
526 #endif
527 
528 #if LV_USE_METER
529     style_init_reset(&styles->meter_marker);
530     lv_style_set_line_width(&styles->meter_marker, lv_disp_dpx(theme.disp, 5));
531     lv_style_set_line_color(&styles->meter_marker, color_text);
532     lv_style_set_size(&styles->meter_marker, lv_disp_dpx(theme.disp, 20));
533     lv_style_set_pad_left(&styles->meter_marker, lv_disp_dpx(theme.disp, 15));
534 
535     style_init_reset(&styles->meter_indic);
536     lv_style_set_radius(&styles->meter_indic, LV_RADIUS_CIRCLE);
537     lv_style_set_bg_color(&styles->meter_indic, color_text);
538     lv_style_set_bg_opa(&styles->meter_indic, LV_OPA_COVER);
539     lv_style_set_size(&styles->meter_indic, lv_disp_dpx(theme.disp, 15));
540 #endif
541 
542 #if LV_USE_TABLE
543     style_init_reset(&styles->table_cell);
544     lv_style_set_border_width(&styles->table_cell, lv_disp_dpx(theme.disp, 1));
545     lv_style_set_border_color(&styles->table_cell, color_grey);
546     lv_style_set_border_side(&styles->table_cell, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM);
547 #endif
548 
549 #if LV_USE_TEXTAREA
550     style_init_reset(&styles->ta_cursor);
551     lv_style_set_border_color(&styles->ta_cursor, color_text);
552     lv_style_set_border_width(&styles->ta_cursor, lv_disp_dpx(theme.disp, 2));
553     lv_style_set_pad_left(&styles->ta_cursor, - lv_disp_dpx(theme.disp, 1));
554     lv_style_set_border_side(&styles->ta_cursor, LV_BORDER_SIDE_LEFT);
555     lv_style_set_anim_time(&styles->ta_cursor, 400);
556 
557     style_init_reset(&styles->ta_placeholder);
558     lv_style_set_text_color(&styles->ta_placeholder, (theme.flags & MODE_DARK) ? lv_palette_darken(LV_PALETTE_GREY,
559                                                                                                    2) : lv_palette_lighten(LV_PALETTE_GREY, 1));
560 #endif
561 
562 #if LV_USE_CALENDAR
563     style_init_reset(&styles->calendar_btnm_bg);
564     lv_style_set_pad_all(&styles->calendar_btnm_bg, PAD_SMALL);
565     lv_style_set_pad_gap(&styles->calendar_btnm_bg, PAD_SMALL / 2);
566 
567     style_init_reset(&styles->calendar_btnm_day);
568     lv_style_set_border_width(&styles->calendar_btnm_day, lv_disp_dpx(theme.disp, 1));
569     lv_style_set_border_color(&styles->calendar_btnm_day, color_grey);
570     lv_style_set_bg_color(&styles->calendar_btnm_day, color_card);
571     lv_style_set_bg_opa(&styles->calendar_btnm_day, LV_OPA_20);
572 
573     style_init_reset(&styles->calendar_header);
574     lv_style_set_pad_hor(&styles->calendar_header, PAD_SMALL);
575     lv_style_set_pad_top(&styles->calendar_header, PAD_SMALL);
576     lv_style_set_pad_bottom(&styles->calendar_header, PAD_TINY);
577     lv_style_set_pad_gap(&styles->calendar_header, PAD_SMALL);
578 #endif
579 
580 #if LV_USE_COLORWHEEL
581     style_init_reset(&styles->colorwheel_main);
582     lv_style_set_arc_width(&styles->colorwheel_main, lv_disp_dpx(theme.disp, 10));
583 #endif
584 
585 #if LV_USE_MSGBOX
586     /*To add space for for the button shadow*/
587     style_init_reset(&styles->msgbox_btn_bg);
588     lv_style_set_pad_all(&styles->msgbox_btn_bg, lv_disp_dpx(theme.disp, 4));
589 
590     style_init_reset(&styles->msgbox_bg);
591     lv_style_set_max_width(&styles->msgbox_bg, lv_pct(100));
592 
593     style_init_reset(&styles->msgbox_backdrop_bg);
594     lv_style_set_bg_color(&styles->msgbox_backdrop_bg, lv_palette_main(LV_PALETTE_GREY));
595     lv_style_set_bg_opa(&styles->msgbox_backdrop_bg, LV_OPA_50);
596 #endif
597 #if LV_USE_KEYBOARD
598     style_init_reset(&styles->keyboard_btn_bg);
599     lv_style_set_shadow_width(&styles->keyboard_btn_bg, 0);
600     lv_style_set_radius(&styles->keyboard_btn_bg, disp_size == DISP_SMALL ? RADIUS_DEFAULT / 2 : RADIUS_DEFAULT);
601 #endif
602 
603 #if LV_USE_TABVIEW
604     style_init_reset(&styles->tab_btn);
605     lv_style_set_border_color(&styles->tab_btn, theme.color_primary);
606     lv_style_set_border_width(&styles->tab_btn, BORDER_WIDTH * 2);
607     lv_style_set_border_side(&styles->tab_btn, LV_BORDER_SIDE_BOTTOM);
608 
609     style_init_reset(&styles->tab_bg_focus);
610     lv_style_set_outline_pad(&styles->tab_bg_focus, -BORDER_WIDTH);
611 #endif
612 
613 #if LV_USE_LIST
614     style_init_reset(&styles->list_bg);
615     lv_style_set_pad_hor(&styles->list_bg, PAD_DEF);
616     lv_style_set_pad_ver(&styles->list_bg, 0);
617     lv_style_set_pad_gap(&styles->list_bg, 0);
618     lv_style_set_clip_corner(&styles->list_bg, true);
619 
620     style_init_reset(&styles->list_btn);
621     lv_style_set_border_width(&styles->list_btn, lv_disp_dpx(theme.disp, 1));
622     lv_style_set_border_color(&styles->list_btn, color_grey);
623     lv_style_set_border_side(&styles->list_btn, LV_BORDER_SIDE_BOTTOM);
624     lv_style_set_pad_all(&styles->list_btn, PAD_SMALL);
625     lv_style_set_pad_column(&styles->list_btn, PAD_SMALL);
626 
627     style_init_reset(&styles->list_item_grow);
628     lv_style_set_transform_width(&styles->list_item_grow, PAD_DEF);
629 #endif
630 
631 
632 #if LV_USE_LED
633     style_init_reset(&styles->led);
634     lv_style_set_bg_opa(&styles->led, LV_OPA_COVER);
635     lv_style_set_bg_color(&styles->led, lv_color_white());
636     lv_style_set_bg_grad_color(&styles->led, lv_palette_main(LV_PALETTE_GREY));
637     lv_style_set_radius(&styles->led, LV_RADIUS_CIRCLE);
638     lv_style_set_shadow_width(&styles->led, lv_disp_dpx(theme.disp, 15));
639     lv_style_set_shadow_color(&styles->led, lv_color_white());
640     lv_style_set_shadow_spread(&styles->led, lv_disp_dpx(theme.disp, 5));
641 #endif
642 }
643 
644 /**********************
645  *   GLOBAL FUNCTIONS
646  **********************/
647 
lv_theme_default_init(lv_disp_t * disp,lv_color_t color_primary,lv_color_t color_secondary,bool dark,const lv_font_t * font)648 lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_color_t color_primary, lv_color_t color_secondary, bool dark,
649                                    const lv_font_t * font)
650 {
651 
652     /*This trick is required only to avoid the garbage collection of
653      *styles' data if LVGL is used in a binding (e.g. Micropython)
654      *In a general case styles could be in simple `static lv_style_t my_style...` variables*/
655     if(!lv_theme_default_is_inited()) {
656         inited = false;
657         LV_GC_ROOT(_lv_theme_default_styles) = lv_mem_alloc(sizeof(my_theme_styles_t));
658         styles = (my_theme_styles_t *)LV_GC_ROOT(_lv_theme_default_styles);
659     }
660 
661     if(LV_HOR_RES <= 320) disp_size = DISP_SMALL;
662     else if(LV_HOR_RES < 720) disp_size = DISP_MEDIUM;
663     else disp_size = DISP_LARGE;
664 
665     theme.disp = disp;
666     theme.color_primary = color_primary;
667     theme.color_secondary = color_secondary;
668     theme.font_small = font;
669     theme.font_normal = font;
670     theme.font_large = font;
671     theme.apply_cb = theme_apply;
672     theme.flags = dark ? MODE_DARK : 0;
673 
674     style_init();
675 
676     if(disp == NULL || lv_disp_get_theme(disp) == &theme) lv_obj_report_style_change(NULL);
677 
678     inited = true;
679 
680     return (lv_theme_t *)&theme;
681 }
682 
lv_theme_default_get(void)683 lv_theme_t * lv_theme_default_get(void)
684 {
685     if(!lv_theme_default_is_inited()) {
686         return NULL;
687     }
688 
689     return (lv_theme_t *)&theme;
690 }
691 
lv_theme_default_is_inited(void)692 bool lv_theme_default_is_inited(void)
693 {
694     return  LV_GC_ROOT(_lv_theme_default_styles) == NULL ? false : true;
695 }
696 
697 
theme_apply(lv_theme_t * th,lv_obj_t * obj)698 static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
699 {
700     LV_UNUSED(th);
701 
702     if(lv_obj_get_parent(obj) == NULL) {
703         lv_obj_add_style(obj, &styles->scr, 0);
704         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
705         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
706         return;
707     }
708 
709     if(lv_obj_check_type(obj, &lv_obj_class)) {
710 #if LV_USE_TABVIEW
711         lv_obj_t * parent = lv_obj_get_parent(obj);
712         /*Tabview content area*/
713         if(lv_obj_check_type(parent, &lv_tabview_class)) {
714             return;
715         }
716         /*Tabview pages*/
717         else if(lv_obj_check_type(lv_obj_get_parent(parent), &lv_tabview_class)) {
718             lv_obj_add_style(obj, &styles->pad_normal, 0);
719             lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
720             lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
721             return;
722         }
723 #endif
724 
725 #if LV_USE_WIN
726         /*Header*/
727         if(lv_obj_get_index(obj) == 0 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win_class)) {
728             lv_obj_add_style(obj, &styles->bg_color_grey, 0);
729             lv_obj_add_style(obj, &styles->pad_tiny, 0);
730             return;
731         }
732         /*Content*/
733         else if(lv_obj_get_index(obj) == 1 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win_class)) {
734             lv_obj_add_style(obj, &styles->scr, 0);
735             lv_obj_add_style(obj, &styles->pad_normal, 0);
736             lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
737             lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
738             return;
739         }
740 #endif
741 
742 
743 #if LV_USE_CALENDAR
744         if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_calendar_class)) {
745             /*No style*/
746             return;
747         }
748 #endif
749 
750         lv_obj_add_style(obj, &styles->card, 0);
751         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
752         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
753     }
754 #if LV_USE_BTN
755     else if(lv_obj_check_type(obj, &lv_btn_class)) {
756         lv_obj_add_style(obj, &styles->btn, 0);
757         lv_obj_add_style(obj, &styles->bg_color_primary, 0);
758         lv_obj_add_style(obj, &styles->transition_delayed, 0);
759         lv_obj_add_style(obj, &styles->pressed, LV_STATE_PRESSED);
760         lv_obj_add_style(obj, &styles->transition_normal, LV_STATE_PRESSED);
761         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
762 #if LV_THEME_DEFAULT_GROW
763         lv_obj_add_style(obj, &styles->grow, LV_STATE_PRESSED);
764 #endif
765         lv_obj_add_style(obj, &styles->bg_color_secondary, LV_STATE_CHECKED);
766         lv_obj_add_style(obj, &styles->disabled, LV_STATE_DISABLED);
767 
768 #if LV_USE_MENU
769         if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_menu_sidebar_header_cont_class) ||
770            lv_obj_check_type(lv_obj_get_parent(obj), &lv_menu_main_header_cont_class)) {
771             lv_obj_add_style(obj, &styles->menu_header_btn, 0);
772             lv_obj_add_style(obj, &styles->menu_pressed, LV_STATE_PRESSED);
773         }
774 #endif
775     }
776 #endif
777 
778 #if LV_USE_LINE
779     else if(lv_obj_check_type(obj, &lv_line_class)) {
780         lv_obj_add_style(obj, &styles->line, 0);
781     }
782 #endif
783 
784 #if LV_USE_BTNMATRIX
785     else if(lv_obj_check_type(obj, &lv_btnmatrix_class)) {
786 #if LV_USE_MSGBOX
787         if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_msgbox_class)) {
788             lv_obj_add_style(obj, &styles->msgbox_btn_bg, 0);
789             lv_obj_add_style(obj, &styles->pad_gap, 0);
790             lv_obj_add_style(obj, &styles->btn, LV_PART_ITEMS);
791             lv_obj_add_style(obj, &styles->pressed, LV_PART_ITEMS | LV_STATE_PRESSED);
792             lv_obj_add_style(obj, &styles->disabled, LV_PART_ITEMS | LV_STATE_DISABLED);
793             lv_obj_add_style(obj, &styles->bg_color_primary, LV_PART_ITEMS | LV_STATE_CHECKED);
794             lv_obj_add_style(obj, &styles->bg_color_primary_muted, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
795             lv_obj_add_style(obj, &styles->bg_color_secondary_muted, LV_PART_ITEMS | LV_STATE_EDITED);
796             return;
797         }
798 #endif
799 #if LV_USE_TABVIEW
800         if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_tabview_class)) {
801             lv_obj_add_style(obj, &styles->bg_color_white, 0);
802             lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
803             lv_obj_add_style(obj, &styles->tab_bg_focus, LV_STATE_FOCUS_KEY);
804             lv_obj_add_style(obj, &styles->pressed, LV_PART_ITEMS | LV_STATE_PRESSED);
805             lv_obj_add_style(obj, &styles->bg_color_primary_muted, LV_PART_ITEMS | LV_STATE_CHECKED);
806             lv_obj_add_style(obj, &styles->tab_btn, LV_PART_ITEMS | LV_STATE_CHECKED);
807             lv_obj_add_style(obj, &styles->outline_primary, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
808             lv_obj_add_style(obj, &styles->outline_secondary, LV_PART_ITEMS | LV_STATE_EDITED);
809             lv_obj_add_style(obj, &styles->tab_bg_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
810             return;
811         }
812 #endif
813 
814 #if LV_USE_CALENDAR
815         if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_calendar_class)) {
816             lv_obj_add_style(obj, &styles->calendar_btnm_bg, 0);
817             lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
818             lv_obj_add_style(obj, &styles->outline_secondary, LV_STATE_EDITED);
819             lv_obj_add_style(obj, &styles->calendar_btnm_day, LV_PART_ITEMS);
820             lv_obj_add_style(obj, &styles->pressed, LV_PART_ITEMS | LV_STATE_PRESSED);
821             lv_obj_add_style(obj, &styles->disabled, LV_PART_ITEMS | LV_STATE_DISABLED);
822             lv_obj_add_style(obj, &styles->outline_primary, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
823             lv_obj_add_style(obj, &styles->outline_secondary, LV_PART_ITEMS | LV_STATE_EDITED);
824             return;
825         }
826 #endif
827         lv_obj_add_style(obj, &styles->card, 0);
828         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
829         lv_obj_add_style(obj, &styles->outline_secondary, LV_STATE_EDITED);
830         lv_obj_add_style(obj, &styles->btn, LV_PART_ITEMS);
831         lv_obj_add_style(obj, &styles->disabled, LV_PART_ITEMS | LV_STATE_DISABLED);
832         lv_obj_add_style(obj, &styles->pressed, LV_PART_ITEMS | LV_STATE_PRESSED);
833         lv_obj_add_style(obj, &styles->bg_color_primary, LV_PART_ITEMS | LV_STATE_CHECKED);
834         lv_obj_add_style(obj, &styles->outline_primary, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
835         lv_obj_add_style(obj, &styles->outline_secondary, LV_PART_ITEMS | LV_STATE_EDITED);
836     }
837 #endif
838 
839 #if LV_USE_BAR
840     else if(lv_obj_check_type(obj, &lv_bar_class)) {
841         lv_obj_add_style(obj, &styles->bg_color_primary_muted, 0);
842         lv_obj_add_style(obj, &styles->circle, 0);
843         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
844         lv_obj_add_style(obj, &styles->outline_secondary, LV_STATE_EDITED);
845         lv_obj_add_style(obj, &styles->bg_color_primary, LV_PART_INDICATOR);
846         lv_obj_add_style(obj, &styles->circle, LV_PART_INDICATOR);
847     }
848 #endif
849 
850 #if LV_USE_SLIDER
851     else if(lv_obj_check_type(obj, &lv_slider_class)) {
852         lv_obj_add_style(obj, &styles->bg_color_primary_muted, 0);
853         lv_obj_add_style(obj, &styles->circle, 0);
854         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
855         lv_obj_add_style(obj, &styles->outline_secondary, LV_STATE_EDITED);
856         lv_obj_add_style(obj, &styles->bg_color_primary, LV_PART_INDICATOR);
857         lv_obj_add_style(obj, &styles->circle, LV_PART_INDICATOR);
858         lv_obj_add_style(obj, &styles->knob, LV_PART_KNOB);
859 #if LV_THEME_DEFAULT_GROW
860         lv_obj_add_style(obj, &styles->grow, LV_PART_KNOB | LV_STATE_PRESSED);
861 #endif
862         lv_obj_add_style(obj, &styles->transition_delayed, LV_PART_KNOB);
863         lv_obj_add_style(obj, &styles->transition_normal, LV_PART_KNOB | LV_STATE_PRESSED);
864     }
865 #endif
866 
867 #if LV_USE_TABLE
868     else if(lv_obj_check_type(obj, &lv_table_class)) {
869         lv_obj_add_style(obj, &styles->card, 0);
870         lv_obj_add_style(obj, &styles->pad_zero, 0);
871         lv_obj_add_style(obj, &styles->no_radius, 0);
872         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
873         lv_obj_add_style(obj, &styles->outline_secondary, LV_STATE_EDITED);
874         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
875         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
876         lv_obj_add_style(obj, &styles->bg_color_white, LV_PART_ITEMS);
877         lv_obj_add_style(obj, &styles->table_cell, LV_PART_ITEMS);
878         lv_obj_add_style(obj, &styles->pad_normal, LV_PART_ITEMS);
879         lv_obj_add_style(obj, &styles->pressed, LV_PART_ITEMS | LV_STATE_PRESSED);
880         lv_obj_add_style(obj, &styles->bg_color_primary, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
881         lv_obj_add_style(obj, &styles->bg_color_secondary, LV_PART_ITEMS | LV_STATE_EDITED);
882     }
883 #endif
884 
885 #if LV_USE_CHECKBOX
886     else if(lv_obj_check_type(obj, &lv_checkbox_class)) {
887         lv_obj_add_style(obj, &styles->pad_gap, 0);
888         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
889         lv_obj_add_style(obj, &styles->disabled, LV_PART_INDICATOR | LV_STATE_DISABLED);
890         lv_obj_add_style(obj, &styles->cb_marker, LV_PART_INDICATOR);
891         lv_obj_add_style(obj, &styles->bg_color_primary, LV_PART_INDICATOR | LV_STATE_CHECKED);
892         lv_obj_add_style(obj, &styles->cb_marker_checked, LV_PART_INDICATOR | LV_STATE_CHECKED);
893         lv_obj_add_style(obj, &styles->pressed, LV_PART_INDICATOR | LV_STATE_PRESSED);
894 #if LV_THEME_DEFAULT_GROW
895         lv_obj_add_style(obj, &styles->grow, LV_PART_INDICATOR | LV_STATE_PRESSED);
896 #endif
897         lv_obj_add_style(obj, &styles->transition_normal, LV_PART_INDICATOR | LV_STATE_PRESSED);
898         lv_obj_add_style(obj, &styles->transition_delayed, LV_PART_INDICATOR);
899     }
900 #endif
901 
902 #if LV_USE_SWITCH
903     else if(lv_obj_check_type(obj, &lv_switch_class)) {
904         lv_obj_add_style(obj, &styles->bg_color_grey, 0);
905         lv_obj_add_style(obj, &styles->circle, 0);
906         lv_obj_add_style(obj, &styles->anim_fast, 0);
907         lv_obj_add_style(obj, &styles->disabled, LV_STATE_DISABLED);
908         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
909         lv_obj_add_style(obj, &styles->bg_color_primary, LV_PART_INDICATOR | LV_STATE_CHECKED);
910         lv_obj_add_style(obj, &styles->circle, LV_PART_INDICATOR);
911         lv_obj_add_style(obj, &styles->disabled, LV_PART_INDICATOR | LV_STATE_DISABLED);
912         lv_obj_add_style(obj, &styles->knob, LV_PART_KNOB);
913         lv_obj_add_style(obj, &styles->bg_color_white, LV_PART_KNOB);
914         lv_obj_add_style(obj, &styles->switch_knob, LV_PART_KNOB);
915         lv_obj_add_style(obj, &styles->disabled, LV_PART_KNOB | LV_STATE_DISABLED);
916 
917         lv_obj_add_style(obj, &styles->transition_normal, LV_PART_INDICATOR | LV_STATE_CHECKED);
918         lv_obj_add_style(obj, &styles->transition_normal, LV_PART_INDICATOR);
919     }
920 #endif
921 
922 #if LV_USE_CHART
923     else if(lv_obj_check_type(obj, &lv_chart_class)) {
924         lv_obj_add_style(obj, &styles->card, 0);
925         lv_obj_add_style(obj, &styles->pad_small, 0);
926         lv_obj_add_style(obj, &styles->chart_bg, 0);
927         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
928         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
929         lv_obj_add_style(obj, &styles->chart_series, LV_PART_ITEMS);
930         lv_obj_add_style(obj, &styles->chart_indic, LV_PART_INDICATOR);
931         lv_obj_add_style(obj, &styles->chart_ticks, LV_PART_TICKS);
932         lv_obj_add_style(obj, &styles->chart_series, LV_PART_CURSOR);
933     }
934 #endif
935 
936 #if LV_USE_ROLLER
937     else if(lv_obj_check_type(obj, &lv_roller_class)) {
938         lv_obj_add_style(obj, &styles->card, 0);
939         lv_obj_add_style(obj, &styles->anim, 0);
940         lv_obj_add_style(obj, &styles->line_space_large, 0);
941         lv_obj_add_style(obj, &styles->text_align_center, 0);
942         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
943         lv_obj_add_style(obj, &styles->outline_secondary, LV_STATE_EDITED);
944         lv_obj_add_style(obj, &styles->bg_color_primary, LV_PART_SELECTED);
945     }
946 #endif
947 
948 #if LV_USE_DROPDOWN
949     else if(lv_obj_check_type(obj, &lv_dropdown_class)) {
950         lv_obj_add_style(obj, &styles->card, 0);
951         lv_obj_add_style(obj, &styles->pad_small, 0);
952         lv_obj_add_style(obj, &styles->transition_delayed, 0);
953         lv_obj_add_style(obj, &styles->transition_normal, LV_STATE_PRESSED);
954         lv_obj_add_style(obj, &styles->pressed, LV_STATE_PRESSED);
955         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
956         lv_obj_add_style(obj, &styles->outline_secondary, LV_STATE_EDITED);
957         lv_obj_add_style(obj, &styles->transition_normal, LV_PART_INDICATOR);
958     }
959     else if(lv_obj_check_type(obj, &lv_dropdownlist_class)) {
960         lv_obj_add_style(obj, &styles->card, 0);
961         lv_obj_add_style(obj, &styles->clip_corner, 0);
962         lv_obj_add_style(obj, &styles->line_space_large, 0);
963         lv_obj_add_style(obj, &styles->dropdown_list, 0);
964         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
965         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
966         lv_obj_add_style(obj, &styles->bg_color_white, LV_PART_SELECTED);
967         lv_obj_add_style(obj, &styles->bg_color_primary, LV_PART_SELECTED | LV_STATE_CHECKED);
968         lv_obj_add_style(obj, &styles->pressed, LV_PART_SELECTED | LV_STATE_PRESSED);
969     }
970 #endif
971 
972 #if LV_USE_ARC
973     else if(lv_obj_check_type(obj, &lv_arc_class)) {
974         lv_obj_add_style(obj, &styles->arc_indic, 0);
975         lv_obj_add_style(obj, &styles->arc_indic, LV_PART_INDICATOR);
976         lv_obj_add_style(obj, &styles->arc_indic_primary, LV_PART_INDICATOR);
977         lv_obj_add_style(obj, &styles->knob, LV_PART_KNOB);
978     }
979 #endif
980 
981 
982 #if LV_USE_SPINNER
983     else if(lv_obj_check_type(obj, &lv_spinner_class)) {
984         lv_obj_add_style(obj, &styles->arc_indic, 0);
985         lv_obj_add_style(obj, &styles->arc_indic, LV_PART_INDICATOR);
986         lv_obj_add_style(obj, &styles->arc_indic_primary, LV_PART_INDICATOR);
987     }
988 #endif
989 
990 #if LV_USE_METER
991     else if(lv_obj_check_type(obj, &lv_meter_class)) {
992         lv_obj_add_style(obj, &styles->card, 0);
993         lv_obj_add_style(obj, &styles->circle, 0);
994         lv_obj_add_style(obj, &styles->meter_indic, LV_PART_INDICATOR);
995     }
996 #endif
997 
998 #if LV_USE_TEXTAREA
999     else if(lv_obj_check_type(obj, &lv_textarea_class)) {
1000         lv_obj_add_style(obj, &styles->card, 0);
1001         lv_obj_add_style(obj, &styles->pad_small, 0);
1002         lv_obj_add_style(obj, &styles->disabled, LV_STATE_DISABLED);
1003         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
1004         lv_obj_add_style(obj, &styles->outline_secondary, LV_STATE_EDITED);
1005         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
1006         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
1007         lv_obj_add_style(obj, &styles->ta_cursor, LV_PART_CURSOR | LV_STATE_FOCUSED);
1008         lv_obj_add_style(obj, &styles->ta_placeholder, LV_PART_TEXTAREA_PLACEHOLDER);
1009     }
1010 #endif
1011 
1012 #if LV_USE_CALENDAR
1013     else if(lv_obj_check_type(obj, &lv_calendar_class)) {
1014         lv_obj_add_style(obj, &styles->card, 0);
1015         lv_obj_add_style(obj, &styles->pad_zero, 0);
1016     }
1017 #endif
1018 
1019 #if LV_USE_CALENDAR_HEADER_ARROW
1020     else if(lv_obj_check_type(obj, &lv_calendar_header_arrow_class)) {
1021         lv_obj_add_style(obj, &styles->calendar_header, 0);
1022     }
1023 #endif
1024 
1025 #if LV_USE_CALENDAR_HEADER_DROPDOWN
1026     else if(lv_obj_check_type(obj, &lv_calendar_header_dropdown_class)) {
1027         lv_obj_add_style(obj, &styles->calendar_header, 0);
1028     }
1029 #endif
1030 
1031 #if LV_USE_KEYBOARD
1032     else if(lv_obj_check_type(obj, &lv_keyboard_class)) {
1033         lv_obj_add_style(obj, &styles->scr, 0);
1034         lv_obj_add_style(obj, disp_size == DISP_LARGE ? &styles->pad_small : &styles->pad_tiny, 0);
1035         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
1036         lv_obj_add_style(obj, &styles->outline_secondary, LV_STATE_EDITED);
1037         lv_obj_add_style(obj, &styles->btn, LV_PART_ITEMS);
1038         lv_obj_add_style(obj, &styles->disabled, LV_PART_ITEMS | LV_STATE_DISABLED);
1039         lv_obj_add_style(obj, &styles->bg_color_white, LV_PART_ITEMS);
1040         lv_obj_add_style(obj, &styles->keyboard_btn_bg, LV_PART_ITEMS);
1041         lv_obj_add_style(obj, &styles->pressed, LV_PART_ITEMS | LV_STATE_PRESSED);
1042         lv_obj_add_style(obj, &styles->bg_color_grey, LV_PART_ITEMS | LV_STATE_CHECKED);
1043         lv_obj_add_style(obj, &styles->bg_color_primary_muted, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
1044         lv_obj_add_style(obj, &styles->bg_color_secondary_muted, LV_PART_ITEMS | LV_STATE_EDITED);
1045     }
1046 #endif
1047 #if LV_USE_LIST
1048     else if(lv_obj_check_type(obj, &lv_list_class)) {
1049         lv_obj_add_style(obj, &styles->card, 0);
1050         lv_obj_add_style(obj, &styles->list_bg, 0);
1051         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
1052         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
1053         return;
1054     }
1055     else if(lv_obj_check_type(obj, &lv_list_text_class)) {
1056         lv_obj_add_style(obj, &styles->bg_color_grey, 0);
1057         lv_obj_add_style(obj, &styles->list_item_grow, 0);
1058     }
1059     else if(lv_obj_check_type(obj, &lv_list_btn_class)) {
1060         lv_obj_add_style(obj, &styles->bg_color_white, 0);
1061         lv_obj_add_style(obj, &styles->list_btn, 0);
1062         lv_obj_add_style(obj, &styles->bg_color_primary, LV_STATE_FOCUS_KEY);
1063         lv_obj_add_style(obj, &styles->list_item_grow, LV_STATE_FOCUS_KEY);
1064         lv_obj_add_style(obj, &styles->list_item_grow, LV_STATE_PRESSED);
1065         lv_obj_add_style(obj, &styles->pressed, LV_STATE_PRESSED);
1066 
1067     }
1068 #endif
1069 #if LV_USE_MENU
1070     else if(lv_obj_check_type(obj, &lv_menu_class)) {
1071         lv_obj_add_style(obj, &styles->card, 0);
1072         lv_obj_add_style(obj, &styles->menu_bg, 0);
1073     }
1074     else if(lv_obj_check_type(obj, &lv_menu_sidebar_cont_class)) {
1075         lv_obj_add_style(obj, &styles->menu_sidebar_cont, 0);
1076         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
1077         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
1078     }
1079     else if(lv_obj_check_type(obj, &lv_menu_main_cont_class)) {
1080         lv_obj_add_style(obj, &styles->menu_main_cont, 0);
1081         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
1082         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
1083     }
1084     else if(lv_obj_check_type(obj, &lv_menu_cont_class)) {
1085         lv_obj_add_style(obj, &styles->menu_cont, 0);
1086         lv_obj_add_style(obj, &styles->menu_pressed, LV_STATE_PRESSED);
1087         lv_obj_add_style(obj, &styles->bg_color_primary_muted, LV_STATE_PRESSED | LV_STATE_CHECKED);
1088         lv_obj_add_style(obj, &styles->bg_color_primary_muted, LV_STATE_CHECKED);
1089         lv_obj_add_style(obj, &styles->bg_color_primary, LV_STATE_FOCUS_KEY);
1090     }
1091     else if(lv_obj_check_type(obj, &lv_menu_sidebar_header_cont_class) ||
1092             lv_obj_check_type(obj, &lv_menu_main_header_cont_class)) {
1093         lv_obj_add_style(obj, &styles->menu_header_cont, 0);
1094     }
1095     else if(lv_obj_check_type(obj, &lv_menu_page_class)) {
1096         lv_obj_add_style(obj, &styles->menu_page, 0);
1097         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
1098         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
1099     }
1100     else if(lv_obj_check_type(obj, &lv_menu_section_class)) {
1101         lv_obj_add_style(obj, &styles->menu_section, 0);
1102     }
1103     else if(lv_obj_check_type(obj, &lv_menu_separator_class)) {
1104         lv_obj_add_style(obj, &styles->menu_separator, 0);
1105     }
1106 #endif
1107 #if LV_USE_MSGBOX
1108     else if(lv_obj_check_type(obj, &lv_msgbox_class)) {
1109         lv_obj_add_style(obj, &styles->card, 0);
1110         lv_obj_add_style(obj, &styles->msgbox_bg, 0);
1111         return;
1112     }
1113     else if(lv_obj_check_type(obj, &lv_msgbox_backdrop_class)) {
1114         lv_obj_add_style(obj, &styles->msgbox_backdrop_bg, 0);
1115     }
1116 #endif
1117 #if LV_USE_SPINBOX
1118     else if(lv_obj_check_type(obj, &lv_spinbox_class)) {
1119         lv_obj_add_style(obj, &styles->card, 0);
1120         lv_obj_add_style(obj, &styles->pad_small, 0);
1121         lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
1122         lv_obj_add_style(obj, &styles->outline_secondary, LV_STATE_EDITED);
1123         lv_obj_add_style(obj, &styles->bg_color_primary, LV_PART_CURSOR);
1124     }
1125 #endif
1126 #if LV_USE_TILEVIEW
1127     else if(lv_obj_check_type(obj, &lv_tileview_class)) {
1128         lv_obj_add_style(obj, &styles->scr, 0);
1129         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
1130         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
1131     }
1132     else if(lv_obj_check_type(obj, &lv_tileview_tile_class)) {
1133         lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR);
1134         lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
1135     }
1136 #endif
1137 
1138 #if LV_USE_TABVIEW
1139     else if(lv_obj_check_type(obj, &lv_tabview_class)) {
1140         lv_obj_add_style(obj, &styles->scr, 0);
1141         lv_obj_add_style(obj, &styles->pad_zero, 0);
1142     }
1143 #endif
1144 
1145 #if LV_USE_WIN
1146     else if(lv_obj_check_type(obj, &lv_win_class)) {
1147         lv_obj_add_style(obj, &styles->clip_corner, 0);
1148     }
1149 #endif
1150 
1151 #if LV_USE_COLORWHEEL
1152     else if(lv_obj_check_type(obj, &lv_colorwheel_class)) {
1153         lv_obj_add_style(obj, &styles->colorwheel_main, 0);
1154         lv_obj_add_style(obj, &styles->pad_normal, 0);
1155         lv_obj_add_style(obj, &styles->bg_color_white, LV_PART_KNOB);
1156         lv_obj_add_style(obj, &styles->pad_normal, LV_PART_KNOB);
1157     }
1158 #endif
1159 
1160 #if LV_USE_LED
1161     else if(lv_obj_check_type(obj, &lv_led_class)) {
1162         lv_obj_add_style(obj, &styles->led, 0);
1163     }
1164 #endif
1165 }
1166 
1167 /**********************
1168  *   STATIC FUNCTIONS
1169  **********************/
1170 
style_init_reset(lv_style_t * style)1171 static void style_init_reset(lv_style_t * style)
1172 {
1173     if(inited) {
1174         lv_style_reset(style);
1175     }
1176     else {
1177         lv_style_init(style);
1178     }
1179 }
1180 
1181 #endif
1182