1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/lv_themes/lv_theme_templ.c

493 lines
9.2 KiB
C
Raw Normal View History

/**
2017-11-18 00:17:21 +01:00
* @file lv_theme_templ.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_theme.h"
2017-11-18 00:17:21 +01:00
#if USE_LV_THEME_TEMPL
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_theme_t theme;
static lv_style_t def;
/*Static style definitions*/
/*Saved input parameters*/
static uint16_t _hue;
2017-11-23 21:28:36 +01:00
static lv_font_t * _font;
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
static void basic_init(void)
{
lv_style_copy(&def, &lv_style_pretty); /*Initialize the default style*/
2017-12-19 22:00:32 +01:00
def.text.font = _font;
theme.style.bg = &def;
theme.style.panel = &def;
}
2017-11-22 23:04:02 +01:00
static void cont_init(void)
{
#if USE_LV_CONT != 0
theme.style.cont = &def;
2017-11-22 23:04:02 +01:00
#endif
}
static void btn_init(void)
{
#if USE_LV_BTN != 0
theme.style.btn.rel = &def;
theme.style.btn.pr = &def;
theme.style.btn.tgl_rel = &def;
theme.style.btn.tgl_pr = &def;
theme.style.btn.ina = &def;
#endif
}
2018-09-12 23:34:23 +02:00
static void imgbtn_init(void)
{
#if USE_LV_IMGBTN != 0
theme.style.imgbtn.rel = &def;
theme.style.imgbtn.pr = &def;
theme.style.imgbtn.tgl_rel = &def;
theme.style.imgbtn.tgl_pr = &def;
theme.style.imgbtn.ina = &def;
2018-09-12 23:34:23 +02:00
#endif
}
static void label_init(void)
{
#if USE_LV_LABEL != 0
theme.style.label.prim = &def;
theme.style.label.sec = &def;
theme.style.label.hint = &def;
#endif
}
static void img_init(void)
{
#if USE_LV_IMG != 0
theme.style.img.light = &def;
theme.style.img.dark = &def;
#endif
}
static void line_init(void)
{
#if USE_LV_LINE != 0
theme.style.line.decor = &def;
#endif
}
static void led_init(void)
{
#if USE_LV_LED != 0
theme.style.led = &def;
#endif
}
2017-11-18 00:17:21 +01:00
static void bar_init(void)
{
#if USE_LV_BAR
theme.style.bar.bg = &def;
theme.style.bar.indic = &def;
2017-11-18 00:17:21 +01:00
#endif
}
static void slider_init(void)
{
#if USE_LV_SLIDER != 0
theme.style.slider.bg = &def;
theme.style.slider.indic = &def;
theme.style.slider.knob = &def;
#endif
}
static void sw_init(void)
{
#if USE_LV_SW != 0
theme.style.sw.bg = &def;
theme.style.sw.indic = &def;
theme.style.sw.knob_off = &def;
theme.style.sw.knob_on = &def;
#endif
}
static void lmeter_init(void)
{
#if USE_LV_LMETER != 0
theme.style.lmeter = &def;
#endif
}
static void gauge_init(void)
{
#if USE_LV_GAUGE != 0
theme.style.gauge = &def;
#endif
}
static void arc_init(void)
{
#if USE_LV_ARC != 0
theme.style.arc = &def;
#endif
}
static void preload_init(void)
{
#if USE_LV_PRELOAD != 0
theme.style.preload = &def;
#endif
}
static void chart_init(void)
{
#if USE_LV_CHART
theme.style.chart = &def;
#endif
}
2018-09-12 23:34:23 +02:00
static void calendar_init(void)
{
#if USE_LV_CALENDAR
theme.style.calendar.bg = theme.style.panel;
theme.style.calendar.header = &def;
theme.style.calendar.inactive_days = &def;
theme.style.calendar.highlighted_days = &def;
theme.style.calendar.week_box = &def;
theme.style.calendar.today_box = &def;
theme.style.calendar.header_pr = &def;
theme.style.calendar.day_names = &def;
2018-09-12 23:34:23 +02:00
#endif
}
static void cb_init(void)
{
#if USE_LV_CB != 0
theme.style.cb.bg = &def;
theme.style.cb.box.rel = &def;
theme.style.cb.box.pr = &def;
theme.style.cb.box.tgl_rel = &def;
theme.style.cb.box.tgl_pr = &def;
theme.style.cb.box.ina = &def;
#endif
}
static void btnm_init(void)
{
#if USE_LV_BTNM
theme.style.btnm.bg = &def;
theme.style.btnm.btn.rel = &def;
theme.style.btnm.btn.pr = &def;
theme.style.btnm.btn.tgl_rel = &def;
theme.style.btnm.btn.tgl_pr = &def;
theme.style.btnm.btn.ina = &def;
#endif
}
static void kb_init(void)
{
#if USE_LV_KB
theme.style.kb.bg = &def;
theme.style.kb.btn.rel = &def;
theme.style.kb.btn.pr = &def;
theme.style.kb.btn.tgl_rel = &def;
theme.style.kb.btn.tgl_pr = &def;
theme.style.kb.btn.ina = &def;
#endif
}
static void mbox_init(void)
{
#if USE_LV_MBOX
theme.style.mbox.bg = &def;
theme.style.mbox.btn.bg = &def;
theme.style.mbox.btn.rel = &def;
theme.style.mbox.btn.pr = &def;
#endif
}
static void page_init(void)
{
#if USE_LV_PAGE
theme.style.page.bg = &def;
theme.style.page.scrl = &def;
theme.style.page.sb = &def;
#endif
}
static void ta_init(void)
{
#if USE_LV_TA
theme.style.ta.area = &def;
theme.style.ta.oneline = &def;
theme.style.ta.cursor = NULL; /*Let library to calculate the cursor's style*/
theme.style.ta.sb = &def;
#endif
}
static void list_init(void)
{
#if USE_LV_LIST != 0
theme.style.list.sb = &def;
theme.style.list.bg = &def;
theme.style.list.scrl = &def;
theme.style.list.btn.rel = &def;
theme.style.list.btn.pr = &def;
theme.style.list.btn.tgl_rel = &def;
theme.style.list.btn.tgl_pr = &def;
theme.style.list.btn.ina = &def;
#endif
}
static void ddlist_init(void)
{
#if USE_LV_DDLIST != 0
theme.style.ddlist.bg = &def;
theme.style.ddlist.sel = &def;
theme.style.ddlist.sb = &def;
#endif
}
static void roller_init(void)
{
#if USE_LV_ROLLER != 0
theme.style.roller.bg = &def;
theme.style.roller.sel = &def;
#endif
}
static void tabview_init(void)
{
#if USE_LV_TABVIEW != 0
theme.style.tabview.bg = &def;
theme.style.tabview.indic = &def;
theme.style.tabview.btn.bg = &def;
theme.style.tabview.btn.rel = &def;
theme.style.tabview.btn.pr = &def;
theme.style.tabview.btn.tgl_rel = &def;
theme.style.tabview.btn.tgl_pr = &def;
#endif
}
static void win_init(void)
{
#if USE_LV_WIN != 0
theme.style.win.bg = &def;
theme.style.win.sb = &def;
theme.style.win.header = &def;
theme.style.win.content.bg = &def;
theme.style.win.content.scrl = &def;
theme.style.win.btn.rel = &def;
theme.style.win.btn.pr = &def;
#endif
}
#if USE_LV_GROUP
static void style_mod(lv_style_t * style)
{
#if LV_COLOR_DEPTH != 1
/*Make the style to be a little bit orange*/
style->body.border.opa = LV_OPA_COVER;
style->body.border.color = LV_COLOR_ORANGE;
/*If not empty or has border then emphasis the border*/
if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_ORANGE, LV_OPA_70);
style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_ORANGE, LV_OPA_70);
style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_ORANGE, LV_OPA_60);
style->text.color = lv_color_mix(style->text.color, LV_COLOR_ORANGE, LV_OPA_70);
#else
style->body.border.opa = LV_OPA_COVER;
style->body.border.color = LV_COLOR_BLACK;
style->body.border.width = 2;
#endif
}
static void style_mod_edit(lv_style_t * style)
{
#if LV_COLOR_DEPTH != 1
/*Make the style to be a little bit orange*/
style->body.border.opa = LV_OPA_COVER;
style->body.border.color = LV_COLOR_GREEN;
/*If not empty or has border then emphasis the border*/
if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70);
style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70);
style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60);
style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70);
#else
style->body.border.opa = LV_OPA_COVER;
style->body.border.color = LV_COLOR_BLACK;
style->body.border.width = 3;
#endif
}
#endif /*USE_LV_GROUP*/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
2017-11-18 00:17:21 +01:00
* Initialize the templ theme
* @param hue [0..360] hue value from HSV color space to define the theme's base color
* @param font pointer to a font (NULL to use the default)
* @return pointer to the initialized theme
*/
2018-06-19 09:49:58 +02:00
lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t * font)
{
2017-11-19 19:28:45 +01:00
if(font == NULL) font = LV_FONT_DEFAULT;
_hue = hue;
_font = font;
/*For backward compatibility initialize all theme elements with a default style */
uint16_t i;
2019-02-12 15:02:43 +01:00
lv_style_t ** style_p = (lv_style_t **) &theme.style;
for(i = 0; i < LV_THEME_STYLE_COUNT; i++) {
*style_p = &def;
style_p++;
}
basic_init();
2017-11-22 23:04:02 +01:00
cont_init();
btn_init();
2018-09-12 23:34:23 +02:00
imgbtn_init();
label_init();
img_init();
line_init();
led_init();
2017-11-18 00:17:21 +01:00
bar_init();
slider_init();
sw_init();
lmeter_init();
gauge_init();
arc_init();
preload_init();
chart_init();
cb_init();
btnm_init();
kb_init();
mbox_init();
page_init();
ta_init();
list_init();
ddlist_init();
roller_init();
tabview_init();
win_init();
#if USE_LV_GROUP
theme.group.style_mod = style_mod;
theme.group.style_mod_edit = style_mod_edit;
#endif
return &theme;
}
/**
* Get a pointer to the theme
* @return pointer to the theme
*/
2017-11-22 23:04:02 +01:00
lv_theme_t * lv_theme_get_templ(void)
{
return &theme;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif