From b973dd342a2cea2d62ee53c80bbf8a866ba57b06 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 16 Nov 2017 15:32:33 +0100 Subject: [PATCH] lv_theme: integrate into the library add lv_theme --- lv_obj/lv_style.c | 6 +- lv_objx/lv_bar.c | 28 +- lv_objx/lv_btn.c | 14 +- lv_objx/lv_btnm.c | 21 +- lv_objx/lv_cb.c | 40 +- lv_objx/lv_cb.h | 10 +- lv_objx/lv_chart.c | 13 +- lv_objx/lv_cont.c | 9 +- lv_objx/lv_ddlist.c | 16 +- lv_objx/lv_gauge.c | 10 +- lv_objx/lv_img.c | 5 +- lv_objx/lv_kb.c | 35 +- lv_objx/lv_label.c | 10 +- lv_objx/lv_led.c | 10 +- lv_objx/lv_line.c | 4 +- lv_objx/lv_list.c | 21 +- lv_objx/lv_lmeter.c | 14 +- lv_objx/lv_mbox.c | 38 +- lv_objx/lv_mbox.h | 7 - lv_objx/lv_page.c | 17 +- lv_objx/lv_roller.c | 12 +- lv_objx/lv_slider.c | 12 +- lv_objx/lv_sw.c | 13 + lv_objx/lv_ta.c | 14 +- lv_objx/lv_tabview.c | 48 ++- lv_objx/lv_win.c | 31 +- lv_themes/lv_theme.c | 304 ++++++++++++++ lv_themes/lv_theme.h | 287 +++++++++++++ lv_themes/lv_theme_alien.c | 816 +++++++++++++++++++++++++++++++++++++ lv_themes/lv_theme_alien.h | 56 +++ lvgl.h | 4 + 31 files changed, 1809 insertions(+), 116 deletions(-) create mode 100644 lv_themes/lv_theme.c create mode 100644 lv_themes/lv_theme.h create mode 100644 lv_themes/lv_theme_alien.c create mode 100644 lv_themes/lv_theme_alien.h diff --git a/lv_obj/lv_style.c b/lv_obj/lv_style.c index 11b959580..a5f6bbc4d 100644 --- a/lv_obj/lv_style.c +++ b/lv_obj/lv_style.c @@ -73,9 +73,9 @@ void lv_style_init (void) lv_style_scr.body.color_main = COLOR_WHITE; lv_style_scr.body.color_gradient = COLOR_WHITE; lv_style_scr.body.radius = 0; - lv_style_scr.body.padding.ver = LV_DPI / 10; - lv_style_scr.body.padding.hor = LV_DPI / 10; - lv_style_scr.body.padding.inner = LV_DPI / 10; + lv_style_scr.body.padding.ver = LV_DPI / 12; + lv_style_scr.body.padding.hor = LV_DPI / 12; + lv_style_scr.body.padding.inner = LV_DPI / 12; lv_style_scr.body.empty = 0; lv_style_scr.body.border.color = COLOR_BLACK; diff --git a/lv_objx/lv_bar.c b/lv_objx/lv_bar.c index 429569f6a..faaf3b390 100644 --- a/lv_objx/lv_bar.c +++ b/lv_objx/lv_bar.c @@ -13,6 +13,7 @@ #include "lv_bar.h" #include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" #include "misc/gfx/anim.h" #include @@ -74,8 +75,15 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy) if(copy == NULL) { lv_obj_set_click(new_bar, false); lv_obj_set_size(new_bar, LV_DPI * 2, LV_DPI / 3); - lv_obj_set_style(new_bar, &lv_style_pretty); lv_bar_set_value(new_bar, ext->cur_value); + + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_bar_set_style(new_bar, LV_BAR_STYLE_BG, th->bar.bg); + lv_bar_set_style(new_bar, LV_BAR_STYLE_INDIC, th->bar.indic); + } else { + lv_obj_set_style(new_bar, &lv_style_pretty); + } } else { lv_bar_ext_t * ext_copy = lv_obj_get_ext_attr(copy); ext->min_value = ext_copy->min_value; @@ -221,20 +229,6 @@ int16_t lv_bar_get_max_value(lv_obj_t * bar) return ext->max_value; } -/** - * Get the style of bar indicator - * @param bar pointer to a bar object - * @return pointer to the bar indicator style - */ -lv_style_t * lv_bar_get_style_indicator(lv_obj_t * bar) -{ - lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - - if(ext->style_indic == NULL) return lv_obj_get_style(bar); - - return ext->style_indic; -} - /** * Get a style of a bar * @param bar pointer to a bar object @@ -279,7 +273,7 @@ static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - lv_style_t * style_indic = lv_bar_get_style_indicator(bar); + lv_style_t *style_indic = lv_bar_get_style(bar, LV_BAR_STYLE_INDIC); area_t indic_area; area_cpy(&indic_area, &bar->coords); indic_area.x1 += style_indic->body.padding.hor; @@ -320,7 +314,7 @@ static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param) if(res != LV_RES_OK) return res; if(sign == LV_SIGNAL_REFR_EXT_SIZE) { - lv_style_t * style_indic = lv_bar_get_style_indicator(bar); + lv_style_t * style_indic = lv_bar_get_style(bar, LV_BAR_STYLE_INDIC); if(style_indic->body.shadow.width > bar->ext_size) bar->ext_size = style_indic->body.shadow.width; } diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index dd5dacef6..2c1cddc4d 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -14,6 +14,7 @@ #include "lv_btn.h" #include "../lv_obj/lv_group.h" #include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" #include "misc/gfx/area.h" #include "misc/gfx/color.h" @@ -81,7 +82,18 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy) /*If no copy do the basic initialization*/ if(copy == NULL) { lv_btn_set_layout(new_btn, LV_CONT_LAYOUT_CENTER); - lv_obj_set_style(new_btn, ext->styles[LV_BTN_STATE_REL]); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_btn_set_style(new_btn, LV_BTN_STYLE_REL, th->btn.md.rel); + lv_btn_set_style(new_btn, LV_BTN_STYLE_PR, th->btn.md.pr); + lv_btn_set_style(new_btn, LV_BTN_STYLE_TGL_REL, th->btn.md.tgl_rel); + lv_btn_set_style(new_btn, LV_BTN_STYLE_TGL_PR, th->btn.md.tgl_pr); + lv_btn_set_style(new_btn, LV_BTN_STYLE_INA, th->btn.md.ina); + } else { + lv_obj_set_style(new_btn, ext->styles[LV_BTN_STATE_REL]); + } } /*Copy 'copy'*/ else { diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index ada05d39c..5e84c033e 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -13,6 +13,7 @@ #include "../lv_obj/lv_group.h" #include "../lv_draw/lv_draw.h" #include "../lv_obj/lv_refr.h" +#include "../lv_themes/lv_theme.h" #include "misc/gfx/text.h" /********************* @@ -92,8 +93,20 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new button matrix object*/ if(copy == NULL) { lv_obj_set_size(new_btnm, LV_HOR_RES, LV_VER_RES / 2); - lv_obj_set_style(new_btnm, &lv_style_pretty); lv_btnm_set_map(new_btnm, lv_btnm_def_map); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BG, th->btnm.bg); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_REL, th->btnm.btn.rel); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_PR, th->btnm.btn.pr); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_TGL_REL, th->btnm.btn.tgl_rel); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_TGL_PR, th->btnm.btn.tgl_pr); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_INA, th->btnm.btn.ina); + } else { + lv_obj_set_style(new_btnm, &lv_style_pretty); + } } /*Copy an existing object*/ else { @@ -120,9 +133,9 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy) * The first byte can be a control data: * - bit 7: always 1 * - bit 6: always 0 - * - bit 5: inactive (disabled) - * - bit 4: no repeat (on long press) - * - bit 3: hidden + * - bit 5: inactive (disabled) (\24x) + * - bit 4: no repeat (on long press) (\22x) + * - bit 3: hidden (\21x) * - bit 2..0: button relative width * Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press */ diff --git a/lv_objx/lv_cb.c b/lv_objx/lv_cb.c index fa3f6d7ee..f0e42dd7e 100644 --- a/lv_objx/lv_cb.c +++ b/lv_objx/lv_cb.c @@ -11,6 +11,7 @@ #include "lv_cb.h" #include "../lv_obj/lv_group.h" +#include "../lv_themes/lv_theme.h" /********************* * DEFINES @@ -71,15 +72,24 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy) lv_obj_set_click(ext->bullet, false); ext->label = lv_label_create(new_cb, NULL); - lv_obj_set_style(ext->label, NULL); /*Inherit the style of the parent*/ - lv_cb_set_style(new_cb,LV_CB_STYLE_BG, &lv_style_transp); lv_cb_set_text(new_cb, "Check box"); - lv_cont_set_layout(new_cb, LV_CONT_LAYOUT_ROW_M); - lv_cont_set_fit(new_cb, true, true); + lv_btn_set_layout(new_cb, LV_CONT_LAYOUT_ROW_M); + lv_btn_set_fit(new_cb, true, true); lv_btn_set_toggle(new_cb, true); - lv_obj_refresh_style(new_cb); + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_cb_set_style(new_cb, LV_CB_STYLE_BG, th->cb.bg); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_REL, th->cb.box.rel); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_PR, th->cb.box.pr); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_TGL_REL, th->cb.box.tgl_rel); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_TGL_PR, th->cb.box.tgl_pr); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_INA, th->cb.box.ina); + } else { + lv_cb_set_style(new_cb,LV_CB_STYLE_BG, &lv_style_transp); + } } else { lv_cb_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->bullet = lv_btn_create(new_cb, copy_ext->bullet); @@ -127,19 +137,19 @@ void lv_cb_set_style(lv_obj_t * cb, lv_cb_style_t type, lv_style_t *style) lv_btn_set_style(cb, LV_BTN_STYLE_TGL_PR, style); lv_btn_set_style(cb, LV_BTN_STYLE_INA, style); break; - case LV_CB_STYLE_REL: + case LV_CB_STYLE_BOX_REL: lv_btn_set_style(ext->bullet, LV_BTN_STYLE_REL, style); break; - case LV_CB_STYLE_PR: + case LV_CB_STYLE_BOX_PR: lv_btn_set_style(ext->bullet, LV_BTN_STYLE_PR, style); break; - case LV_CB_STYLE_TGL_REL: + case LV_CB_STYLE_BOX_TGL_REL: lv_btn_set_style(ext->bullet, LV_BTN_STYLE_TGL_REL, style); break; - case LV_CB_STYLE_TGL_PR: + case LV_CB_STYLE_BOX_TGL_PR: lv_btn_set_style(ext->bullet, LV_BTN_STYLE_TGL_PR, style); break; - case LV_CB_STYLE_INA: + case LV_CB_STYLE_BOX_INA: lv_btn_set_style(ext->bullet, LV_BTN_STYLE_INA, style); break; } @@ -174,11 +184,11 @@ lv_style_t * lv_cb_get_style(lv_obj_t * cb, lv_cb_style_t type) lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb); switch (type) { - case LV_CB_STYLE_REL: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_REL); - case LV_CB_STYLE_PR: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_PR); - case LV_CB_STYLE_TGL_REL: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_TGL_REL); - case LV_CB_STYLE_TGL_PR: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_TGL_PR); - case LV_CB_STYLE_INA: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_INA); + case LV_CB_STYLE_BOX_REL: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_REL); + case LV_CB_STYLE_BOX_PR: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_PR); + case LV_CB_STYLE_BOX_TGL_REL: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_TGL_REL); + case LV_CB_STYLE_BOX_TGL_PR: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_TGL_PR); + case LV_CB_STYLE_BOX_INA: return lv_btn_get_style(ext->bullet, LV_BTN_STYLE_INA); default: return NULL; } diff --git a/lv_objx/lv_cb.h b/lv_objx/lv_cb.h index 36f28c5fa..11f3ef0c5 100644 --- a/lv_objx/lv_cb.h +++ b/lv_objx/lv_cb.h @@ -48,11 +48,11 @@ typedef struct typedef enum { LV_CB_STYLE_BG, - LV_CB_STYLE_REL, - LV_CB_STYLE_PR, - LV_CB_STYLE_TGL_REL, - LV_CB_STYLE_TGL_PR, - LV_CB_STYLE_INA, + LV_CB_STYLE_BOX_REL, + LV_CB_STYLE_BOX_PR, + LV_CB_STYLE_BOX_TGL_REL, + LV_CB_STYLE_BOX_TGL_PR, + LV_CB_STYLE_BOX_INA, }lv_cb_style_t; /********************** diff --git a/lv_objx/lv_chart.c b/lv_objx/lv_chart.c index f2c7d2955..1c5324392 100644 --- a/lv_objx/lv_chart.c +++ b/lv_objx/lv_chart.c @@ -11,6 +11,7 @@ #include "lv_chart.h" #include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" /********************* * DEFINES @@ -84,8 +85,16 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new chart background object*/ if(copy == NULL) { - lv_obj_set_style(new_chart, &lv_style_pretty); - lv_obj_set_size(new_chart, LV_HOR_RES / 2, LV_VER_RES / 2); + lv_obj_set_size(new_chart, LV_HOR_RES / 3, LV_VER_RES / 3); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_chart_set_style(new_chart, th->chart); + } else { + lv_chart_set_style(new_chart, &lv_style_pretty); + } + } else { lv_chart_ext_t * ext_copy = lv_obj_get_ext_attr(copy); ext->type = ext_copy->type; diff --git a/lv_objx/lv_cont.c b/lv_objx/lv_cont.c index b306c4049..463651124 100644 --- a/lv_objx/lv_cont.c +++ b/lv_objx/lv_cont.c @@ -17,6 +17,7 @@ #include "lv_cont.h" #include "../lv_draw/lv_draw.h" #include "../lv_draw/lv_draw_vbasic.h" +#include "../lv_themes/lv_theme.h" #include "misc/gfx/area.h" #include "misc/gfx/color.h" @@ -79,7 +80,13 @@ lv_obj_t * lv_cont_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new container*/ if(copy == NULL) { - lv_cont_set_style(new_cont, &lv_style_plain); + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_cont_set_style(new_cont, th->cont.filled); + } else { + lv_cont_set_style(new_cont, &lv_style_pretty); + } } /*Copy an existing object*/ else { diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index 119e2b76f..49267fa0e 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -14,6 +14,7 @@ #include "../lv_draw/lv_draw.h" #include "../lv_obj/lv_group.h" #include "../lv_obj/lv_indev.h" +#include "../lv_themes/lv_theme.h" #include "misc/gfx/anim.h" /********************* @@ -94,9 +95,20 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) lv_page_set_release_action(new_ddlist, lv_ddlist_release_action); lv_page_set_sb_mode(new_ddlist, LV_PAGE_SB_MODE_DRAG); lv_page_set_style(new_ddlist, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight); - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, &lv_style_pretty); - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, &lv_style_plain_color); + lv_ddlist_set_options(new_ddlist, "Option 1\nOption 2\nOption 3"); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, th->ddlist.bg); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL,th->ddlist.sel); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, th->ddlist.sb); + } else { + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, &lv_style_pretty); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, &lv_style_plain_color); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, &lv_style_pretty_color); + } } /*Copy an existing drop down list*/ else { diff --git a/lv_objx/lv_gauge.c b/lv_objx/lv_gauge.c index 0058111db..5806dd049 100644 --- a/lv_objx/lv_gauge.c +++ b/lv_objx/lv_gauge.c @@ -12,6 +12,7 @@ #include "lv_gauge.h" #include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" #include "misc/gfx/text.h" #include "misc/math/trigo.h" #include "misc/math/math_base.h" @@ -90,7 +91,14 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, lv_obj_t * copy) lv_gauge_set_scale(new_gauge, LV_GAUGE_DEF_ANGLE, LV_GAUGE_DEF_LINE_COUNT, LV_GAUGE_DEF_LABEL_COUNT); lv_gauge_set_needle_count(new_gauge, 1, NULL); lv_obj_set_size(new_gauge, 2 * LV_DPI, 2 * LV_DPI); - lv_obj_set_style(new_gauge, &lv_style_pretty_color); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_gauge_set_style(new_gauge, th->gauge); + } else { + lv_gauge_set_style(new_gauge, &lv_style_pretty_color); + } } /*Copy an existing gauge*/ else { diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index a6e0516c8..48ac02eaa 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -12,6 +12,7 @@ #include "lv_img.h" #include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" #include "misc/fs/fsint.h" #include "misc/fs/ufs/ufs.h" #include "misc/gfx/text.h" @@ -79,8 +80,8 @@ lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy) * and must be screen sized*/ if(par != NULL) ext->auto_size = 1; else ext->auto_size = 0; - if(par != NULL) lv_obj_set_style(new_img, NULL); /*Inherit the style by default*/ - else lv_obj_set_style(new_img, &lv_style_plain); /*Set style for screens*/ + if(par != NULL) lv_obj_set_style(new_img, NULL); /*Inherit the style by default*/ + else lv_obj_set_style(new_img, &lv_style_plain); /*Set a style for screens*/ } else { lv_img_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->auto_size = copy_ext->auto_size; diff --git a/lv_objx/lv_kb.c b/lv_objx/lv_kb.c index 7ca5ce574..2018de66d 100644 --- a/lv_objx/lv_kb.c +++ b/lv_objx/lv_kb.c @@ -12,6 +12,7 @@ #include "lv_kb.h" #include "lv_ta.h" +#include "../lv_themes/lv_theme.h" /********************* * DEFINES @@ -34,21 +35,21 @@ static lv_signal_func_t ancestor_signal; static const char * kb_map_lc[] = { "\2051#", "\204q", "\204w", "\204e", "\204r", "\204t", "\204y", "\204u", "\204i", "\204o", "\204p", "\207Del", "\n", -"\206ABC", "\203a", "\203s", "\203d", "\203f", "\203g", "\203h", "\203j", "\203k", "\203l", "\207Enter", "\n", +"\226ABC", "\203a", "\203s", "\203d", "\203f", "\203g", "\203h", "\203j", "\203k", "\203l", "\207Enter", "\n", "_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n", "\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, "" }; static const char * kb_map_uc[] = { "\2051#", "\204Q", "\204W", "\204E", "\204R", "\204T", "\204Y", "\204U", "\204I", "\204O", "\204P", "\207Del", "\n", -"\206abc", "\203A", "\203S", "\203D", "\203F", "\203G", "\203H", "\203J", "\203K", "\203L", "\207Enter", "\n", +"\226abc", "\203A", "\203S", "\203D", "\203F", "\203G", "\203H", "\203J", "\203K", "\203L", "\207Enter", "\n", "_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n", "\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, "" }; static const char * kb_map_spec[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\202Del", "\n", -"\202abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n", +"\222abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n", "\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n", "\202"SYMBOL_CLOSE, "\202"SYMBOL_LEFT, "\206 ", "\202"SYMBOL_RIGHT, "\202"SYMBOL_OK, "" }; @@ -101,6 +102,19 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy) lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_btnm_set_action(new_kb, lv_app_kb_action); lv_btnm_set_map(new_kb, kb_map_lc); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_kb_set_style(new_kb, LV_KB_STYLE_BG, th->kb.bg); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_REL, th->kb.btn.rel); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_PR, th->kb.btn.pr); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_REL, th->kb.btn.tgl_rel); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_PR, th->kb.btn.tgl_pr); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_INA, th->kb.btn.ina); + } else { + /*Let the button matrix's styles*/ + } } /*Copy an existing keyboard*/ else { @@ -334,9 +348,18 @@ static lv_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt) lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); /*Do the corresponding action according to the text of the button*/ - if(strcmp(txt, "abc") == 0) lv_btnm_set_map(kb, kb_map_lc); - else if(strcmp(txt, "ABC") == 0) lv_btnm_set_map(kb, kb_map_uc); - else if(strcmp(txt, "1#") == 0) lv_btnm_set_map(kb, kb_map_spec); + if(strcmp(txt, "abc") == 0) { + lv_btnm_set_map(kb, kb_map_lc); + return LV_RES_OK; + } + else if(strcmp(txt, "ABC") == 0) { + lv_btnm_set_map(kb, kb_map_uc); + return LV_RES_OK; + } + else if(strcmp(txt, "1#") == 0) { + lv_btnm_set_map(kb, kb_map_spec); + return LV_RES_OK; + } else if(strcmp(txt, SYMBOL_CLOSE) == 0) { if(ext->close_action) ext->close_action(kb); else lv_obj_del(kb); diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 2b4e0f076..ff382821c 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -9,15 +9,15 @@ #include "lv_conf.h" #if USE_LV_LABEL != 0 -#include "misc/gfx/color.h" -#include "misc/gfx/text.h" -#include "misc/math/math_base.h" #include "lv_label.h" #include "../lv_obj/lv_obj.h" #include "../lv_obj/lv_group.h" +#include "../lv_draw/lv_draw.h" +#include "misc/gfx/color.h" +#include "misc/gfx/text.h" +#include "misc/math/math_base.h" #include "misc/gfx/text.h" #include "misc/gfx/anim.h" -#include "../lv_draw/lv_draw.h" /********************* * DEFINES @@ -93,9 +93,9 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new label*/ if(copy == NULL) { lv_obj_set_click(new_label, false); - lv_obj_set_style(new_label, NULL); lv_label_set_long_mode(new_label, LV_LABEL_LONG_EXPAND); lv_label_set_text(new_label, "Text"); + lv_label_set_style(new_label, NULL); /*Inherit parent's style*/ } /*Copy 'copy' if not NULL*/ else { diff --git a/lv_objx/lv_led.c b/lv_objx/lv_led.c index d3781f732..7881bc16b 100644 --- a/lv_objx/lv_led.c +++ b/lv_objx/lv_led.c @@ -10,6 +10,7 @@ #if USE_LV_LED != 0 #include "lv_led.h" +#include "../lv_themes/lv_theme.h" #include "../lv_draw/lv_draw.h" /********************* @@ -68,8 +69,15 @@ lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new led object*/ if(copy == NULL) { - lv_obj_set_style(new_led, &lv_style_pretty_color); lv_obj_set_size(new_led, LV_LED_WIDTH_DEF, LV_LED_HEIGHT_DEF); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_led_set_style(new_led, th->led); + } else { + lv_led_set_style(new_led, &lv_style_pretty_color); + } } /*Copy an existing object*/ else { diff --git a/lv_objx/lv_line.c b/lv_objx/lv_line.c index 38d8edbe9..14ef9399a 100644 --- a/lv_objx/lv_line.c +++ b/lv_objx/lv_line.c @@ -70,8 +70,8 @@ lv_obj_t * lv_line_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new line*/ if(copy == NULL) { - lv_obj_set_size(new_line, LV_DPI, LV_DPI); - lv_obj_set_style(new_line, &lv_style_plain); + lv_obj_set_size(new_line, LV_DPI, LV_DPI); /*Auto size is enables, but set default size until no points are added*/ + lv_obj_set_style(new_line, NULL); /*Inherit parent's style*/ } /*Copy an existing object*/ else { diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 2d13b788c..8d83b59c7 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -11,6 +11,7 @@ #include "lv_list.h" #include "../lv_obj/lv_group.h" +#include "../lv_themes/lv_theme.h" #include "misc/gfx/anim.h" #include "misc/math/math_base.h" @@ -79,9 +80,23 @@ lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy) if(copy == NULL) { lv_obj_set_size(new_list, 2 * LV_DPI, 3 * LV_DPI); lv_page_set_scrl_layout(new_list, LV_LIST_LAYOUT_DEF); - lv_page_set_sb_mode(new_list, LV_PAGE_SB_MODE_DRAG); - lv_list_set_style(new_list, LV_LIST_STYLE_BG, &lv_style_transp_fit); - lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, &lv_style_pretty); + lv_list_set_sb_mode(new_list, LV_PAGE_SB_MODE_DRAG); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_list_set_style(new_list, LV_LIST_STYLE_BG, th->list.bg); + lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, th->list.scrl); + lv_list_set_style(new_list, LV_LIST_STYLE_SB, th->list.sb); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_REL, th->list.btn.rel); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_PR, th->list.btn.pr); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_REL, th->list.btn.tgl_rel); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_PR, th->list.btn.tgl_pr); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_INA, th->list.btn.ina); + } else { + lv_list_set_style(new_list, LV_LIST_STYLE_BG, &lv_style_transp_fit); + lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, &lv_style_pretty); + } } else { lv_list_ext_t * copy_ext = lv_obj_get_ext_attr(copy); diff --git a/lv_objx/lv_lmeter.c b/lv_objx/lv_lmeter.c index 96005a688..b39fbee59 100644 --- a/lv_objx/lv_lmeter.c +++ b/lv_objx/lv_lmeter.c @@ -10,8 +10,9 @@ #if USE_LV_LMETER != 0 #include "lv_lmeter.h" -#include "misc/math/trigo.h" #include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" +#include "misc/math/trigo.h" /********************* * DEFINES @@ -70,8 +71,15 @@ lv_obj_t * lv_lmeter_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new line meter line meter*/ if(copy == NULL) { - lv_obj_set_size(new_lmeter, 1 * LV_DPI, 1 * LV_DPI); - lv_obj_set_style(new_lmeter, &lv_style_pretty_color); + lv_obj_set_size(new_lmeter, LV_DPI, LV_DPI); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_lmeter_set_style(new_lmeter, th->lmeter); + } else { + lv_lmeter_set_style(new_lmeter, &lv_style_pretty_color); + } } /*Copy an existing line meter*/ else { diff --git a/lv_objx/lv_mbox.c b/lv_objx/lv_mbox.c index be0727f80..a1ec898f8 100644 --- a/lv_objx/lv_mbox.c +++ b/lv_objx/lv_mbox.c @@ -12,6 +12,7 @@ #include "lv_mbox.h" #include "../lv_obj/lv_group.h" +#include "../lv_themes/lv_theme.h" #include "misc/gfx/anim.h" #include "misc/math/math_base.h" @@ -29,6 +30,7 @@ **********************/ static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param); static void mbox_realign(lv_obj_t *mbox); +static lv_res_t lv_mbox_close_action(lv_obj_t *btn, const char *txt); /********************** * STATIC VARIABLES @@ -76,8 +78,16 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy) lv_cont_set_layout(new_mbox, LV_CONT_LAYOUT_COL_M); lv_cont_set_fit(new_mbox, false, true); lv_obj_set_width(new_mbox, LV_HOR_RES / 3); + lv_obj_align(new_mbox, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, th->mbox.bg); + } else { + lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, &lv_style_pretty); + } - lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, &lv_style_pretty); } /*Copy an existing message box*/ else { @@ -110,11 +120,21 @@ void lv_mbox_set_btns(lv_obj_t * mbox, const char **btn_map, lv_btnm_action_t ac if(ext->btnm == NULL) { ext->btnm = lv_btnm_create(mbox, NULL); lv_obj_set_height(ext->btnm, LV_DPI / 2); - lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BG, &lv_style_transp_fit); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_BG, th->mbox.btn.bg); + lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_REL, th->mbox.btn.rel); + lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_PR, th->mbox.btn.pr); + } else { + lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BG, &lv_style_transp_fit); + } } lv_btnm_set_map(ext->btnm, btn_map); - lv_btnm_set_action(ext->btnm, action); + if(action == NULL) lv_btnm_set_action(ext->btnm, lv_mbox_close_action); /*Set a default action anyway*/ + else lv_btnm_set_action(ext->btnm, action); mbox_realign(mbox); } @@ -346,4 +366,16 @@ static void mbox_realign(lv_obj_t *mbox) if(ext->text) lv_obj_set_width(ext->text, w); } +static lv_res_t lv_mbox_close_action(lv_obj_t *btn, const char *txt) +{ + lv_obj_t *mbox = lv_mbox_get_from_btn(btn); + + if(txt[0] != '\0') { + lv_mbox_start_auto_close(mbox, 0); + return LV_RES_INV; + } + + return LV_RES_OK; +} + #endif diff --git a/lv_objx/lv_mbox.h b/lv_objx/lv_mbox.h index d2269d3dc..93b2daeda 100644 --- a/lv_objx/lv_mbox.h +++ b/lv_objx/lv_mbox.h @@ -75,13 +75,6 @@ typedef enum { */ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy); -/** - * A release action which can be assigned to a message box button to close it - * @param btn pointer to the released button - * @return always lv_action_res_t because the button is deleted with the mesage box - */ -lv_res_t lv_mbox_close_action(lv_obj_t * btn); - /** * Set button to the message box * @param mbox pointer to message box object diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index d206dcf6a..8ff9783c9 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -13,6 +13,7 @@ #include "../lv_obj/lv_group.h" #include "../lv_objx/lv_page.h" #include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" #include "../lv_obj/lv_refr.h" #include "misc/gfx/anim.h" @@ -88,10 +89,20 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy) lv_obj_set_signal_func(new_page, lv_page_signal); lv_obj_set_design_func(new_page, lv_page_design); - lv_page_set_style(new_page, LV_PAGE_STYLE_BG, &lv_style_pretty_color); - lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_pretty); - lv_page_set_style(new_page, LV_PAGE_STYLE_SB, &lv_style_pretty_color); lv_page_set_sb_mode(new_page, ext->sb.mode); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->page.bg); + lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, th->page.scrl); + lv_page_set_style(new_page, LV_PAGE_STYLE_SB, th->page.sb); + } else { + lv_page_set_style(new_page, LV_PAGE_STYLE_BG, &lv_style_pretty_color); + lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_pretty); + lv_page_set_style(new_page, LV_PAGE_STYLE_SB, &lv_style_pretty_color); + } + } else { lv_page_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->scrl = lv_cont_create(new_page, copy_ext->scrl); diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index 65f72ed55..f23258990 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -11,6 +11,7 @@ #include "lv_roller.h" #include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" /********************* * DEFINES @@ -78,7 +79,16 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy) lv_label_set_align(ext->ddlist.label, LV_LABEL_ALIGN_CENTER); lv_obj_set_signal_func(scrl, lv_roller_scrl_signal); - lv_obj_refresh_style(new_roller); /*To set scrollable size automatically*/ + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_roller_set_style(new_roller, LV_ROLLER_STYLE_BG, th->roller.bg); + lv_roller_set_style(new_roller, LV_ROLLER_STYLE_SEL, th->roller.sel); + } else { + /*Let the ddlist's style*/ + lv_obj_refresh_style(new_roller); /*To set scrollable size automatically*/ + } } /*Copy an existing roller*/ else { diff --git a/lv_objx/lv_slider.c b/lv_objx/lv_slider.c index a9a4b1341..7e5020516 100644 --- a/lv_objx/lv_slider.c +++ b/lv_objx/lv_slider.c @@ -12,6 +12,7 @@ #include "lv_slider.h" #include "../lv_obj/lv_group.h" #include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" #include "misc/math/math_base.h" /********************* @@ -75,7 +76,16 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new slider slider*/ if(copy == NULL) { lv_obj_set_click(new_slider, true); - lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, ext->style_knob); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_BG, th->slider.bg); + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_INDIC, th->slider.indic); + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, th->slider.knob); + } else { + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, ext->style_knob); + } } /*Copy an existing slider*/ else { diff --git a/lv_objx/lv_sw.c b/lv_objx/lv_sw.c index c589c56f6..2557760f6 100644 --- a/lv_objx/lv_sw.c +++ b/lv_objx/lv_sw.c @@ -10,6 +10,7 @@ #if USE_LV_SW != 0 #include "lv_sw.h" +#include "../lv_themes/lv_theme.h" /********************* * DEFINES @@ -68,6 +69,18 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy) lv_slider_set_range(new_sw, 0, 1); lv_obj_set_size(new_sw, 2 * LV_DPI / 3, LV_DPI / 3); lv_slider_set_knob_in(new_sw, true); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_slider_set_style(new_sw, LV_SW_STYLE_BG, th->sw.bg); + lv_slider_set_style(new_sw, LV_SW_STYLE_INDIC, th->sw.indic); + lv_slider_set_style(new_sw, LV_SW_STYLE_KNOB_OFF, th->sw.knob_off); + lv_slider_set_style(new_sw, LV_SW_STYLE_KNOB_ON, th->sw.knob_on); + } else { + /*Let the slider' style*/ + } + } /*Copy an existing switch*/ else { diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index aa230c634..f950dba11 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -13,6 +13,7 @@ #include "lv_ta.h" #include "../lv_obj/lv_group.h" #include "../lv_draw/lv_draw.h" +#include "../lv_themes/lv_theme.h" #include "misc/gfx/anim.h" #include "misc/gfx/text.h" #include "misc/math/math_base.h" @@ -103,13 +104,22 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy) ext->label = lv_label_create(new_ta, NULL); lv_obj_set_design_func(ext->page.scrl, lv_ta_scrollable_design); + lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK); lv_label_set_text(ext->label, "Text area"); lv_obj_set_click(ext->label, false); - lv_obj_set_style(new_ta, &lv_style_pretty); - lv_obj_set_style(lv_page_get_scrl(new_ta), &lv_style_transp_fit); lv_obj_set_size(new_ta, LV_TA_DEF_WIDTH, LV_TA_DEF_HEIGHT); lv_ta_set_sb_mode(new_ta, LV_PAGE_SB_MODE_DRAG); + lv_page_set_style(new_ta, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_ta_set_style(new_ta, LV_TA_STYLE_BG, th->ta.area); + lv_ta_set_style(new_ta, LV_TA_STYLE_SB, th->ta.sb); + } else { + lv_ta_set_style(new_ta, LV_TA_STYLE_BG, &lv_style_pretty); + } } /*Copy an existing object*/ else { diff --git a/lv_objx/lv_tabview.c b/lv_objx/lv_tabview.c index 478ace6a9..2328c655c 100644 --- a/lv_objx/lv_tabview.c +++ b/lv_objx/lv_tabview.c @@ -9,8 +9,9 @@ #include "lv_conf.h" #if USE_LV_TABVIEW != 0 -#include +#include "lv_tabview.h" #include "lv_btnm.h" +#include "../lv_themes/lv_theme.h" #include "misc/gfx/anim.h" /********************* @@ -107,12 +108,23 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy) lv_obj_set_height(ext->content, LV_VER_RES - lv_obj_get_height(ext->btns)); lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); - lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, &lv_style_transp); - lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, &lv_style_plain_color); - + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BG, th->tabview.bg); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, th->tabview.indic); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, th->tabview.btn.bg); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_REL, th->tabview.btn.rel); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_PR, th->tabview.btn.pr); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_REL, th->tabview.btn.tgl_rel); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_PR, th->tabview.btn.tgl_pr); + } else { + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, &lv_style_transp); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, &lv_style_plain_color); + } } - /*Copy an existing tab*/ + /*Copy an existing tab view*/ else { lv_tabview_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->point_last.x = 0; @@ -194,7 +206,7 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name) lv_obj_set_width(ext->indic, indic_width); lv_obj_set_x(ext->indic, indic_width * ext->tab_cur + style_tabs->body.padding.inner * ext->tab_cur + style_tabs->body.padding.hor); - /*Set the first tab as active*/ + /*Set the first btn as active*/ if(ext->tab_cnt == 1) { ext->tab_cur = 0; lv_tabview_set_current_tab(tabview, 0, false); @@ -274,7 +286,7 @@ void lv_tabview_set_current_tab(lv_obj_t * tabview, uint16_t id, bool anim_en) * Set an action to call when a tab is loaded (Good to create content only if required) * lv_tabview_get_act() still gives the current (old) tab (to remove content from here) * @param tabview pointer to a tabview object - * @param action pointer to a function to call when a tab is loaded + * @param action pointer to a function to call when a btn is loaded */ void lv_tabview_set_tab_load_action(lv_obj_t *tabview, lv_tabview_action_t action) { @@ -346,9 +358,9 @@ void lv_tabview_set_style(lv_obj_t *tabview, lv_tabview_style_t type, lv_style_t *====================*/ /** - * Get the index of the currently active tab + * Get the index of the currently active btn * @param tabview pointer to Tab view object - * @return the active tab index + * @return the active btn index */ uint16_t lv_tabview_get_current_tab(lv_obj_t * tabview) { @@ -359,7 +371,7 @@ uint16_t lv_tabview_get_current_tab(lv_obj_t * tabview) /** * Get the number of tabs * @param tabview pointer to Tab view object - * @return tab count + * @return btn count */ uint16_t lv_tabview_get_tab_count(lv_obj_t * tabview) { @@ -370,7 +382,7 @@ uint16_t lv_tabview_get_tab_count(lv_obj_t * tabview) /** * Get the page (content area) of a tab * @param tabview pointer to Tab view object - * @param id index of the tab (>= 0) + * @param id index of the btn (>= 0) * @return pointer to page (lv_page) object */ lv_obj_t * lv_tabview_get_tab(lv_obj_t * tabview, uint16_t id) @@ -392,7 +404,7 @@ lv_obj_t * lv_tabview_get_tab(lv_obj_t * tabview, uint16_t id) /** * Get the tab load action * @param tabview pointer to a tabview object - * @param return the current tab load action + * @param return the current btn load action */ lv_tabview_action_t lv_tabview_get_tab_load_action(lv_obj_t *tabview) { @@ -537,8 +549,8 @@ static lv_res_t tabpage_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void /** * Called when a tab's page or scrollable object is pressed - * @param tabview pointer to the tab view object - * @param tabpage pointer to the page of a tab + * @param tabview pointer to the btn view object + * @param tabpage pointer to the page of a btn */ static void tabpage_pressed_hadler(lv_obj_t * tabview, lv_obj_t * tabpage) { @@ -549,8 +561,8 @@ static void tabpage_pressed_hadler(lv_obj_t * tabview, lv_obj_t * tabpage) /** * Called when a tab's page or scrollable object is being pressed - * @param tabview pointer to the tab view object - * @param tabpage pointer to the page of a tab + * @param tabview pointer to the btn view object + * @param tabpage pointer to the page of a btn */ static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage) { @@ -588,8 +600,8 @@ static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage) /** * Called when a tab's page or scrollable object is released or the press id lost - * @param tabview pointer to the tab view object - * @param tabpage pointer to the page of a tab + * @param tabview pointer to the btn view object + * @param tabpage pointer to the page of a btn */ static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage) { diff --git a/lv_objx/lv_win.c b/lv_objx/lv_win.c index ac128aae9..3ea4a102f 100644 --- a/lv_objx/lv_win.c +++ b/lv_objx/lv_win.c @@ -10,6 +10,7 @@ #if USE_LV_WIN != 0 #include "lv_win.h" +#include "../lv_themes/lv_theme.h" /********************* * DEFINES @@ -71,7 +72,7 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy) ext->page = lv_page_create(new_win, NULL); lv_obj_set_protect(ext->page, LV_PROTECT_PARENT); lv_page_set_sb_mode(ext->page, LV_PAGE_SB_MODE_AUTO); - lv_page_set_style(ext->page, LV_PAGE_STYLE_BG, &lv_style_transp_tight); + lv_page_set_style(ext->page, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight); /*Create a holder for the header*/ ext->header = lv_obj_create(new_win, NULL); @@ -83,9 +84,24 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy) ext->title = lv_label_create(ext->header, NULL); lv_label_set_text(ext->title,"My title"); - lv_win_set_style(new_win, LV_WIN_STYLE_BG, &lv_style_pretty); - lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT, &lv_style_transp); - lv_win_set_style(new_win, LV_WIN_STYLE_HEADER, &lv_style_plain_color); + + /*Set the default styles*/ + lv_theme_t *th = lv_theme_get_current(); + if(th) { + lv_win_set_style(new_win, LV_WIN_STYLE_BG, th->win.bg); + lv_win_set_style(new_win, LV_WIN_STYLE_SB, th->win.sb); + lv_win_set_style(new_win, LV_WIN_STYLE_HEADER, th->win.header); + lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT, th->win.content); + lv_win_set_style(new_win, LV_WIN_STYLE_BTN_REL, th->win.btn.rel); + lv_win_set_style(new_win, LV_WIN_STYLE_BTN_PR, th->win.btn.pr); + + } else { + lv_win_set_style(new_win, LV_WIN_STYLE_BG, &lv_style_pretty); + lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT, &lv_style_transp); + lv_win_set_style(new_win, LV_WIN_STYLE_HEADER, &lv_style_plain_color); + + } + lv_obj_set_signal_func(new_win, lv_win_signal); lv_obj_set_size(new_win, LV_HOR_RES, LV_VER_RES); @@ -212,7 +228,7 @@ void lv_win_set_style(lv_obj_t *win, lv_win_style_t type, lv_style_t *style) lv_win_realign(win); break; case LV_WIN_STYLE_CONTENT: - lv_page_set_style(ext->page, LV_PAGE_STYLE_SCRL, style); + lv_page_set_style(ext->page, LV_PAGE_STYLE_BG, style); break; case LV_WIN_STYLE_SB: lv_page_set_style(ext->page, LV_PAGE_STYLE_SB, style); @@ -292,8 +308,7 @@ cord_t lv_win_get_width(lv_obj_t * win) */ lv_obj_t * lv_win_get_from_btn(lv_obj_t * ctrl_btn) { - lv_obj_t * ctrl_holder = lv_obj_get_parent(ctrl_btn); - lv_obj_t * header = lv_obj_get_parent(ctrl_holder); + lv_obj_t * header = lv_obj_get_parent(ctrl_btn); lv_obj_t * win = lv_obj_get_parent(header); return win; @@ -312,7 +327,7 @@ lv_style_t * lv_win_get_style(lv_obj_t *win, lv_win_style_t type) switch (type) { case LV_WIN_STYLE_BG: return lv_obj_get_style(win); case LV_WIN_STYLE_SB: return lv_page_get_style(ext->page, LV_PAGE_STYLE_SB); - case LV_WIN_STYLE_CONTENT: return lv_page_get_style(ext->page, LV_PAGE_STYLE_SCRL); + case LV_WIN_STYLE_CONTENT: return lv_page_get_style(ext->page, LV_PAGE_STYLE_BG); case LV_WIN_STYLE_HEADER: return lv_obj_get_style(ext->header); case LV_WIN_STYLE_BTN_REL: return ext->style_btn_rel; case LV_WIN_STYLE_BTN_PR: return ext->style_btn_pr; diff --git a/lv_themes/lv_theme.c b/lv_themes/lv_theme.c new file mode 100644 index 000000000..1f6bc488d --- /dev/null +++ b/lv_themes/lv_theme.c @@ -0,0 +1,304 @@ +/** + * @file lv_theme.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lvgl/lvgl.h" +#include "lv_theme.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static void create_tab1(lv_theme_t * th, lv_obj_t *parent); +static void create_tab2(lv_theme_t * th, lv_obj_t *parent); +static void create_tab3(lv_theme_t * th, lv_obj_t *parent); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_theme_t *current_theme; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Set a theme for the system. + * From now, all the created objects will use styles from this theme by default + * @param th pointer to theme (return value of: 'lv_theme_init_xxx()') + */ +void lv_theme_set_current(lv_theme_t *th) +{ + current_theme = th; +} + +/** + * Get the current system theme. + * @return pointer to the current system theme. NULL if not set. + */ +lv_theme_t * lv_theme_get_current(void) +{ + return current_theme; +} + + +/** + * Create a test screen with a lot objects and apply the given theme on them + * @param th pointer to a theme + */ +void lv_theme_create_test_screen(lv_theme_t *th) +{ + lv_theme_set_current(th); + lv_obj_t *scr = lv_cont_create(NULL, NULL); + lv_scr_load(scr); + lv_cont_set_style(scr, th->bg); + + + lv_obj_t *tv = lv_tabview_create(scr, NULL); + + lv_obj_set_size(tv, LV_HOR_RES, LV_VER_RES); + lv_obj_t *tab1 = lv_tabview_add_tab(tv, "Tab 1"); + lv_obj_t *tab2 = lv_tabview_add_tab(tv, "Tab 2"); + lv_obj_t *tab3 = lv_tabview_add_tab(tv, "Tab 3"); + + create_tab1(th, tab1); + create_tab2(th, tab2); + create_tab3(th, tab3); + + lv_tabview_set_current_tab(tv, 2, false); + +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +static void create_tab1(lv_theme_t * th, lv_obj_t *parent) +{ + lv_page_set_scrl_layout(parent, LV_CONT_LAYOUT_PRETTY); + + static lv_style_t h_style; + lv_style_copy(&h_style, &lv_style_transp); + h_style.body.padding.inner = LV_DPI / 4; + h_style.body.padding.hor = LV_DPI / 4; + h_style.body.padding.ver = LV_DPI / 6; + + lv_obj_t *h = lv_cont_create(parent, NULL); + lv_obj_set_style(h, &h_style); + lv_cont_set_fit(h, true, true); + lv_cont_set_layout(h, LV_CONT_LAYOUT_COL_M); + + lv_obj_t *btn = lv_btn_create(h, NULL); + lv_btn_set_style(btn, LV_BTN_STYLE_REL, th->btn.sm.rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, th->btn.sm.pr); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_REL, th->btn.sm.tgl_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_PR, th->btn.sm.tgl_pr); + lv_btn_set_style(btn, LV_BTN_STYLE_INA, th->btn.sm.ina); + lv_btn_set_fit(btn, true, true); + lv_btn_set_toggle(btn, true); + lv_obj_t *btn_label = lv_label_create(btn, NULL); + lv_label_set_text(btn_label, "Small"); + + btn = lv_btn_create(h, btn); + lv_btn_toggle(btn); + btn_label = lv_label_create(btn, NULL); + lv_label_set_text(btn_label, "Toggled"); + + btn = lv_btn_create(h, btn); + lv_btn_set_state(btn, LV_BTN_STATE_INA); + btn_label = lv_label_create(btn, NULL); + lv_label_set_text(btn_label, "Inactive"); + + btn = lv_btn_create(h, btn); + lv_btn_set_state(btn, LV_BTN_STATE_REL); + + btn_label = lv_label_create(btn, NULL); + lv_label_set_text(btn_label, "Medium"); + + btn = lv_btn_create(h, btn); + lv_btn_set_style(btn, LV_BTN_STYLE_REL, th->btn.lg.rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, th->btn.lg.pr); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_REL, th->btn.lg.tgl_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_PR, th->btn.lg.tgl_pr); + lv_btn_set_style(btn, LV_BTN_STYLE_INA, th->btn.lg.ina); + btn_label = lv_label_create(btn, NULL); + lv_label_set_text(btn_label, "Large"); + + lv_obj_t *label = lv_label_create(h, NULL); + lv_label_set_text(label, "Small"); + lv_obj_set_style(label, th->label.sm); + + label = lv_label_create(h, NULL); + lv_label_set_text(label, "Medium"); + lv_obj_set_style(label, th->label.md); + + label = lv_label_create(h, NULL); + lv_label_set_text(label, "Large"); + lv_obj_set_style(label, th->label.lg); + lv_obj_set_protect(label, LV_PROTECT_FOLLOW); + + h = lv_cont_create(parent, h); + + lv_obj_t *sw_h = lv_cont_create(h, NULL); + lv_cont_set_style(sw_h, &lv_style_transp); + lv_cont_set_fit(sw_h, false, true); + lv_obj_set_width(sw_h, LV_HOR_RES / 4); + lv_cont_set_layout(sw_h, LV_CONT_LAYOUT_PRETTY); + + lv_obj_t *sw = lv_sw_create(sw_h, NULL); + + sw = lv_sw_create(sw_h, sw); + lv_sw_set_on(sw); + + lv_obj_t *bar = lv_bar_create(h, NULL); + lv_bar_set_value(bar, 70); + + lv_obj_t *slider = lv_slider_create(h, NULL); + lv_obj_set_height(slider, LV_DPI / 2); + lv_bar_set_value(slider, 70); + + lv_obj_t *line = lv_line_create(h, NULL); + static const point_t line_p[] = {{0,0},{LV_HOR_RES / 5, 0}}; + lv_line_set_points(line, line_p, 2); + lv_line_set_style(line, th->line.decor); + + lv_obj_t *ta = lv_ta_create(h, NULL); + lv_obj_set_style(ta, th->ta.oneline); + lv_ta_set_text(ta, "Some text"); + lv_ta_set_one_line(ta, true); + + lv_obj_t *cb = lv_cb_create(h, NULL); + + cb = lv_cb_create(h, cb); + lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL); + + + lv_obj_t *ddlist = lv_ddlist_create(h, NULL); + lv_ddlist_open(ddlist, false); + lv_ddlist_set_selected(ddlist, 1); + + + static const char *btnm_str[] = {"1", "2", "3", SYMBOL_OK, SYMBOL_CLOSE, ""}; + + lv_obj_t *btnm = lv_btnm_create(h, NULL); + lv_obj_set_size(btnm,LV_HOR_RES / 4, 2 * LV_DPI / 3); + lv_btnm_set_map(btnm, btnm_str); + ((lv_btnm_ext_t *) btnm->ext_attr)->btn_id_pr = 3; /*Hack to show a button pressed*/ + + h = lv_cont_create(parent, h); + + lv_obj_t * list = lv_list_create(h, NULL); + lv_list_add(list, SYMBOL_GPS, "GPS", NULL); + lv_list_add(list, SYMBOL_WIFI, "WiFi", NULL); + lv_list_add(list, SYMBOL_CALL, "Call", NULL); + lv_list_add(list, SYMBOL_BELL, "Bell", NULL); + lv_list_add(list, SYMBOL_FILE, "File", NULL); + lv_list_add(list, SYMBOL_EDIT, "Edit", NULL); + lv_list_add(list, SYMBOL_CUT, "Cut", NULL); + lv_list_add(list, SYMBOL_COPY, "Copy", NULL); + + lv_obj_t *roller = lv_roller_create(h, NULL); + lv_roller_set_options(roller, "Monday\nTuesday\nWednesday\nThursday\nFriday\nSaturday\nSunday"); + lv_obj_set_height(roller, LV_DPI); + + lv_obj_t *gauge = lv_gauge_create(h, NULL); + lv_gauge_set_value(gauge, 0, 40); + lv_obj_set_size(gauge, 3 * LV_DPI / 2, 3 * LV_DPI / 2); +} + +static void create_tab2(lv_theme_t * th, lv_obj_t *parent) +{ + cord_t w = lv_page_get_scrl_width(parent); + + lv_obj_t *chart = lv_chart_create(parent, NULL); + lv_chart_series_t * s1 = lv_chart_add_series(chart, COLOR_RED); + lv_chart_set_next(chart, s1, 30); + lv_chart_set_next(chart, s1, 20); + lv_chart_set_next(chart, s1, 10); + lv_chart_set_next(chart, s1, 12); + lv_chart_set_next(chart, s1, 20); + lv_chart_set_next(chart, s1, 27); + lv_chart_set_next(chart, s1, 35); + lv_chart_set_next(chart, s1, 55); + lv_chart_set_next(chart, s1, 70); + lv_chart_set_next(chart, s1, 75); + + lv_obj_t *ta = lv_ta_create(parent, NULL); + lv_obj_set_size(ta, w / 3, LV_VER_RES / 4); + lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + lv_ta_set_cursor_type(ta, LV_TA_CURSOR_BLOCK); + + lv_obj_t *kb = lv_kb_create(parent, NULL); + lv_obj_set_size(kb, w / 2, LV_VER_RES / 3); + lv_obj_align(kb, ta, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, LV_DPI / 4); + lv_kb_set_ta(kb, ta); +} + + +static void create_tab3(lv_theme_t * th, lv_obj_t *parent) +{ + lv_obj_t *win = lv_win_create(parent, NULL); + lv_win_add_btn(win, SYMBOL_CLOSE, lv_win_close_action); + lv_win_add_btn(win, SYMBOL_DOWN, NULL); + lv_obj_set_size(win, LV_HOR_RES / 2, LV_VER_RES / 2); + lv_obj_set_top(win, true); + + lv_obj_t *label = lv_label_create(win, NULL); + lv_label_set_text(label, "Label in the window"); + + lv_obj_t *lmeter = lv_lmeter_create(win, NULL); + lv_obj_align(lmeter, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 2); + lv_lmeter_set_value(lmeter, 70); + + lv_obj_t *led1 = lv_led_create(win, NULL); + lv_obj_align(led1, lmeter, LV_ALIGN_OUT_BOTTOM_MID, 0, LV_DPI / 2); + lv_led_on(led1); + + lv_obj_t *led2 = lv_led_create(win, NULL); + lv_obj_align(led2, led1, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 2, 0); + lv_led_off(led2); + + + lv_obj_t *page = lv_page_create(parent, NULL); + lv_obj_set_size(page, LV_HOR_RES / 3, LV_VER_RES / 2); + lv_obj_set_top(page, true); + lv_obj_align(page, win, LV_ALIGN_IN_TOP_RIGHT, LV_DPI, LV_DPI); + + label = lv_label_create(page, NULL); + lv_label_set_text(label, "Lorem ipsum dolor sit amet, repudiare voluptatibus pri cu. " + "Ei mundi pertinax posidonium eum, cum tempor maiorum at, " + "mea fuisset assentior ad. Usu cu suas civibus iudicabit. " + "Eum eu congue tempor facilisi. Tale hinc unum te vim. " + "Te cum populo animal eruditi, labitur inciderint at nec.\n\n" + "Eius corpora et quo. Everti voluptaria instructior est id, " + "vel in falli primis. Mea ei porro essent admodum, " + "his ei malis quodsi, te quis aeterno his. " + "Qui tritani recusabo reprehendunt ne, " + "per duis explicari at. Simul mediocritatem mei et."); + lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); + lv_obj_set_width(label, lv_page_get_scrl_width(page)); + + + static const char * mbox_btn_map[] = {"\211", "\222Got it!", "\211", ""}; + lv_obj_t *mbox = lv_mbox_create(parent, NULL); + lv_mbox_set_text(mbox, "Click on the window or the page to bring it to the foreground"); + lv_mbox_set_btns(mbox, mbox_btn_map, NULL); + lv_obj_set_top(mbox, true); +} + + diff --git a/lv_themes/lv_theme.h b/lv_themes/lv_theme.h new file mode 100644 index 000000000..6d30d6ee6 --- /dev/null +++ b/lv_themes/lv_theme.h @@ -0,0 +1,287 @@ +/** + *@file lv_themes.h + * + */ + +#ifndef LV_THEMES_H +#define LV_THEMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#include "lvgl/lv_obj/lv_style.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_style_t *bg; + lv_style_t *panel; + +#if USE_LV_CONT != 0 + struct { + lv_style_t *filled; + lv_style_t *frame; + }cont; +#endif +#if USE_LV_BTN != 0 + struct { + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + }sm; + + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + }md; + + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + }lg; + }btn; +#endif + +#if USE_LV_LABEL != 0 + struct { + lv_style_t *sm; + lv_style_t *md; + lv_style_t *lg; + }label; +#endif + +#if USE_LV_IMG != 0 + struct { + lv_style_t *light; + lv_style_t *dark; + }img; +#endif + +#if USE_LV_LINE != 0 + struct { + lv_style_t *decor; + }line; +#endif + +#if USE_LV_LED != 0 + lv_style_t *led; +#endif + +#if USE_LV_BAR != 0 + struct { + lv_style_t *bg; + lv_style_t *indic; + }bar; +#endif + +#if USE_LV_SLIDER != 0 + struct { + lv_style_t *bg; + lv_style_t *indic; + lv_style_t *knob; + }slider; +#endif + +#if USE_LV_LMETER != 0 + lv_style_t *lmeter; +#endif + +#if USE_LV_GAUGE != 0 + lv_style_t *gauge; +#endif + +#if USE_LV_SW != 0 + struct { + lv_style_t *bg; + lv_style_t *indic; + lv_style_t *knob_off; + lv_style_t *knob_on; + }sw; +#endif + +#if USE_LV_CHART != 0 + lv_style_t *chart; +#endif + +#if USE_LV_CB != 0 + struct { + lv_style_t *bg; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + }box; + }cb; +#endif + +#if USE_LV_BTNM != 0 + struct { + lv_style_t *bg; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + }btn; + }btnm; +#endif + +#if USE_LV_KB != 0 + struct { + lv_style_t *bg; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } btn; + }kb; +#endif + +#if USE_LV_MBOX != 0 + struct { + lv_style_t *bg; + struct { + lv_style_t *bg; + lv_style_t *rel; + lv_style_t *pr; + }btn; + }mbox; +#endif + +#if USE_LV_PAGE != 0 + struct { + lv_style_t *bg; + lv_style_t *scrl; + lv_style_t *sb; + }page; +#endif + +#if USE_LV_TA != 0 + struct { + lv_style_t *area; + lv_style_t *oneline; + lv_style_t *sb; + }ta; +#endif + +#if USE_LV_LIST + struct { + lv_style_t *bg; + lv_style_t *scrl; + lv_style_t *sb; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + }btn; + }list; +#endif + +#if USE_LV_DDLIST != 0 + struct { + lv_style_t *bg; + lv_style_t *sel; + lv_style_t *sb; + }ddlist; +#endif + +#if USE_LV_ROLLER != 0 + struct { + lv_style_t *bg; + lv_style_t *sel; + }roller; +#endif + +#if USE_LV_TABVIEW != 0 + struct { + lv_style_t *bg; + lv_style_t *sb; + lv_style_t *indic; + struct { + lv_style_t *bg; + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + }btn; + }tabview; +#endif + +#if USE_LV_WIN != 0 + struct { + lv_style_t *bg; + lv_style_t *sb; + lv_style_t *header; + lv_style_t *content; + struct { + lv_style_t *rel; + lv_style_t *pr; + }btn; + }win; +#endif +}lv_theme_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Set a theme for the system. + * From now, all the created objects will use styles from this theme by default + * @param th pointer to theme (return value of: 'lv_theme_init_xxx()') + */ +void lv_theme_set_current(lv_theme_t *th); + +/** + * Get the current system theme. + * @return pointer to the current system theme. NULL if not set. + */ +lv_theme_t * lv_theme_get_current(void); + +/** + * Create a test screen with a lot objects and apply the given theme on them + * @param th pointer to a theme + */ +void lv_theme_create_test_screen(lv_theme_t *th); + +/********************** + * MACROS + **********************/ + +/********************** + * POST INCLUDE + *********************/ +#include "lv_theme_alien.h" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_THEMES_H*/ diff --git a/lv_themes/lv_theme_alien.c b/lv_themes/lv_theme_alien.c new file mode 100644 index 000000000..2c87a8962 --- /dev/null +++ b/lv_themes/lv_theme_alien.c @@ -0,0 +1,816 @@ +/** + * @file lv_theme_alien.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lvgl/lvgl.h" +#include "lv_theme.h" + +#include "lv_conf.h" + +#if USE_LV_THEME_ALIEN + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ +static lv_theme_t theme; +static lv_style_t def; +static lv_style_t bg; +static lv_style_t panel; /*General fancy background (for e.g. chart or ta)*/ +static lv_style_t sb; +static lv_style_t label_sm, label_md, label_lg; +static lv_style_t btn_sm_rel, btn_sm_pr, btn_sm_trel, btn_sm_tpr, btn_sm_ina; +static lv_style_t btn_md_rel, btn_md_pr, btn_md_trel, btn_md_tpr, btn_md_ina; +static lv_style_t btn_lg_rel, btn_lg_pr, btn_lg_trel, btn_lg_tpr, btn_lg_ina; +static lv_style_t img_light, img_dark; +static lv_style_t line_decor; +static lv_style_t led; +static lv_style_t bar_bg, bar_indic; +static lv_style_t slider_knob; +static lv_style_t sw_bg, sw_indic, sw_knob; +static lv_style_t lmeter_bg; +static lv_style_t gauge_bg; +static lv_style_t list_bg, list_rel, list_pr, list_trel, list_tpr, list_ina; +static lv_style_t ddlist_bg, ddlist_sel; +static lv_style_t roller_bg, roller_sel; +static lv_style_t cb_bg, cb_rel, cb_pr, cb_trel, cb_tpr, cb_ina; +static lv_style_t btnm_bg, btnm_rel, btnm_pr, btnm_trel, btnm_ina; +static lv_style_t mbox_bg, mbox_btn_rel, mbox_btn_pr; +static lv_style_t tab_rel, tab_pr, tab_trel, tab_tpr, tab_indic; +static lv_style_t win_header; + +static uint16_t _hue; +static font_t * _font_sm; +static font_t * _font_md; +static font_t * _font_lg; + +/********************** + * MACROS + **********************/ + +/********************** + * STATIC FUNCTIONS + **********************/ + +static void basic_init(void) +{ + /*Default*/ + lv_style_copy(&def, &lv_style_plain); + def.body.opa = OPA_COVER; + def.glass = 0; + + def.body.empty = 0; + def.body.color_main = COLOR_HEX3(0x222); + def.body.color_gradient = COLOR_HEX3(0x222); + def.body.radius = 0; + def.body.padding.hor = LV_DPI / 8; + def.body.padding.ver = LV_DPI / 8; + def.body.padding.inner = LV_DPI / 8; + def.body.border.color = COLOR_SILVER; + def.body.border.width = 1 << LV_ANTIALIAS; + def.body.border.opa = OPA_COVER; + def.body.shadow.color = COLOR_SILVER; + def.body.shadow.width = 0; + def.body.shadow.type = LV_SHADOW_FULL; + + def.text.color = COLOR_HEX3(0xDDD); + def.text.font = _font_sm; + def.text.letter_space = 1 << LV_ANTIALIAS; + def.text.line_space = 2 << LV_ANTIALIAS; + + def.image.color = COLOR_HEX3(0xDDD); + def.image.intense = OPA_TRANSP; + + def.line.color = COLOR_HEX3(0xDDD); + def.line.width = 1 << LV_ANTIALIAS; + + /*Background*/ + lv_style_copy(&bg, &def); + bg.body.color_main = COLOR_HEX3(0x333); + bg.body.color_gradient = COLOR_HEX3(0x333); + bg.body.border.width = 0; + bg.body.border.opa = OPA_70; + bg.body.shadow.color = COLOR_SILVER; + + /*Panel*/ + lv_style_copy(&panel, &def); + panel.body.radius = LV_DPI / 10; + panel.body.color_main = COLOR_HEX3(0x666); + panel.body.color_gradient = COLOR_HEX3(0x666); + panel.body.border.color = COLOR_HEX3(0xccc); + panel.body.border.width = 2 << LV_ANTIALIAS; + panel.body.border.opa = OPA_60; + panel.text.color = color_hsv_to_rgb(_hue, 8, 96); + panel.line.color = color_hsv_to_rgb(_hue, 20, 70); + + /*Scrollbar*/ + lv_style_copy(&sb, &def); + sb.body.opa = OPA_50; + sb.body.radius = LV_RADIUS_CIRCLE; + sb.body.border.color = COLOR_SILVER; + sb.body.border.opa = OPA_40; + sb.body.border.width = 1 << LV_ANTIALIAS; + sb.body.color_main = color_hsv_to_rgb(_hue, 33, 92); + sb.body.color_gradient = color_hsv_to_rgb(_hue, 33, 92); + sb.body.padding.hor = 1 << LV_ANTIALIAS; + sb.body.padding.ver = 1 << LV_ANTIALIAS; + sb.body.padding.inner = LV_DPI / 15; /*Scrollbar width*/ + + theme.bg = &bg; + theme.panel = &panel; + +} + +static void btn_init(void) +{ +#if USE_LV_BTN != 0 + lv_style_copy(&btn_sm_rel, &def); + btn_sm_rel.glass = 0; + btn_sm_rel.body.empty = 1; + btn_sm_rel.body.radius = LV_RADIUS_CIRCLE; + btn_sm_rel.body.border.width = 2 << LV_ANTIALIAS; + btn_sm_rel.body.border.color = color_hsv_to_rgb(_hue, 70, 90); + btn_sm_rel.body.border.opa = OPA_80; + btn_sm_rel.body.padding.hor = LV_DPI / 4; + btn_sm_rel.body.padding.ver = LV_DPI / 6; + btn_sm_rel.body.padding.inner = LV_DPI / 10; + btn_sm_rel.text.color = color_hsv_to_rgb(_hue, 8, 96); + btn_sm_rel.text.font = _font_sm; + + lv_style_copy(&btn_sm_pr, &btn_sm_rel); + btn_sm_pr.body.opa = OPA_COVER; + btn_sm_pr.body.empty = 0; + btn_sm_pr.body.color_main = color_hsv_to_rgb(_hue, 50, 50); + btn_sm_pr.body.color_gradient = color_hsv_to_rgb(_hue, 50, 50); + btn_sm_pr.body.border.opa = OPA_60; + btn_sm_pr.text.font = _font_sm; + btn_sm_pr.text.color = color_hsv_to_rgb(_hue, 10, 100); + + lv_style_copy(&btn_sm_trel, &btn_sm_pr); + btn_sm_trel.body.opa = OPA_COVER; + btn_sm_trel.body.empty = 0; + btn_sm_trel.body.color_main = color_hsv_to_rgb(_hue, 50, 60); + btn_sm_trel.body.color_gradient = color_hsv_to_rgb(_hue, 50, 60); + btn_sm_trel.body.border.opa = OPA_60; + btn_sm_trel.body.border.color = color_hsv_to_rgb(_hue, 80, 90); + btn_sm_trel.text.font = _font_sm; + btn_sm_trel.text.color = color_hsv_to_rgb(_hue, 0, 100); + + lv_style_copy(&btn_sm_tpr, &btn_sm_trel); + btn_sm_tpr.body.opa = OPA_COVER; + btn_sm_tpr.body.empty = 0; + btn_sm_tpr.body.color_main = color_hsv_to_rgb(_hue, 50, 50); + btn_sm_tpr.body.color_gradient = color_hsv_to_rgb(_hue, 50, 50); + btn_sm_tpr.body.border.opa = OPA_60; + btn_sm_tpr.body.border.color = color_hsv_to_rgb(_hue, 80, 70); + btn_sm_tpr.text.font = _font_sm; + btn_sm_tpr.text.color = color_hsv_to_rgb(_hue, 10, 90); + + lv_style_copy(&btn_sm_ina, &btn_sm_rel); + btn_sm_ina.body.border.opa = OPA_60; + btn_sm_ina.body.border.color = color_hsv_to_rgb(_hue, 10, 50); + btn_sm_ina.text.font = _font_sm; + btn_sm_ina.text.color = color_hsv_to_rgb(_hue, 10, 90); + + lv_style_copy(&btn_md_rel, &btn_sm_rel); + btn_md_rel.body.padding.hor = LV_DPI / 3; + btn_md_rel.body.padding.ver = LV_DPI / 5; + btn_md_rel.body.padding.inner = LV_DPI / 8; + btn_md_rel.text.font = _font_md; + + lv_style_copy(&btn_md_pr, &btn_sm_pr); + btn_md_pr.body.padding.hor = LV_DPI / 3; + btn_md_pr.body.padding.ver = LV_DPI / 5; + btn_md_pr.body.padding.inner = LV_DPI / 8; + btn_md_pr.text.font = _font_md; + + lv_style_copy(&btn_md_trel, &btn_sm_trel); + btn_md_trel.body.padding.hor = LV_DPI / 3; + btn_md_trel.body.padding.ver = LV_DPI / 5; + btn_md_trel.body.padding.inner = LV_DPI / 8; + btn_md_trel.text.font = _font_md; + + lv_style_copy(&btn_md_tpr, &btn_sm_tpr); + btn_md_tpr.body.padding.hor = LV_DPI / 3; + btn_md_tpr.body.padding.ver = LV_DPI / 5; + btn_md_tpr.body.padding.inner = LV_DPI / 8; + btn_md_tpr.text.font = _font_md; + + lv_style_copy(&btn_md_ina, &btn_sm_ina); + btn_md_ina.body.padding.hor = LV_DPI / 3; + btn_md_ina.body.padding.ver = LV_DPI / 5; + btn_md_ina.body.padding.inner = LV_DPI / 8; + btn_md_ina.text.font = _font_md; + + lv_style_copy(&btn_lg_rel, &btn_sm_rel); + btn_lg_rel.body.padding.hor = LV_DPI / 2; + btn_lg_rel.body.padding.ver = LV_DPI / 4; + btn_lg_rel.body.padding.inner = LV_DPI / 6; + btn_lg_rel.text.font = _font_lg; + + lv_style_copy(&btn_lg_pr, &btn_sm_pr); + btn_lg_pr.body.padding.hor = LV_DPI / 2; + btn_lg_pr.body.padding.ver = LV_DPI / 4; + btn_lg_pr.body.padding.inner = LV_DPI / 6; + btn_lg_pr.text.font = _font_lg; + + lv_style_copy(&btn_lg_trel, &btn_sm_trel); + btn_lg_trel.body.padding.hor = LV_DPI / 2; + btn_lg_trel.body.padding.ver = LV_DPI / 4; + btn_lg_trel.body.padding.inner = LV_DPI / 6; + btn_lg_trel.text.font = _font_lg; + + lv_style_copy(&btn_lg_tpr, &btn_sm_tpr); + btn_lg_tpr.body.padding.hor = LV_DPI / 2; + btn_lg_tpr.body.padding.ver = LV_DPI / 4; + btn_lg_tpr.body.padding.inner = LV_DPI / 6; + btn_lg_tpr.text.font = _font_lg; + + lv_style_copy(&btn_lg_ina, &btn_sm_ina); + btn_lg_ina.body.padding.hor = LV_DPI / 2; + btn_lg_ina.body.padding.ver = LV_DPI / 4; + btn_lg_ina.body.padding.inner = LV_DPI / 6; + btn_lg_ina.text.font = _font_lg; + + theme.btn.sm.rel = &btn_sm_rel; + theme.btn.sm.pr = &btn_sm_pr; + theme.btn.sm.tgl_rel = &btn_sm_trel; + theme.btn.sm.tgl_pr = &btn_sm_tpr; + theme.btn.sm.ina = &btn_sm_ina; + theme.btn.md.rel = &btn_md_rel; + theme.btn.md.pr = &btn_md_pr; + theme.btn.md.tgl_rel = &btn_md_trel; + theme.btn.md.tgl_pr = &btn_md_tpr; + theme.btn.md.ina = &btn_md_ina; + theme.btn.lg.rel = &btn_lg_rel; + theme.btn.lg.pr = &btn_lg_pr; + theme.btn.lg.tgl_rel = &btn_lg_trel; + theme.btn.lg.tgl_pr = &btn_lg_tpr; + theme.btn.lg.ina = &btn_lg_ina; +#endif +} + + +static void label_init(void) +{ +#if USE_LV_LABEL != 0 + lv_style_copy(&label_sm, &def); + label_sm.text.font = _font_sm; + label_sm.text.color = color_hsv_to_rgb(_hue, 8, 96); + + lv_style_copy(&label_md, &label_sm); + label_md.text.font = _font_md; + + lv_style_copy(&label_lg, &label_sm); + label_lg.text.font = _font_lg; + + theme.label.sm = &label_sm; + theme.label.md = &label_md; + theme.label.lg = &label_lg; +#endif +} + + +static void bar_init(void) +{ +#if USE_LV_BAR + lv_style_copy(&bar_bg, &def); + bar_bg.body.opa = OPA_30; + bar_bg.body.radius = LV_RADIUS_CIRCLE; + bar_bg.body.color_main = COLOR_WHITE; + bar_bg.body.color_gradient = COLOR_SILVER; + bar_bg.body.border.width = 2 << LV_ANTIALIAS; + bar_bg.body.border.color = COLOR_SILVER; + bar_bg.body.border.opa = OPA_20; + bar_bg.body.padding.hor = 0; + bar_bg.body.padding.ver = LV_DPI / 6; + bar_bg.body.padding.inner = 0; + + lv_style_copy(&bar_indic, &def); + bar_indic.body.radius = LV_RADIUS_CIRCLE; + bar_indic.body.border.width = 2 << LV_ANTIALIAS; + bar_indic.body.border.color = COLOR_SILVER; + bar_indic.body.border.opa = OPA_70; + bar_indic.body.padding.hor = 0; + bar_indic.body.padding.ver = 0; + bar_indic.body.shadow.width = LV_DPI / 12; + bar_indic.body.color_main = color_hsv_to_rgb(_hue, 40, 80); + bar_indic.body.color_gradient = color_hsv_to_rgb(_hue, 40, 80); + + theme.bar.bg = &bar_bg; + theme.bar.indic = &bar_indic; +#endif +} + +static void img_init(void) +{ +#if USE_LV_IMG != 0 + lv_style_copy(&img_light, &def); + img_light.image.color = color_hsv_to_rgb(_hue, 15, 85); + img_light.image.intense = OPA_80; + + lv_style_copy(&img_dark, &def); + img_light.image.color = color_hsv_to_rgb(_hue, 85, 65); + img_light.image.intense = OPA_80; + + theme.img.light = &img_light; + theme.img.dark = &img_dark; +#endif +} + +static void line_init(void) +{ +#if USE_LV_LINE != 0 + lv_style_copy(&line_decor, &def); + line_decor.line.color = color_hsv_to_rgb(_hue, 50, 50); + line_decor.line.width = 1 << LV_ANTIALIAS; + + theme.line.decor = &line_decor; +#endif +} + +static void led_init(void) +{ +#if USE_LV_LED != 0 + lv_style_copy(&led, &lv_style_pretty_color); + led.body.shadow.width = LV_DPI / 10; + led.body.radius = LV_RADIUS_CIRCLE; + led.body.border.width= LV_DPI / 30; + led.body.border.opa = OPA_30; + led.body.color_main = color_hsv_to_rgb(_hue, 100, 100); + led.body.color_gradient = color_hsv_to_rgb(_hue, 100, 40); + led.body.border.color = color_hsv_to_rgb(_hue, 60, 60); + led.body.shadow.color = color_hsv_to_rgb(_hue, 100, 100); + + theme.led = &led; +#endif +} + +static void slider_init(void) +{ +#if USE_LV_SLIDER != 0 + lv_style_copy(&slider_knob, &def); + slider_knob.body.opa = OPA_60; + slider_knob.body.radius = LV_RADIUS_CIRCLE; + slider_knob.body.color_main = COLOR_WHITE; + slider_knob.body.color_gradient = COLOR_SILVER; + slider_knob.body.border.width = 1 << LV_ANTIALIAS; + slider_knob.body.border.color = COLOR_GRAY; + slider_knob.body.border.opa = OPA_50; + + theme.slider.bg = &bar_bg; + theme.slider.indic = &bar_indic; + theme.slider.knob = &slider_knob; +#endif +} + +static void sw_init(void) +{ +#if USE_LV_SW != 0 + lv_style_copy(&sw_bg, &bar_bg); + sw_bg.body.opa = OPA_COVER; + sw_bg.body.padding.ver = -2 << LV_ANTIALIAS; + sw_bg.body.padding.hor = -2 << LV_ANTIALIAS; + sw_bg.body.color_main = COLOR_HEX3(0x666); + sw_bg.body.color_gradient = COLOR_HEX3(0x999); + sw_bg.body.border.width = 2 << LV_ANTIALIAS; + sw_bg.body.border.opa = OPA_50; + + lv_style_copy(&sw_indic, &bar_indic); + sw_indic.body.shadow .width = LV_DPI / 12; + sw_indic.body.padding.ver = 0; + sw_indic.body.padding.hor = 0; + + lv_style_copy(&sw_knob, &slider_knob); + sw_knob.body.opa = OPA_80; + + theme.sw.bg = &sw_bg; + theme.sw.indic = &sw_indic; + theme.sw.knob_off = &sw_knob; + theme.sw.knob_on = &sw_knob; +#endif +} + + +static void lmeter_init(void) +{ +#if USE_LV_LMETER != 0 + lv_style_copy(&lmeter_bg, &def); + lmeter_bg.body.color_main = color_hsv_to_rgb(_hue, 10, 70); + lmeter_bg.body.color_gradient = color_hsv_to_rgb(_hue, 80, 80); + lmeter_bg.body.padding.hor = LV_DPI / 8; /*Scale line length*/ + lmeter_bg.line.color = COLOR_HEX3(0x555); + lmeter_bg.line.width = 2 << LV_ANTIALIAS; + + theme.lmeter = &lmeter_bg; + +#endif +} + +static void gauge_init(void) +{ +#if USE_LV_GAUGE != 0 + lv_style_copy(&gauge_bg, &def); + gauge_bg.body.color_main = color_hsv_to_rgb(_hue, 10, 70); + gauge_bg.body.color_gradient = color_hsv_to_rgb(_hue, 80, 80); + gauge_bg.body.padding.hor = LV_DPI / 12; /*Scale line length*/ + gauge_bg.body.padding.ver = LV_DPI / 10; /*Needle center size*/ + gauge_bg.body.padding.inner = LV_DPI / 8; /*Label - scale distance*/ + gauge_bg.body.border.color = COLOR_HEX3(0x777); + gauge_bg.line.color = COLOR_HEX3(0x555); + gauge_bg.line.width = 2 << LV_ANTIALIAS; + gauge_bg.text.color = color_hsv_to_rgb(_hue, 10, 90); + gauge_bg.text.font = _font_sm; + + theme.gauge = &gauge_bg; +#endif +} + +static void chart_init(void) +{ +#if USE_LV_CHART + theme.chart = &panel; +#endif +} + +static void cb_init(void) +{ + +#if USE_LV_CB != 0 + lv_style_copy(&cb_rel, &bg); + cb_rel.body.radius = LV_DPI / 20; + cb_rel.body.border.width = 1 << LV_ANTIALIAS; + cb_rel.body.border.color = COLOR_GRAY; + cb_rel.body.color_main = COLOR_WHITE; + cb_rel.body.color_gradient = COLOR_SILVER; + + lv_style_copy(&cb_bg, &bg); + cb_bg.body.empty = 1; + cb_bg.body.border.width = 0; + cb_bg.body.padding.inner = LV_DPI / 8; + cb_bg.body.padding.hor = 0; + cb_bg.body.padding.ver = 0; + cb_bg.text.font = _font_sm; + + lv_style_copy(&cb_pr, &cb_rel); + cb_pr.body.color_main = color_hsv_to_rgb(_hue, 10, 90); + cb_pr.body.color_main = color_hsv_to_rgb(_hue, 10, 82); + + lv_style_copy(&cb_trel, &cb_rel); + cb_trel.body.border.width = 4 << LV_ANTIALIAS; + cb_trel.body.border.color = COLOR_WHITE; + cb_trel.body.border.opa = OPA_60; + cb_trel.body.color_main = color_hsv_to_rgb(_hue, 50, 82); + cb_trel.body.color_gradient = color_hsv_to_rgb(_hue, 50, 62); + + lv_style_copy(&cb_tpr, &cb_trel); + cb_tpr.body.border.color = COLOR_SILVER; + cb_tpr.body.border.opa = OPA_70; + cb_tpr.body.color_main = color_hsv_to_rgb(_hue, 50, 72); + cb_tpr.body.color_gradient = color_hsv_to_rgb(_hue, 50, 52); + + lv_style_copy(&cb_ina, &cb_trel); + cb_ina.body.border.width = 1 << LV_ANTIALIAS; + cb_ina.body.border.color = COLOR_GRAY; + cb_ina.body.color_main = COLOR_SILVER; + cb_ina.body.color_gradient = COLOR_SILVER; + + theme.cb.bg = &cb_bg; + theme.cb.box.rel = &cb_rel; + theme.cb.box.pr = &cb_pr; + theme.cb.box.tgl_rel = &cb_trel; + theme.cb.box.tgl_pr = &cb_tpr; + theme.cb.box.ina = &cb_ina; +#endif +} + + +static void btnm_init(void) +{ +#if USE_LV_BTNM + lv_style_copy(&btnm_bg, &lv_style_transp_tight); + btnm_bg.body.border.width = 1 << LV_ANTIALIAS; + btnm_bg.body.border.color = color_hsv_to_rgb(_hue, 60, 80); + btnm_bg.body.border.opa = OPA_COVER; + btnm_bg.body.radius = LV_DPI / 8; + + lv_style_copy(&btnm_rel, &lv_style_plain); + btnm_rel.body.empty = 1; + btnm_rel.body.radius = LV_DPI / 8; + btnm_rel.text.color = color_hsv_to_rgb(_hue, 60, 80); + btnm_rel.text.font = _font_md; + + lv_style_copy(&btnm_pr, &lv_style_plain); + btnm_pr.body.color_main = color_hsv_to_rgb(_hue, 40, 70); + btnm_pr.body.color_gradient = color_hsv_to_rgb(_hue, 40, 70); + btnm_pr.body.radius = LV_DPI / 8; + btnm_pr.text.color = color_hsv_to_rgb(_hue, 40, 40); + btnm_pr.text.font = _font_md; + + lv_style_copy(&btnm_trel, &btnm_rel); + btnm_trel.body.border.color = color_hsv_to_rgb(_hue, 80, 80); + btnm_trel.body.border.width = 3 << LV_ANTIALIAS; + + lv_style_copy(&btnm_ina, &btnm_rel); + btnm_ina.text.color = color_hsv_to_rgb(_hue, 10, 60); + + theme.btnm.bg = &btnm_bg; + theme.btnm.btn.rel = &btnm_rel; + theme.btnm.btn.pr = &btnm_pr; + theme.btnm.btn.tgl_rel = &btnm_trel; + theme.btnm.btn.tgl_pr = &btnm_pr; + theme.btnm.btn.ina = &btnm_ina; +#endif +} + +static void kb_init(void) +{ +#if USE_LV_KB + theme.kb.bg = &btnm_bg; + theme.kb.btn.rel = &btnm_rel; + theme.kb.btn.pr = &btnm_pr; + theme.kb.btn.tgl_rel = &btnm_trel; + theme.kb.btn.tgl_pr = &btnm_pr; + theme.kb.btn.ina = &btnm_ina; +#endif + +} + +static void mbox_init(void) +{ +#if USE_LV_MBOX + lv_style_copy(&mbox_bg, &panel); + mbox_bg.body.shadow.width = LV_DPI / 12; + + theme.mbox.bg = &mbox_bg; + theme.mbox.btn.bg = &lv_style_transp; + theme.mbox.btn.rel = &btn_sm_trel; + theme.mbox.btn.pr = &btn_sm_tpr; +#endif +} + +static void page_init(void) +{ +#if USE_LV_PAGE + theme.page.bg = &panel; + theme.page.scrl = &lv_style_transp_fit; + theme.page.sb = &sb; +#endif +} + +static void ta_init(void) +{ +#if USE_LV_TA + theme.ta.area = &panel; + theme.ta.oneline = &panel; + theme.ta.sb = &sb; +#endif +} + +static void list_init(void) +{ +#if USE_LV_LIST != 0 + lv_style_copy(&list_rel, &def); + list_rel.body.empty = 1; + list_rel.body.border.width = 1 << LV_ANTIALIAS; + list_rel.body.border.color = color_hsv_to_rgb(_hue, 50, 85); + list_rel.body.border.opa = OPA_COVER; + list_rel.text.color = color_hsv_to_rgb(_hue, 10, 94); + list_rel.text.font = _font_sm; + + lv_style_copy(&list_pr, &list_rel); + list_pr.body.empty = 0; + list_pr.body.opa = OPA_COVER; + list_pr.body.color_main = color_hsv_to_rgb(_hue, 34, 41); + list_pr.body.color_gradient = color_hsv_to_rgb(_hue, 34, 41); + list_pr.text.color = color_hsv_to_rgb(_hue, 7, 96); + + lv_style_copy(&list_trel, &list_rel); + lv_style_copy(&list_tpr, &list_pr); + lv_style_copy(&list_ina, &def); + + lv_style_copy(&list_bg, &list_rel); + list_bg.body.padding.hor = 0; + list_bg.body.padding.ver = 0; + + theme.list.sb = &sb; + theme.list.bg = &list_bg; + theme.list.scrl = &lv_style_transp_tight; + theme.list.btn.rel = &list_rel; + theme.list.btn.pr = &list_pr; + theme.list.btn.tgl_rel = &list_trel; + theme.list.btn.tgl_pr = &list_tpr; + theme.list.btn.ina = &list_ina; +#endif +} + +static void ddlist_init(void) +{ +#if USE_LV_DDLIST != 0 + lv_style_copy(&ddlist_bg, &panel); + ddlist_bg.text.line_space = LV_DPI / 10; + + lv_style_copy(&ddlist_sel, &panel); + ddlist_sel.body.color_main = color_hsv_to_rgb(_hue, 45, 70); + ddlist_sel.body.color_gradient = color_hsv_to_rgb(_hue, 45, 70); + ddlist_sel.body.opa = OPA_COVER; + ddlist_sel.body.radius = 0; + + theme.ddlist.bg = &ddlist_bg; + theme.ddlist.sel = &ddlist_sel; + theme.ddlist.sb = &sb; +#endif +} + +static void roller_init(void) +{ +#if USE_LV_ROLLER != 0 + lv_style_copy(&roller_bg, &ddlist_bg); + roller_bg.text.line_space = LV_DPI / 6; + roller_bg.body.radius = LV_DPI / 20; + roller_bg.body.color_main = COLOR_HEX3(0x222); + roller_bg.body.color_gradient = COLOR_HEX3(0x999); + roller_bg.body.border.opa = OPA_30; + roller_bg.text.opa = OPA_70; + roller_bg.text.color = color_hsv_to_rgb(_hue, 20, 70); + roller_bg.body.shadow.width = LV_DPI / 20; + roller_bg.body.shadow.color = COLOR_HEX3(0x111); + + lv_style_copy(&roller_sel, &panel); + roller_sel.body.empty = 1; + roller_sel.body.radius = 0; + roller_sel.text.color = color_hsv_to_rgb(_hue, 55, 90); + + theme.roller.bg = &roller_bg; + theme.roller.sel = &roller_sel; +#endif +} + +static void tabview_init(void) +{ +#if USE_LV_TABVIEW != 0 + lv_style_copy(&tab_rel, &def); + tab_rel.body.color_main = COLOR_HEX3(0x666); + tab_rel.body.color_gradient = COLOR_HEX3(0x666); + tab_rel.body.padding.hor = 0; + tab_rel.body.padding.ver = 0; + tab_rel.body.padding.inner = 0; + tab_rel.body.border.width = 1 << LV_ANTIALIAS; + tab_rel.body.border.color = COLOR_SILVER; + tab_rel.body.border.opa = OPA_40; + tab_rel.text.color = COLOR_HEX3(0xDDD); + tab_rel.text.font = _font_sm; + + lv_style_copy(&tab_pr, &tab_rel); + tab_pr.body.color_main = COLOR_HEX3(0x444); + tab_pr.body.color_gradient = COLOR_HEX3(0x444); + + lv_style_copy(&tab_trel, &def); + tab_trel.body.empty = 1; + tab_trel.body.padding.hor = 0; + tab_trel.body.padding.ver = 0; + tab_trel.body.padding.inner = 0; + tab_trel.body.border.width = 1 << LV_ANTIALIAS; + tab_trel.body.border.color = COLOR_SILVER; + tab_trel.body.border.opa = OPA_40; + tab_trel.text.color = color_hsv_to_rgb(_hue, 10, 94); + tab_trel.text.font = _font_md; + + lv_style_copy(&tab_tpr, &def); + tab_tpr.body.color_main = COLOR_GRAY; + tab_tpr.body.color_gradient = COLOR_GRAY; + tab_tpr.body.padding.hor = 0; + tab_tpr.body.padding.ver = 0; + tab_tpr.body.padding.inner = 0; + tab_tpr.body.border.width = 1 << LV_ANTIALIAS; + tab_tpr.body.border.color = COLOR_SILVER; + tab_tpr.body.border.opa = OPA_40; + tab_tpr.text.color = color_hsv_to_rgb(_hue, 10, 94); + tab_tpr.text.font = _font_md; + + lv_style_copy(&tab_indic, &def); + tab_indic.body.border.width = 0; + tab_indic.body.color_main = color_hsv_to_rgb(_hue, 80, 87); + tab_indic.body.color_gradient = color_hsv_to_rgb(_hue, 80, 87); + tab_indic.body.padding.inner = LV_DPI / 10; /*Indicator height*/ + + theme.tabview.bg = &bg; + theme.tabview.indic = &tab_indic; + theme.tabview.btn.bg = &lv_style_transp_tight; + theme.tabview.btn.rel = &tab_rel; + theme.tabview.btn.pr = &tab_pr; + theme.tabview.btn.tgl_rel = &tab_trel; + theme.tabview.btn.tgl_pr = &tab_tpr; +#endif +} + + +static void win_init(void) +{ +#if USE_LV_WIN != 0 + lv_style_copy(&win_header, &def); + win_header.body.radius = panel.body.radius; + win_header.body.padding.hor = LV_DPI / 12; + win_header.body.padding.ver = LV_DPI / 12; + win_header.body.color_main = color_hsv_to_rgb(_hue, 20, 50); + win_header.body.color_gradient = win_header.body.color_main; + win_header.body.border.opa = panel.body.border.opa; + win_header.body.border.width = panel.body.border.width; + win_header.body.border.color = color_hsv_to_rgb(_hue, 20, 80); + win_header.text.color = color_hsv_to_rgb(_hue, 5, 100); + + theme.win.bg = &panel; + theme.win.sb = &sb; + theme.win.header = &win_header; + theme.win.content = &lv_style_transp; + theme.win.btn.rel = &btn_sm_rel; + theme.win.btn.pr = &btn_sm_pr; +#endif +} + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initalize the alien theme + * @param hue [0..360] hue value from HSV color space to define the theme's base color + * @param font_sm pointer to a small font (NULL to use the default) + * @param font_md pointer to a medium font (NULL to use the default) + * @param font_lg pointer to a large font (NULL to use the default) + */ +void lv_theme_alien_init(uint16_t hue, font_t *font_sm, font_t *font_md, font_t *font_lg) +{ + if(font_sm == NULL) font_sm = FONT_DEFAULT; + if(font_md == NULL) font_md = FONT_DEFAULT; + if(font_lg == NULL) font_lg = FONT_DEFAULT; + + + _hue = hue; + _font_sm = font_sm; + _font_md = font_md; + _font_lg = font_lg; + + /*For backward compatibility initialize all theme elements with a default style */ + uint16_t i; + lv_style_t **style_p = (lv_style_t**) &theme; + for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t*); i++) { + *style_p = &def; + style_p++; + } + + basic_init(); + btn_init(); + label_init(); + bar_init(); + img_init(); + line_init(); + led_init(); + slider_init(); + sw_init(); + lmeter_init(); + gauge_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(); +} + +/** + * Get a pointer to the theme + * @return pointer to the theme + */ +lv_theme_t * lv_theme_get_alien(void) +{ + return &theme; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#endif + diff --git a/lv_themes/lv_theme_alien.h b/lv_themes/lv_theme_alien.h new file mode 100644 index 000000000..47adb995c --- /dev/null +++ b/lv_themes/lv_theme_alien.h @@ -0,0 +1,56 @@ +/** + * @file lv_theme_alien.h + * + */ + +#ifndef LV_THEME_ALIEN_H +#define LV_THEME_ALIEN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" + +#if USE_LV_THEME_ALIEN + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +/** + * Initalize the alien theme + * @param hue [0..360] hue value from HSV color space to define the theme's base color + * @param font_sm pointer to a small font (NULL to use the default) + * @param font_md pointer to a medium font (NULL to use the default) + * @param font_lg pointer to a large font (NULL to use the default) + */ +void lv_theme_alien_init(uint16_t hue, font_t *font_sm, font_t *font_md, font_t *font_lg); + +/** + * Get a pointer to the theme + * @return pointer to the theme + */ +lv_theme_t * lv_theme_get_alien(void); + +/********************** + * MACROS + **********************/ + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_THEME_ALIEN_H*/ diff --git a/lvgl.h b/lvgl.h index d28872639..12e40987f 100644 --- a/lvgl.h +++ b/lvgl.h @@ -17,8 +17,12 @@ extern "C" { /*Test misc. module version*/ #include "misc/misc.h" #include "lv_hal/lv_hal.h" + #include "lv_obj/lv_obj.h" #include "lv_obj/lv_group.h" + +#include "lv_themes/lv_theme.h" + #include "lv_objx/lv_btn.h" #include "lv_objx/lv_img.h" #include "lv_objx/lv_label.h"