1 /**
2 * @file lv_theme_default.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_theme.h"
10
11 #if LV_USE_THEME_DEFAULT
12
13 /*********************
14 * DEFINES
15 *********************/
16
17 /**********************
18 * TYPEDEFS
19 **********************/
20
21 /**********************
22 * STATIC PROTOTYPES
23 **********************/
24
25 /**********************
26 * STATIC VARIABLES
27 **********************/
28 static lv_theme_t theme;
29 static lv_style_t def;
30 static lv_style_t scr;
31
32 /*Static style definitions*/
33 static lv_style_t sb;
34 static lv_style_t plain_bordered;
35 static lv_style_t label_prim;
36 static lv_style_t label_sec;
37 static lv_style_t label_hint;
38
39 /*Saved input parameters*/
40 static uint16_t _hue;
41 static lv_font_t * _font;
42
43 /**********************
44 * MACROS
45 **********************/
46
47 /**********************
48 * STATIC FUNCTIONS
49 **********************/
50
basic_init(void)51 static void basic_init(void)
52 {
53 lv_style_copy(&def, &lv_style_pretty); /*Initialize the default style*/
54
55 lv_style_copy(&scr, &def);
56 scr.body.padding.bottom = 0;
57 scr.body.padding.top = 0;
58 scr.body.padding.left = 0;
59 scr.body.padding.right = 0;
60
61 lv_style_copy(&sb, &lv_style_pretty_color);
62 sb.body.grad_color = sb.body.main_color;
63 sb.body.padding.right = sb.body.padding.right / 2; /*Make closer to the edges*/
64 sb.body.padding.bottom = sb.body.padding.bottom / 2;
65
66 lv_style_copy(&plain_bordered, &lv_style_plain);
67 plain_bordered.body.border.width = 2;
68 plain_bordered.body.border.color = lv_color_hex3(0xbbb);
69
70 theme.style.bg = &lv_style_plain;
71 theme.style.scr = &scr;
72 theme.style.panel = &lv_style_pretty;
73 }
74
btn_init(void)75 static void btn_init(void)
76 {
77 #if LV_USE_BTN != 0
78 theme.style.btn.rel = &lv_style_btn_rel;
79 theme.style.btn.pr = &lv_style_btn_pr;
80 theme.style.btn.tgl_rel = &lv_style_btn_tgl_rel;
81 theme.style.btn.tgl_pr = &lv_style_btn_tgl_pr;
82 theme.style.btn.ina = &lv_style_btn_ina;
83 #endif
84 }
85
label_init(void)86 static void label_init(void)
87 {
88 #if LV_USE_LABEL != 0
89
90 lv_style_copy(&label_prim, &lv_style_plain);
91 lv_style_copy(&label_sec, &lv_style_plain);
92 lv_style_copy(&label_hint, &lv_style_plain);
93
94 label_prim.text.color = lv_color_hex3(0x111);
95 label_sec.text.color = lv_color_hex3(0x888);
96 label_hint.text.color = lv_color_hex3(0xaaa);
97
98 theme.style.label.prim = &label_prim;
99 theme.style.label.sec = &label_sec;
100 theme.style.label.hint = &label_hint;
101 #endif
102 }
103
img_init(void)104 static void img_init(void)
105 {
106 #if LV_USE_IMG != 0
107
108 theme.style.img.light = &def;
109 theme.style.img.dark = &def;
110 #endif
111 }
112
line_init(void)113 static void line_init(void)
114 {
115 #if LV_USE_LINE != 0
116
117 theme.style.line.decor = &def;
118 #endif
119 }
120
led_init(void)121 static void led_init(void)
122 {
123 #if LV_USE_LED != 0
124 static lv_style_t led;
125
126 lv_style_copy(&led, &lv_style_pretty_color);
127 led.body.shadow.width = LV_DPI / 10;
128 led.body.radius = LV_RADIUS_CIRCLE;
129 led.body.border.width = LV_DPI / 30;
130 led.body.border.opa = LV_OPA_30;
131 led.body.shadow.color = led.body.main_color;
132
133 theme.style.led = &led;
134 #endif
135 }
136
bar_init(void)137 static void bar_init(void)
138 {
139 #if LV_USE_BAR
140
141 theme.style.bar.bg = &lv_style_pretty;
142 theme.style.bar.indic = &lv_style_pretty_color;
143 #endif
144 }
145
slider_init(void)146 static void slider_init(void)
147 {
148 #if LV_USE_SLIDER != 0
149 static lv_style_t slider_bg;
150 lv_style_copy(&slider_bg, &lv_style_pretty);
151 slider_bg.body.padding.left = LV_DPI / 20;
152 slider_bg.body.padding.right = LV_DPI / 20;
153 slider_bg.body.padding.top = LV_DPI / 20;
154 slider_bg.body.padding.bottom = LV_DPI / 20;
155
156 theme.style.slider.bg = &slider_bg;
157 theme.style.slider.indic = &lv_style_pretty_color;
158 theme.style.slider.knob = &lv_style_pretty;
159 #endif
160 }
161
sw_init(void)162 static void sw_init(void)
163 {
164 #if LV_USE_SW != 0
165 static lv_style_t sw_bg;
166 lv_style_copy(&sw_bg, &lv_style_pretty);
167 sw_bg.body.padding.left = 3;
168 sw_bg.body.padding.right = 3;
169 sw_bg.body.padding.top = 3;
170 sw_bg.body.padding.bottom = 3;
171
172 theme.style.sw.bg = &sw_bg;
173 theme.style.sw.indic = &lv_style_pretty_color;
174 theme.style.sw.knob_off = &lv_style_pretty;
175 theme.style.sw.knob_on = &lv_style_pretty;
176 #endif
177 }
178
lmeter_init(void)179 static void lmeter_init(void)
180 {
181 #if LV_USE_LMETER != 0
182 static lv_style_t lmeter;
183 lv_style_copy(&lmeter, &lv_style_pretty_color);
184 lmeter.line.color = lv_color_hex3(0xddd);
185 lmeter.line.width = 2;
186 lmeter.body.main_color = lv_color_mix(lmeter.body.main_color, LV_COLOR_WHITE, LV_OPA_50);
187 lmeter.body.grad_color = lv_color_mix(lmeter.body.grad_color, LV_COLOR_BLACK, LV_OPA_50);
188
189 theme.style.lmeter = &lmeter;
190 #endif
191 }
192
gauge_init(void)193 static void gauge_init(void)
194 {
195 #if LV_USE_GAUGE != 0
196 static lv_style_t gauge;
197 lv_style_copy(&gauge, theme.style.lmeter);
198 gauge.line.color = theme.style.lmeter->body.grad_color;
199 gauge.line.width = 2;
200 gauge.body.main_color = lv_color_hex3(0x888);
201 gauge.body.grad_color = theme.style.lmeter->body.main_color;
202 gauge.text.color = lv_color_hex3(0x888);
203
204 theme.style.gauge = &gauge;
205 #endif
206 }
207
chart_init(void)208 static void chart_init(void)
209 {
210 #if LV_USE_CHART
211
212 theme.style.chart = &lv_style_pretty;
213 #endif
214 }
215
cb_init(void)216 static void cb_init(void)
217 {
218 #if LV_USE_CB != 0
219
220 theme.style.cb.bg = &lv_style_transp;
221 theme.style.cb.box.rel = &lv_style_pretty;
222 theme.style.cb.box.pr = &lv_style_btn_pr;
223 theme.style.cb.box.tgl_rel = &lv_style_btn_tgl_rel;
224 theme.style.cb.box.tgl_pr = &lv_style_btn_tgl_pr;
225 theme.style.cb.box.ina = &lv_style_btn_ina;
226 #endif
227 }
228
btnm_init(void)229 static void btnm_init(void)
230 {
231 #if LV_USE_BTNM
232
233 theme.style.btnm.bg = &lv_style_pretty;
234 theme.style.btnm.btn.rel = &lv_style_btn_rel;
235 theme.style.btnm.btn.pr = &lv_style_btn_pr;
236 theme.style.btnm.btn.tgl_rel = &lv_style_btn_tgl_rel;
237 theme.style.btnm.btn.tgl_pr = &lv_style_btn_tgl_pr;
238 theme.style.btnm.btn.ina = &lv_style_btn_ina;
239 #endif
240 }
241
kb_init(void)242 static void kb_init(void)
243 {
244 #if LV_USE_KB
245
246 theme.style.kb.bg = &lv_style_pretty;
247 theme.style.kb.btn.rel = &lv_style_btn_rel;
248 theme.style.kb.btn.pr = &lv_style_btn_pr;
249 theme.style.kb.btn.tgl_rel = &lv_style_btn_tgl_rel;
250 theme.style.kb.btn.tgl_pr = &lv_style_btn_tgl_pr;
251 theme.style.kb.btn.ina = &lv_style_btn_ina;
252 #endif
253 }
254
mbox_init(void)255 static void mbox_init(void)
256 {
257 #if LV_USE_MBOX
258
259 theme.style.mbox.bg = &lv_style_pretty;
260 theme.style.mbox.btn.bg = &lv_style_transp;
261 theme.style.mbox.btn.rel = &lv_style_btn_rel;
262 theme.style.mbox.btn.pr = &lv_style_btn_tgl_pr;
263 #endif
264 }
265
page_init(void)266 static void page_init(void)
267 {
268 #if LV_USE_PAGE
269
270 theme.style.page.bg = &lv_style_pretty;
271 theme.style.page.scrl = &lv_style_transp_tight;
272 theme.style.page.sb = &sb;
273 #endif
274 }
275
ta_init(void)276 static void ta_init(void)
277 {
278 #if LV_USE_TA
279
280 theme.style.ta.area = &lv_style_pretty;
281 theme.style.ta.oneline = &lv_style_pretty;
282 theme.style.ta.cursor = NULL;
283 theme.style.ta.sb = &sb;
284 #endif
285 }
286
list_init(void)287 static void list_init(void)
288 {
289 #if LV_USE_LIST != 0
290
291 theme.style.list.bg = &lv_style_pretty;
292 theme.style.list.scrl = &lv_style_transp_fit;
293 theme.style.list.sb = &sb;
294 theme.style.list.btn.rel = &lv_style_btn_rel;
295 theme.style.list.btn.pr = &lv_style_btn_pr;
296 theme.style.list.btn.tgl_rel = &lv_style_btn_tgl_rel;
297 theme.style.list.btn.tgl_pr = &lv_style_btn_tgl_pr;
298 theme.style.list.btn.ina = &lv_style_btn_ina;
299 #endif
300 }
301
ddlist_init(void)302 static void ddlist_init(void)
303 {
304 #if LV_USE_DDLIST != 0
305
306 theme.style.ddlist.bg = &lv_style_pretty;
307 theme.style.ddlist.sel = &lv_style_plain_color;
308 theme.style.ddlist.sb = &sb;
309 #endif
310 }
311
roller_init(void)312 static void roller_init(void)
313 {
314 #if LV_USE_ROLLER != 0
315
316 theme.style.roller.bg = &lv_style_pretty;
317 theme.style.roller.sel = &lv_style_plain_color;
318 #endif
319 }
320
tabview_init(void)321 static void tabview_init(void)
322 {
323 #if LV_USE_TABVIEW != 0
324
325 theme.style.tabview.bg = &plain_bordered;
326 theme.style.tabview.indic = &lv_style_plain_color;
327 theme.style.tabview.btn.bg = &lv_style_transp;
328 theme.style.tabview.btn.rel = &lv_style_btn_rel;
329 theme.style.tabview.btn.pr = &lv_style_btn_pr;
330 theme.style.tabview.btn.tgl_rel = &lv_style_btn_tgl_rel;
331 theme.style.tabview.btn.tgl_pr = &lv_style_btn_tgl_pr;
332 #endif
333 }
334
table_init(void)335 static void table_init(void)
336 {
337 #if LV_USE_TABLE != 0
338 theme.style.table.bg = &lv_style_transp_tight;
339 theme.style.table.cell = &lv_style_plain;
340 #endif
341 }
342
win_init(void)343 static void win_init(void)
344 {
345 #if LV_USE_WIN != 0
346
347 theme.style.win.bg = &plain_bordered;
348 theme.style.win.sb = &sb;
349 theme.style.win.header = &lv_style_plain_color;
350 theme.style.win.content = &lv_style_transp;
351 theme.style.win.btn.rel = &lv_style_btn_rel;
352 theme.style.win.btn.pr = &lv_style_btn_pr;
353 #endif
354 }
355
356 #if LV_USE_GROUP
357
style_mod(lv_group_t * group,lv_style_t * style)358 static void style_mod(lv_group_t * group, lv_style_t * style)
359 {
360 (void)group; /*Unused*/
361 #if LV_COLOR_DEPTH != 1
362 /*Make the style to be a little bit orange*/
363 style->body.border.opa = LV_OPA_COVER;
364 style->body.border.color = LV_COLOR_ORANGE;
365
366 /*If not empty or has border then emphasis the border*/
367 if(style->body.opa != LV_OPA_TRANSP || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
368
369 style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_ORANGE, LV_OPA_70);
370 style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_ORANGE, LV_OPA_70);
371 style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_ORANGE, LV_OPA_60);
372
373 style->text.color = lv_color_mix(style->text.color, LV_COLOR_ORANGE, LV_OPA_70);
374 #else
375 style->body.border.opa = LV_OPA_COVER;
376 style->body.border.color = LV_COLOR_BLACK;
377 style->body.border.width = 2;
378 #endif
379 }
380
style_mod_edit(lv_group_t * group,lv_style_t * style)381 static void style_mod_edit(lv_group_t * group, lv_style_t * style)
382 {
383 (void)group; /*Unused*/
384 #if LV_COLOR_DEPTH != 1
385 /*Make the style to be a little bit orange*/
386 style->body.border.opa = LV_OPA_COVER;
387 style->body.border.color = LV_COLOR_GREEN;
388
389 /*If not empty or has border then emphasis the border*/
390 if(style->body.opa != LV_OPA_TRANSP || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
391
392 style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70);
393 style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70);
394 style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60);
395
396 style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70);
397 #else
398 style->body.border.opa = LV_OPA_COVER;
399 style->body.border.color = LV_COLOR_BLACK;
400 style->body.border.width = 3;
401 #endif
402 }
403
404 #endif /*LV_USE_GROUP*/
405
406 /**********************
407 * GLOBAL FUNCTIONS
408 **********************/
409
410 /**
411 * Initialize the default theme
412 * @param hue [0..360] hue value from HSV color space to define the theme's base color
413 * @param font pointer to a font (NULL to use the default)
414 * @return pointer to the initialized theme
415 */
lv_theme_default_init(uint16_t hue,lv_font_t * font)416 lv_theme_t * lv_theme_default_init(uint16_t hue, lv_font_t * font)
417 {
418 if(font == NULL) font = LV_FONT_DEFAULT;
419
420 _hue = hue;
421 _font = font;
422
423 /*For backward compatibility initialize all theme elements with a default style */
424 uint16_t i;
425 lv_style_t ** style_p = (lv_style_t **)&theme.style;
426 for(i = 0; i < LV_THEME_STYLE_COUNT; i++) {
427 *style_p = &def;
428 style_p++;
429 }
430
431 basic_init();
432 btn_init();
433 label_init();
434 img_init();
435 line_init();
436 led_init();
437 bar_init();
438 slider_init();
439 sw_init();
440 lmeter_init();
441 gauge_init();
442 chart_init();
443 cb_init();
444 btnm_init();
445 kb_init();
446 mbox_init();
447 page_init();
448 ta_init();
449 list_init();
450 ddlist_init();
451 roller_init();
452 tabview_init();
453 table_init();
454 win_init();
455
456 #if LV_USE_GROUP
457 theme.group.style_mod_xcb = style_mod;
458 theme.group.style_mod_edit_xcb = style_mod_edit;
459 #endif
460
461 return &theme;
462 }
463
464 /**
465 * Get a pointer to the theme
466 * @return pointer to the theme
467 */
lv_theme_get_default(void)468 lv_theme_t * lv_theme_get_default(void)
469 {
470 return &theme;
471 }
472
473 /**********************
474 * STATIC FUNCTIONS
475 **********************/
476
477 #endif
478