1 /**
2 * @file lv_theme_material.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_theme.h"
10
11 #if LV_USE_THEME_MATERIAL
12
13 /*********************
14 * DEFINES
15 *********************/
16 #define DEF_RADIUS 4
17 #define DEF_SHADOW_COLOR lv_color_hex3(0xaaa)
18
19 /**********************
20 * TYPEDEFS
21 **********************/
22
23 /**********************
24 * STATIC PROTOTYPES
25 **********************/
26
27 /**********************
28 * STATIC VARIABLES
29 **********************/
30 static lv_theme_t theme;
31 static lv_style_t def;
32
33 /*Static style definitions*/
34 static lv_style_t sb;
35
36 /*Saved input parameters*/
37 static uint16_t _hue;
38 static lv_font_t * _font;
39
40 /**********************
41 * MACROS
42 **********************/
43
44 /**********************
45 * STATIC FUNCTIONS
46 **********************/
47
basic_init(void)48 static void basic_init(void)
49 {
50 static lv_style_t bg, panel, scr;
51
52 lv_style_copy(&def, &lv_style_plain); /*Initialize the default style*/
53 def.text.font = _font;
54 def.body.radius = DEF_RADIUS;
55
56 lv_style_copy(&bg, &def);
57 bg.body.main_color = lv_color_hex(0xf0f0f0);
58 bg.body.grad_color = bg.body.main_color;
59 bg.body.radius = 0;
60
61 lv_style_copy(&scr, &bg);
62 scr.body.padding.bottom = 0;
63 scr.body.padding.top = 0;
64 scr.body.padding.left = 0;
65 scr.body.padding.right = 0;
66
67 lv_style_copy(&panel, &def);
68 panel.body.radius = DEF_RADIUS;
69 panel.body.main_color = LV_COLOR_WHITE;
70 panel.body.grad_color = LV_COLOR_WHITE;
71 panel.body.border.width = 1;
72 panel.body.border.color = lv_color_hex3(0xbbb);
73 panel.body.border.opa = LV_OPA_COVER;
74 panel.body.shadow.color = DEF_SHADOW_COLOR;
75 panel.body.shadow.type = LV_SHADOW_BOTTOM;
76 panel.body.shadow.width = 4;
77 panel.body.padding.left = LV_DPI / 8;
78 panel.body.padding.right = LV_DPI / 8;
79 panel.body.padding.top = LV_DPI / 8;
80 panel.body.padding.bottom = LV_DPI / 8;
81 panel.body.padding.inner = LV_DPI / 12;
82 panel.text.color = lv_color_hex3(0x333);
83 panel.image.color = lv_color_hex3(0x333);
84
85 lv_style_copy(&sb, &def);
86 sb.body.main_color = LV_COLOR_BLACK;
87 sb.body.grad_color = LV_COLOR_BLACK;
88 sb.body.opa = LV_OPA_40;
89 sb.body.padding.right = LV_DPI / 25;
90 sb.body.padding.bottom = LV_DPI / 25;
91
92 theme.style.bg = &bg;
93 theme.style.scr = &scr;
94 theme.style.panel = &panel;
95 }
96
cont_init(void)97 static void cont_init(void)
98 {
99 #if LV_USE_CONT != 0
100
101 theme.style.cont = theme.style.panel;
102 #endif
103 }
104
btn_init(void)105 static void btn_init(void)
106 {
107 #if LV_USE_BTN != 0
108 static lv_style_t rel, pr, tgl_rel, tgl_pr, ina;
109
110 lv_style_copy(&rel, &def);
111 rel.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70);
112 rel.body.grad_color = rel.body.main_color;
113 rel.body.radius = DEF_RADIUS;
114 rel.body.padding.left = LV_DPI / 6;
115 rel.body.padding.right = LV_DPI / 6;
116 rel.body.padding.top = LV_DPI / 8;
117 rel.body.padding.bottom = LV_DPI / 8;
118 rel.body.padding.inner = LV_DPI / 10;
119 rel.body.shadow.color = DEF_SHADOW_COLOR;
120 rel.body.shadow.type = LV_SHADOW_BOTTOM;
121 rel.body.shadow.width = 6;
122 rel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95);
123 rel.image.color = lv_color_hsv_to_rgb(_hue, 5, 95);
124
125 lv_style_copy(&pr, &rel);
126 pr.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 60);
127 pr.body.grad_color = pr.body.main_color;
128 pr.body.shadow.width = 4;
129
130 lv_style_copy(&tgl_rel, &rel);
131 tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 95, 50);
132 tgl_rel.body.grad_color = tgl_rel.body.main_color;
133 tgl_rel.body.shadow.width = 4;
134
135 lv_style_copy(&tgl_pr, &tgl_rel);
136 tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 95, 40);
137 tgl_pr.body.grad_color = tgl_pr.body.main_color;
138 tgl_pr.body.shadow.width = 2;
139
140 lv_style_copy(&ina, &rel);
141 ina.body.main_color = lv_color_hex3(0xccc);
142 ina.body.grad_color = ina.body.main_color;
143 ina.body.shadow.width = 0;
144 ina.text.color = lv_color_hsv_to_rgb(_hue, 95, 5);
145 ina.image.color = lv_color_hsv_to_rgb(_hue, 95, 5);
146
147 theme.style.btn.rel = &rel;
148 theme.style.btn.pr = ≺
149 theme.style.btn.tgl_rel = &tgl_rel;
150 theme.style.btn.tgl_pr = &tgl_pr;
151 theme.style.btn.ina = &ina;
152 #endif
153 }
154
label_init(void)155 static void label_init(void)
156 {
157 #if LV_USE_LABEL != 0
158 static lv_style_t prim, sec, hint;
159
160 lv_style_copy(&prim, &def);
161 prim.text.font = _font;
162 prim.text.color = lv_color_hsv_to_rgb(_hue, 80, 10);
163
164 lv_style_copy(&sec, &prim);
165 sec.text.color = lv_color_hsv_to_rgb(_hue, 80, 75);
166
167 lv_style_copy(&hint, &prim);
168 hint.text.color = lv_color_hsv_to_rgb(_hue, 40, 90);
169
170 theme.style.label.prim = &prim;
171 theme.style.label.sec = &sec;
172 theme.style.label.hint = &hint;
173 #endif
174 }
175
img_init(void)176 static void img_init(void)
177 {
178 #if LV_USE_IMG != 0
179 static lv_style_t img_light, img_dark;
180 lv_style_copy(&img_light, &def);
181 img_light.image.color = lv_color_hsv_to_rgb(_hue, 15, 85);
182 img_light.image.intense = LV_OPA_80;
183
184 lv_style_copy(&img_dark, &def);
185 img_light.image.color = lv_color_hsv_to_rgb(_hue, 85, 65);
186 img_light.image.intense = LV_OPA_80;
187
188 theme.style.img.light = &def;
189 theme.style.img.dark = &def;
190 #endif
191 }
192
line_init(void)193 static void line_init(void)
194 {
195 #if LV_USE_LINE != 0
196
197 theme.style.line.decor = &def;
198 #endif
199 }
200
led_init(void)201 static void led_init(void)
202 {
203 #if LV_USE_LED != 0
204 static lv_style_t led;
205 lv_style_copy(&led, &def);
206 led.body.shadow.width = LV_DPI / 10;
207 led.body.radius = LV_RADIUS_CIRCLE;
208 led.body.border.width = LV_DPI / 30;
209 led.body.border.opa = LV_OPA_30;
210 led.body.main_color = lv_color_hsv_to_rgb(_hue, 100, 100);
211 led.body.grad_color = lv_color_hsv_to_rgb(_hue, 100, 100);
212 led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60);
213 led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100);
214
215 theme.style.led = &led;
216 #endif
217 }
218
bar_init(void)219 static void bar_init(void)
220 {
221 #if LV_USE_BAR
222 static lv_style_t bar_bg, bar_indic;
223
224 lv_style_copy(&bar_bg, &def);
225 bar_bg.body.main_color = lv_color_hsv_to_rgb(_hue, 15, 95);
226 bar_bg.body.grad_color = bar_bg.body.main_color;
227 bar_bg.body.radius = 3;
228 bar_bg.body.border.width = 0;
229 bar_bg.body.padding.left = LV_DPI / 16;
230 bar_bg.body.padding.right = LV_DPI / 16;
231 bar_bg.body.padding.top = LV_DPI / 16;
232 bar_bg.body.padding.bottom = LV_DPI / 16;
233
234 lv_style_copy(&bar_indic, &bar_bg);
235 bar_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 85, 70);
236 bar_indic.body.grad_color = bar_indic.body.main_color;
237 bar_indic.body.padding.left = 0;
238 bar_indic.body.padding.right = 0;
239 bar_indic.body.padding.top = 0;
240 bar_indic.body.padding.bottom = 0;
241
242 theme.style.bar.bg = &bar_bg;
243 theme.style.bar.indic = &bar_indic;
244 #endif
245 }
246
slider_init(void)247 static void slider_init(void)
248 {
249 #if LV_USE_SLIDER != 0
250 static lv_style_t knob;
251
252 lv_style_copy(&knob, &def);
253 knob.body.radius = LV_RADIUS_CIRCLE;
254 knob.body.border.width = 0;
255 knob.body.main_color = theme.style.bar.indic->body.main_color;
256 knob.body.grad_color = knob.body.main_color;
257
258 theme.style.slider.bg = theme.style.bar.bg;
259 theme.style.slider.indic = theme.style.bar.indic;
260 theme.style.slider.knob = &knob;
261 #endif
262 }
263
sw_init(void)264 static void sw_init(void)
265 {
266 #if LV_USE_SW != 0
267 static lv_style_t sw_bg, sw_indic, sw_knob_off, sw_knob_on;
268 lv_style_copy(&sw_bg, theme.style.slider.bg);
269 sw_bg.body.radius = LV_RADIUS_CIRCLE;
270
271 lv_style_copy(&sw_indic, theme.style.slider.bg);
272 sw_indic.body.radius = LV_RADIUS_CIRCLE;
273
274 lv_style_copy(&sw_knob_on, theme.style.slider.knob);
275 sw_knob_on.body.shadow.width = 3;
276 sw_knob_on.body.shadow.type = LV_SHADOW_BOTTOM;
277 sw_knob_on.body.shadow.color = DEF_SHADOW_COLOR;
278
279 lv_style_copy(&sw_knob_off, &sw_knob_on);
280 sw_knob_off.body.main_color = lv_color_hex(0xfafafa);
281 sw_knob_off.body.grad_color = sw_knob_off.body.main_color;
282 sw_knob_off.body.border.width = 1;
283 sw_knob_off.body.border.color = lv_color_hex3(0x999);
284 sw_knob_off.body.border.opa = LV_OPA_COVER;
285
286 theme.style.sw.bg = &sw_bg;
287 theme.style.sw.indic = &sw_indic;
288 theme.style.sw.knob_off = &sw_knob_off;
289 theme.style.sw.knob_on = &sw_knob_on;
290 #endif
291 }
292
lmeter_init(void)293 static void lmeter_init(void)
294 {
295 #if LV_USE_LMETER != 0
296 static lv_style_t lmeter;
297 lv_style_copy(&lmeter, &def);
298 lmeter.body.main_color = lv_color_hsv_to_rgb(_hue, 75, 90);
299 lmeter.body.grad_color = lmeter.body.main_color;
300 lmeter.body.padding.left = LV_DPI / 10; /*Scale line length*/
301 lmeter.line.color = lv_color_hex3(0x999);
302 lmeter.line.width = 2;
303
304 theme.style.lmeter = &lmeter;
305 #endif
306 }
307
gauge_init(void)308 static void gauge_init(void)
309 {
310 #if LV_USE_GAUGE != 0
311
312 static lv_style_t gauge;
313 lv_style_copy(&gauge, &def);
314 gauge.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 60);
315 gauge.body.grad_color = gauge.body.main_color;
316 gauge.body.padding.left = LV_DPI / 16; /*Scale line length*/
317 gauge.body.padding.inner = LV_DPI / 8;
318 gauge.body.border.color = lv_color_hex3(0x999);
319 gauge.text.color = lv_color_hex3(0x333);
320 gauge.line.width = 3;
321 gauge.line.color = lv_color_hsv_to_rgb(_hue, 95, 70);
322
323 theme.style.gauge = &gauge;
324 #endif
325 }
326
arc_init(void)327 static void arc_init(void)
328 {
329 #if LV_USE_ARC != 0
330
331 static lv_style_t arc;
332 lv_style_copy(&arc, &def);
333 arc.line.width = 10;
334 arc.line.color = lv_color_hsv_to_rgb(_hue, 90, 90);
335
336 /*For prelaoder*/
337 arc.body.border.width = 10;
338 arc.body.border.color = lv_color_hsv_to_rgb(_hue, 30, 90);
339 arc.body.padding.left = 0;
340 arc.body.padding.right = 0;
341 arc.body.padding.top = 0;
342 arc.body.padding.bottom = 0;
343
344 theme.style.arc = &arc;
345 #endif
346 }
347
preload_init(void)348 static void preload_init(void)
349 {
350 #if LV_USE_PRELOAD != 0
351
352 theme.style.preload = theme.style.arc;
353 #endif
354 }
355
chart_init(void)356 static void chart_init(void)
357 {
358 #if LV_USE_CHART
359 theme.style.chart = theme.style.panel;
360 #endif
361 }
362
calendar_init(void)363 static void calendar_init(void)
364 {
365 #if LV_USE_CALENDAR
366 static lv_style_t ina_days;
367 lv_style_copy(&ina_days, &def);
368 ina_days.text.color = lv_color_hsv_to_rgb(_hue, 0, 70);
369
370 static lv_style_t high_days;
371 lv_style_copy(&high_days, &def);
372 high_days.text.color = lv_color_hsv_to_rgb(_hue, 80, 90);
373
374 static lv_style_t week_box;
375 lv_style_copy(&week_box, &def);
376 week_box.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 100);
377 week_box.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 100);
378 week_box.body.padding.top = LV_DPI / 20;
379 week_box.body.padding.bottom = LV_DPI / 20;
380 week_box.body.padding.left = theme.style.panel->body.padding.left;
381 week_box.body.padding.right = theme.style.panel->body.padding.right;
382 week_box.body.border.color = theme.style.panel->body.border.color;
383 week_box.body.border.width = theme.style.panel->body.border.width;
384 week_box.body.border.part = LV_BORDER_LEFT | LV_BORDER_RIGHT;
385 week_box.body.radius = 0;
386
387 static lv_style_t today_box;
388 lv_style_copy(&today_box, &def);
389 today_box.body.main_color = LV_COLOR_WHITE;
390 today_box.body.grad_color = LV_COLOR_WHITE;
391 today_box.body.padding.top = LV_DPI / 20;
392 today_box.body.padding.bottom = LV_DPI / 20;
393 today_box.body.radius = 0;
394
395 theme.style.calendar.bg = theme.style.panel;
396 theme.style.calendar.header = &lv_style_transp;
397 theme.style.calendar.inactive_days = &ina_days;
398 theme.style.calendar.highlighted_days = &high_days;
399 theme.style.calendar.week_box = &week_box;
400 theme.style.calendar.today_box = &today_box;
401 #endif
402 }
403
cb_init(void)404 static void cb_init(void)
405 {
406 #if LV_USE_CB != 0
407 static lv_style_t rel, pr, tgl_rel, tgl_pr, ina;
408 lv_style_copy(&rel, theme.style.panel);
409 rel.body.shadow.type = LV_SHADOW_BOTTOM;
410 rel.body.shadow.width = 3;
411
412 lv_style_copy(&pr, &rel);
413 pr.body.main_color = lv_color_hex3(0xccc);
414 pr.body.grad_color = pr.body.main_color;
415 pr.body.shadow.width = 0;
416
417 lv_style_copy(&tgl_rel, &rel);
418 tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 75, 85);
419 tgl_rel.body.grad_color = tgl_rel.body.main_color;
420 tgl_rel.body.shadow.type = LV_SHADOW_FULL;
421 tgl_rel.body.shadow.width = 0;
422
423 lv_style_copy(&tgl_pr, &tgl_rel);
424 tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 75, 65);
425 tgl_pr.body.grad_color = tgl_pr.body.main_color;
426 tgl_pr.body.shadow.width = 0;
427
428 lv_style_copy(&ina, theme.style.btn.ina);
429
430 theme.style.cb.bg = &lv_style_transp;
431 theme.style.cb.box.rel = &rel;
432 theme.style.cb.box.pr = ≺
433 theme.style.cb.box.tgl_rel = &tgl_rel;
434 theme.style.cb.box.tgl_pr = &tgl_pr;
435 theme.style.cb.box.ina = &ina;
436 #endif
437 }
438
btnm_init(void)439 static void btnm_init(void)
440 {
441 #if LV_USE_BTNM
442 static lv_style_t bg, rel, pr, tgl_rel, tgl_pr, ina;
443
444 lv_style_copy(&bg, theme.style.panel);
445 bg.body.padding.left = 0;
446 bg.body.padding.right = 0;
447 bg.body.padding.top = 0;
448 bg.body.padding.bottom = 0;
449 bg.body.padding.inner = 0;
450 bg.text.color = lv_color_hex3(0x555);
451
452 lv_style_copy(&rel, theme.style.panel);
453 rel.body.border.part = LV_BORDER_FULL | LV_BORDER_INTERNAL;
454 rel.body.border.width = 1;
455 rel.body.border.color = lv_color_hex3(0xbbb);
456 rel.body.opa = LV_OPA_TRANSP;
457 rel.body.shadow.width = 0;
458
459 lv_style_copy(&pr, &rel);
460 pr.glass = 0;
461 pr.body.main_color = lv_color_hex3(0xddd);
462 pr.body.grad_color = pr.body.main_color;
463 pr.body.border.width = 0;
464 pr.body.opa = LV_OPA_COVER;
465
466 lv_style_copy(&tgl_rel, &pr);
467 tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70);
468 tgl_rel.body.grad_color = tgl_rel.body.main_color;
469 tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95);
470
471 lv_style_copy(&tgl_pr, &tgl_rel);
472 tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 95, 65);
473 tgl_pr.body.grad_color = tgl_pr.body.main_color;
474 tgl_pr.body.border.width = 0;
475
476 lv_style_copy(&ina, &pr);
477 ina.body.main_color = lv_color_hex3(0xccc);
478 ina.body.grad_color = ina.body.main_color;
479
480 theme.style.btnm.bg = &bg;
481 theme.style.btnm.btn.rel = &rel;
482 theme.style.btnm.btn.pr = ≺
483 theme.style.btnm.btn.tgl_rel = &tgl_rel;
484 theme.style.btnm.btn.tgl_pr = &tgl_pr;
485 theme.style.btnm.btn.ina = &def;
486 #endif
487 }
488
kb_init(void)489 static void kb_init(void)
490 {
491 #if LV_USE_KB
492
493 static lv_style_t rel;
494 lv_style_copy(&rel, &lv_style_transp);
495 rel.text.font = _font;
496
497 theme.style.kb.bg = theme.style.btnm.bg;
498 theme.style.kb.btn.rel = &rel;
499 theme.style.kb.btn.pr = theme.style.btnm.btn.pr;
500 theme.style.kb.btn.tgl_rel = theme.style.btnm.btn.tgl_rel;
501 theme.style.kb.btn.tgl_pr = theme.style.btnm.btn.tgl_pr;
502 theme.style.kb.btn.ina = theme.style.btnm.btn.ina;
503 #endif
504 }
505
mbox_init(void)506 static void mbox_init(void)
507 {
508 #if LV_USE_MBOX
509 static lv_style_t pr, rel;
510
511 lv_style_copy(&rel, &lv_style_transp);
512 rel.glass = 0;
513 rel.text.font = _font;
514 rel.text.color = lv_color_hsv_to_rgb(_hue, 85, 75);
515
516 lv_style_copy(&pr, theme.style.btnm.btn.pr);
517 pr.text.color = lv_color_hsv_to_rgb(_hue, 85, 60);
518
519 theme.style.mbox.bg = theme.style.panel;
520 theme.style.mbox.btn.bg = &lv_style_transp;
521 theme.style.mbox.btn.rel = &rel;
522 theme.style.mbox.btn.pr = ≺
523 #endif
524 }
525
page_init(void)526 static void page_init(void)
527 {
528 #if LV_USE_PAGE
529
530 theme.style.page.bg = theme.style.panel;
531 theme.style.page.scrl = &lv_style_transp;
532 theme.style.page.sb = &sb;
533 #endif
534 }
535
ta_init(void)536 static void ta_init(void)
537 {
538 #if LV_USE_TA
539 static lv_style_t oneline;
540
541 lv_style_copy(&oneline, &def);
542 oneline.body.opa = LV_OPA_TRANSP;
543 oneline.body.radius = 0;
544 oneline.body.border.part = LV_BORDER_BOTTOM;
545 oneline.body.border.width = 3;
546 oneline.body.border.color = lv_color_hex3(0x333);
547 oneline.body.border.opa = LV_OPA_COVER;
548 oneline.text.color = lv_color_hex3(0x333);
549
550 theme.style.ta.area = theme.style.panel;
551 theme.style.ta.oneline = &oneline;
552 theme.style.ta.cursor = NULL; /*Let library to calculate the cursor's style*/
553 theme.style.ta.sb = &sb;
554 #endif
555 }
556
spinbox_init(void)557 static void spinbox_init(void)
558 {
559 #if LV_USE_SPINBOX
560 theme.style.spinbox.bg = theme.style.panel;
561 theme.style.spinbox.cursor = theme.style.ta.cursor;
562 theme.style.spinbox.sb = theme.style.ta.sb;
563 #endif
564 }
565
list_init(void)566 static void list_init(void)
567 {
568 #if LV_USE_LIST != 0
569
570 static lv_style_t list_bg, rel, pr, tgl_rel, tgl_pr, ina;
571
572 lv_style_copy(&list_bg, theme.style.panel);
573 list_bg.body.padding.left = 0;
574 list_bg.body.padding.right = 0;
575 list_bg.body.padding.top = 0;
576 list_bg.body.padding.bottom = 0;
577 list_bg.body.padding.inner = 0;
578
579 lv_style_copy(&rel, &lv_style_transp);
580 rel.body.padding.left = LV_DPI / 8;
581 rel.body.padding.right = LV_DPI / 8;
582 rel.body.padding.top = LV_DPI / 6;
583 rel.body.padding.bottom = LV_DPI / 6;
584 rel.body.radius = 10;
585 rel.body.border.color = lv_color_hex3(0xbbb);
586 rel.body.border.width = 1;
587 rel.body.border.part = LV_BORDER_BOTTOM;
588
589 lv_style_copy(&pr, &rel);
590 pr.glass = 0;
591 pr.body.main_color = lv_color_hex3(0xddd);
592 pr.body.grad_color = pr.body.main_color;
593 pr.body.border.width = 0;
594 pr.body.opa = LV_OPA_COVER;
595 pr.body.radius = DEF_RADIUS;
596 pr.text.font = _font;
597
598 lv_style_copy(&tgl_rel, &pr);
599 tgl_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70);
600 tgl_rel.body.grad_color = tgl_rel.body.main_color;
601 tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95);
602
603 lv_style_copy(&tgl_pr, &tgl_rel);
604 tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 60);
605 tgl_pr.body.grad_color = tgl_pr.body.main_color;
606 tgl_pr.body.border.width = 0;
607
608 lv_style_copy(&ina, &pr);
609 ina.body.main_color = lv_color_hex3(0xccc);
610 ina.body.grad_color = ina.body.main_color;
611
612 theme.style.list.sb = &sb;
613 theme.style.list.bg = &list_bg;
614 theme.style.list.scrl = &lv_style_transp_tight;
615 theme.style.list.btn.rel = &rel;
616 theme.style.list.btn.pr = ≺
617 theme.style.list.btn.tgl_rel = &tgl_rel;
618 theme.style.list.btn.tgl_pr = &tgl_pr;
619 theme.style.list.btn.ina = &ina;
620 #endif
621 }
622
ddlist_init(void)623 static void ddlist_init(void)
624 {
625 #if LV_USE_DDLIST != 0
626 static lv_style_t bg, sel;
627 lv_style_copy(&bg, theme.style.panel);
628 bg.body.padding.left = LV_DPI / 6;
629 bg.body.padding.right = LV_DPI / 6;
630 bg.body.padding.top = LV_DPI / 6;
631 bg.body.padding.bottom = LV_DPI / 6;
632 bg.text.line_space = LV_DPI / 8;
633
634 lv_style_copy(&sel, &bg);
635 sel.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70);
636 sel.body.grad_color = sel.body.main_color;
637 sel.body.border.width = 0;
638 sel.body.shadow.width = 0;
639 sel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95);
640
641 theme.style.ddlist.bg = &bg;
642 theme.style.ddlist.sel = &sel;
643 theme.style.ddlist.sb = &sb;
644 #endif
645 }
646
roller_init(void)647 static void roller_init(void)
648 {
649 #if LV_USE_ROLLER != 0
650 static lv_style_t roller_bg, roller_sel;
651
652 lv_style_copy(&roller_bg, &lv_style_transp);
653 roller_bg.body.padding.left = LV_DPI / 6;
654 roller_bg.body.padding.right = LV_DPI / 6;
655 roller_bg.body.padding.top = LV_DPI / 6;
656 roller_bg.body.padding.bottom = LV_DPI / 6;
657 roller_bg.text.line_space = LV_DPI / 8;
658 roller_bg.text.font = _font;
659 roller_bg.glass = 0;
660
661 lv_style_copy(&roller_sel, &roller_bg);
662 roller_sel.text.color = lv_color_hsv_to_rgb(_hue, 90, 70);
663
664 theme.style.roller.bg = &roller_bg;
665 theme.style.roller.sel = &roller_sel;
666 #endif
667 }
668
tabview_init(void)669 static void tabview_init(void)
670 {
671 #if LV_USE_TABVIEW != 0
672 static lv_style_t indic, btn_bg, rel, pr, tgl_rel, tgl_pr;
673
674 lv_style_copy(&indic, &def);
675 indic.body.main_color = lv_color_hsv_to_rgb(_hue, 90, 70);
676 indic.body.grad_color = indic.body.main_color;
677 indic.body.radius = 0;
678 indic.body.border.width = 0;
679 indic.body.padding.inner = LV_DPI / 20;
680
681 lv_style_copy(&btn_bg, &def);
682 btn_bg.body.main_color = lv_color_hex3(0xccc);
683 btn_bg.body.grad_color = btn_bg.body.main_color;
684 btn_bg.body.radius = 0;
685 btn_bg.body.border.width = 1;
686 btn_bg.body.border.color = lv_color_hex3(0x888);
687 btn_bg.body.border.part = LV_BORDER_BOTTOM;
688 btn_bg.body.border.opa = LV_OPA_COVER;
689 btn_bg.body.shadow.width = 5;
690 btn_bg.body.shadow.color = DEF_SHADOW_COLOR;
691 btn_bg.body.shadow.type = LV_SHADOW_BOTTOM;
692 btn_bg.body.padding.inner = 0;
693 btn_bg.body.padding.left = 0;
694 btn_bg.body.padding.right = 0;
695 btn_bg.body.padding.top = 0;
696 btn_bg.body.padding.bottom = 0;
697 btn_bg.text.color = lv_color_hex3(0x333);
698
699 lv_style_copy(&rel, &lv_style_transp);
700 rel.body.padding.top = LV_DPI / 8;
701 rel.body.padding.bottom = LV_DPI / 8;
702 rel.text.font = _font;
703
704 lv_style_copy(&pr, &def);
705 pr.body.main_color = lv_color_hex3(0xbbb);
706 pr.body.grad_color = pr.body.main_color;
707 pr.body.border.width = 0;
708 pr.body.opa = LV_OPA_COVER;
709 pr.body.radius = 0;
710 pr.body.border.width = 1;
711 pr.body.border.color = lv_color_hex3(0x888);
712 pr.body.border.part = LV_BORDER_BOTTOM;
713 pr.body.border.opa = LV_OPA_COVER;
714 pr.text.color = lv_color_hex3(0x111);
715
716 lv_style_copy(&tgl_rel, &lv_style_transp);
717 tgl_rel.glass = 0;
718 tgl_rel.text.font = _font;
719 tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 90, 70);
720
721 lv_style_copy(&tgl_pr, &def);
722 tgl_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 15, 85);
723 tgl_pr.body.grad_color = tgl_pr.body.main_color;
724 tgl_pr.body.border.width = 0;
725 tgl_pr.body.opa = LV_OPA_COVER;
726 tgl_pr.body.radius = 0;
727 tgl_pr.text.color = lv_color_hsv_to_rgb(_hue, 90, 60);
728
729 theme.style.tabview.bg = theme.style.bg;
730 theme.style.tabview.indic = &indic;
731 theme.style.tabview.btn.bg = &btn_bg;
732 theme.style.tabview.btn.rel = &rel;
733 theme.style.tabview.btn.pr = ≺
734 theme.style.tabview.btn.tgl_rel = &tgl_rel;
735 theme.style.tabview.btn.tgl_pr = &tgl_pr;
736 #endif
737 }
738
tileview_init(void)739 static void tileview_init(void)
740 {
741 #if LV_USE_TILEVIEW != 0
742 theme.style.tileview.bg = &lv_style_transp_tight;
743 theme.style.tileview.scrl = &lv_style_transp_tight;
744 theme.style.tileview.sb = theme.style.page.sb;
745 #endif
746 }
747
table_init(void)748 static void table_init(void)
749 {
750 #if LV_USE_TABLE != 0
751 static lv_style_t cell;
752 lv_style_copy(&cell, theme.style.panel);
753 cell.body.radius = 0;
754 cell.body.border.width = 1;
755 cell.body.padding.left = LV_DPI / 12;
756 cell.body.padding.right = LV_DPI / 12;
757 cell.body.padding.top = LV_DPI / 12;
758 cell.body.padding.bottom = LV_DPI / 12;
759
760 theme.style.table.bg = &lv_style_transp_tight;
761 theme.style.table.cell = &cell;
762 #endif
763 }
764
win_init(void)765 static void win_init(void)
766 {
767 #if LV_USE_WIN != 0
768 static lv_style_t header, pr;
769
770 lv_style_copy(&header, &def);
771 header.body.main_color = lv_color_hex3(0xccc);
772 header.body.grad_color = header.body.main_color;
773 header.body.radius = 0;
774 header.body.border.width = 1;
775 header.body.border.color = lv_color_hex3(0xbbb);
776 header.body.border.part = LV_BORDER_BOTTOM;
777 header.body.border.opa = LV_OPA_COVER;
778 header.body.padding.inner = 0;
779 header.body.padding.left = 0;
780 header.body.padding.right = 0;
781 header.body.padding.top = 0;
782 header.body.padding.bottom = 0;
783 header.text.color = lv_color_hex3(0x333);
784 header.image.color = lv_color_hex3(0x333);
785
786 lv_style_copy(&pr, &def);
787 pr.body.main_color = lv_color_hex3(0xbbb);
788 pr.body.grad_color = pr.body.main_color;
789 pr.body.border.width = 0;
790 pr.body.opa = LV_OPA_COVER;
791 pr.body.radius = 0;
792 pr.text.color = lv_color_hex3(0x111);
793 pr.image.color = lv_color_hex3(0x111);
794
795 theme.style.win.bg = theme.style.panel;
796 theme.style.win.sb = &sb;
797 theme.style.win.header = &header;
798 theme.style.win.content = &lv_style_transp;
799 theme.style.win.btn.rel = &lv_style_transp;
800 theme.style.win.btn.pr = ≺
801 #endif
802 }
803
804 #if LV_USE_GROUP
805
style_mod(lv_group_t * group,lv_style_t * style)806 static void style_mod(lv_group_t * group, lv_style_t * style)
807 {
808 (void)group; /*Unused*/
809 #if LV_COLOR_DEPTH != 1
810 uint16_t hue2 = (_hue + 60) % 360;
811
812 /*Make the style to be a little bit orange*/
813 style->body.border.opa = LV_OPA_COVER;
814 style->body.border.color = lv_color_hsv_to_rgb(hue2, 90, 70);
815
816 /*If not empty or has border then emphasis the border*/
817 if(style->body.opa != LV_OPA_TRANSP || style->body.border.width != 0) style->body.border.width = LV_DPI / 30;
818
819 style->body.main_color = lv_color_mix(style->body.main_color, lv_color_hsv_to_rgb(hue2, 90, 70), LV_OPA_70);
820 style->body.grad_color = lv_color_mix(style->body.grad_color, lv_color_hsv_to_rgb(hue2, 90, 70), LV_OPA_70);
821 style->body.shadow.color = lv_color_mix(style->body.shadow.color, lv_color_hsv_to_rgb(hue2, 90, 70), LV_OPA_60);
822
823 style->text.color = lv_color_mix(style->text.color, lv_color_hsv_to_rgb(hue2, 90, 70), LV_OPA_70);
824 #else
825 style->body.border.opa = LV_OPA_COVER;
826 style->body.border.color = LV_COLOR_BLACK;
827 style->body.border.width = 2;
828 #endif
829 }
830
style_mod_edit(lv_group_t * group,lv_style_t * style)831 static void style_mod_edit(lv_group_t * group, lv_style_t * style)
832 {
833 (void)group; /*Unused*/
834 #if LV_COLOR_DEPTH != 1
835 uint16_t hue2 = (_hue + 300) % 360;
836
837 /*Make the style to be a little bit orange*/
838 style->body.border.opa = LV_OPA_COVER;
839 style->body.border.color = LV_COLOR_GREEN;
840
841 /*If not empty or has border then emphasis the border*/
842 if(style->body.opa != LV_OPA_TRANSP || style->body.border.width != 0) style->body.border.width = LV_DPI / 30;
843
844
845 style->body.main_color = lv_color_mix(style->body.main_color, lv_color_hsv_to_rgb(hue2, 90, 70), LV_OPA_70);
846 style->body.grad_color = lv_color_mix(style->body.grad_color, lv_color_hsv_to_rgb(hue2, 90, 70), LV_OPA_70);
847 style->body.shadow.color = lv_color_mix(style->body.shadow.color, lv_color_hsv_to_rgb(hue2, 90, 70), LV_OPA_60);
848
849 style->text.color = lv_color_mix(style->text.color, lv_color_hsv_to_rgb(hue2, 90, 70), LV_OPA_70);
850 #else
851 style->body.border.opa = LV_OPA_COVER;
852 style->body.border.color = LV_COLOR_BLACK;
853 style->body.border.width = 3;
854 #endif
855 }
856
857 #endif /*LV_USE_GROUP*/
858
859 /**********************
860 * GLOBAL FUNCTIONS
861 **********************/
862
863 /**
864 * Initialize the material theme
865 * @param hue [0..360] hue value from HSV color space to define the theme's base color
866 * @param font pointer to a font (NULL to use the default)
867 * @return pointer to the initialized theme
868 */
lv_theme_material_init(uint16_t hue,lv_font_t * font)869 lv_theme_t * lv_theme_material_init(uint16_t hue, lv_font_t * font)
870 {
871 if(font == NULL) font = LV_FONT_DEFAULT;
872
873 _hue = hue;
874 _font = font;
875
876 /*For backward compatibility initialize all theme elements with a default style */
877 uint16_t i;
878 lv_style_t ** style_p = (lv_style_t **)&theme.style;
879 for(i = 0; i < LV_THEME_STYLE_COUNT; i++) {
880 *style_p = &def;
881 style_p++;
882 }
883
884 basic_init();
885 cont_init();
886 btn_init();
887 label_init();
888 img_init();
889 line_init();
890 led_init();
891 bar_init();
892 slider_init();
893 sw_init();
894 lmeter_init();
895 gauge_init();
896 chart_init();
897 arc_init();
898 preload_init();
899 calendar_init();
900 cb_init();
901 btnm_init();
902 kb_init();
903 mbox_init();
904 page_init();
905 ta_init();
906 spinbox_init();
907 list_init();
908 ddlist_init();
909 roller_init();
910 tabview_init();
911 tileview_init();
912 table_init();
913 win_init();
914
915 #if LV_USE_GROUP
916 theme.group.style_mod_xcb = style_mod;
917 theme.group.style_mod_edit_xcb = style_mod_edit;
918 #endif
919
920 return &theme;
921 }
922
923 /**
924 * Get a pointer to the theme
925 * @return pointer to the theme
926 */
lv_theme_get_material(void)927 lv_theme_t * lv_theme_get_material(void)
928 {
929 return &theme;
930 }
931
932 /**********************
933 * STATIC FUNCTIONS
934 **********************/
935
936 #endif
937