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