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