Romain BECAN / lvgl_RB
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lv_theme_rb.h Source File

lv_theme_rb.h

00001 /**
00002  * @file lv_theme_rb.c
00003  *
00004  */
00005 
00006 /*********************
00007  *      INCLUDES
00008  *********************/
00009 #include "lv_theme.h"
00010 
00011 
00012 /*********************
00013  *      DEFINES
00014  *********************/
00015 
00016 /**********************
00017  *      TYPEDEFS
00018  **********************/
00019 
00020 /**********************
00021  *  STATIC PROTOTYPES
00022  **********************/
00023 
00024 /**********************
00025  *  STATIC VARIABLES
00026  **********************/
00027 static lv_theme_t theme;
00028 static lv_style_t def;
00029 static lv_style_t scr;
00030 
00031 /*Static style definitions*/
00032 static lv_style_t sb;
00033 static lv_style_t plain_bordered;
00034 static lv_style_t label_prim;
00035 static lv_style_t label_sec;
00036 static lv_style_t label_hint;
00037 
00038 /*Saved input parameters*/
00039 static uint16_t _hue;
00040 static lv_font_t * _font;
00041 
00042 /**********************
00043  *      MACROS
00044  **********************/
00045 
00046 /**********************
00047  *   STATIC FUNCTIONS
00048  **********************/
00049 
00050 static void basic_init(void)
00051 {
00052     lv_style_copy(&def, &lv_style_pretty); /*Initialize the default style*/
00053 
00054     lv_style_copy(&scr, &def);
00055     scr.body.padding.bottom = 0;
00056     scr.body.padding.top    = 0;
00057     scr.body.padding.left   = 0;
00058     scr.body.padding.right  = 0;
00059 
00060     lv_style_copy(&sb, &lv_style_pretty_color);
00061     sb.body.grad_color     = sb.body.main_color;
00062     sb.body.padding.right  = sb.body.padding.right / 2; /*Make closer to the edges*/
00063     sb.body.padding.bottom = sb.body.padding.bottom / 2;
00064 
00065     lv_style_copy(&plain_bordered, &lv_style_plain);
00066     plain_bordered.body.border.width = 2;
00067     plain_bordered.body.border.color = lv_color_hex3(0xbbb);
00068 
00069     theme.style.bg    = &lv_style_plain;
00070     theme.style.scr   = &scr;
00071     theme.style.panel = &lv_style_pretty;
00072 }
00073 
00074 static void btn_init(void)
00075 {
00076 #if LV_USE_BTN != 0
00077     theme.style.btn.rel     = &lv_style_btn_rel;
00078     theme.style.btn.pr      = &lv_style_btn_pr;
00079     theme.style.btn.tgl_rel = &lv_style_btn_tgl_rel;
00080     theme.style.btn.tgl_pr  = &lv_style_btn_tgl_pr;
00081     theme.style.btn.ina     = &lv_style_btn_ina;
00082 #endif
00083 }
00084 
00085 static void label_init(void)
00086 {
00087 #if LV_USE_LABEL != 0
00088 
00089     lv_style_copy(&label_prim, &lv_style_plain);
00090     lv_style_copy(&label_sec, &lv_style_plain);
00091     lv_style_copy(&label_hint, &lv_style_plain);
00092 
00093     label_prim.text.color = lv_color_hex3(0x111);
00094     label_sec.text.color  = lv_color_hex3(0x888);
00095     label_hint.text.color = lv_color_hex3(0xaaa);
00096 
00097     theme.style.label.prim = &label_prim;
00098     theme.style.label.sec  = &label_sec;
00099     theme.style.label.hint = &label_hint;
00100 #endif
00101 }
00102 
00103 static void img_init(void)
00104 {
00105 #if LV_USE_IMG != 0
00106 
00107     theme.style.img.light = &def;
00108     theme.style.img.dark  = &def;
00109 #endif
00110 }
00111 
00112 static void line_init(void)
00113 {
00114 #if LV_USE_LINE != 0
00115 
00116     theme.style.line.decor = &def;
00117 #endif
00118 }
00119 
00120 static void led_init(void)
00121 {
00122 #if LV_USE_LED != 0
00123     static lv_style_t led;
00124 
00125     lv_style_copy(&led, &lv_style_pretty_color);
00126     led.body.shadow.width = LV_DPI / 10;
00127     led.body.radius       = LV_RADIUS_CIRCLE;
00128     led.body.border.width = LV_DPI / 30;
00129     led.body.border.opa   = LV_OPA_30;
00130     led.body.shadow.color = led.body.main_color;
00131 
00132     theme.style.led = &led;
00133 #endif
00134 }
00135 
00136 static void bar_init(void)
00137 {
00138 #if LV_USE_BAR
00139 
00140     theme.style.bar.bg    = &lv_style_pretty;
00141     theme.style.bar.indic = &lv_style_pretty_color;
00142 #endif
00143 }
00144 
00145 static void slider_init(void)
00146 {
00147 #if LV_USE_SLIDER != 0
00148     static lv_style_t slider_bg;
00149     lv_style_copy(&slider_bg, &lv_style_pretty);
00150     slider_bg.body.padding.left   = LV_DPI / 20;
00151     slider_bg.body.padding.right  = LV_DPI / 20;
00152     slider_bg.body.padding.top    = LV_DPI / 20;
00153     slider_bg.body.padding.bottom = LV_DPI / 20;
00154 
00155     theme.style.slider.bg    = &slider_bg;
00156     theme.style.slider.indic = &lv_style_pretty_color;
00157     theme.style.slider.knob  = &lv_style_pretty;
00158 #endif
00159 }
00160 
00161 static void sw_init(void)
00162 {
00163 #if LV_USE_SW != 0
00164     static lv_style_t sw_bg;
00165     lv_style_copy(&sw_bg, &lv_style_pretty);
00166     sw_bg.body.padding.left   = 3;
00167     sw_bg.body.padding.right  = 3;
00168     sw_bg.body.padding.top    = 3;
00169     sw_bg.body.padding.bottom = 3;
00170 
00171     theme.style.sw.bg       = &sw_bg;
00172     theme.style.sw.indic    = &lv_style_pretty_color;
00173     theme.style.sw.knob_off = &lv_style_pretty;
00174     theme.style.sw.knob_on  = &lv_style_pretty;
00175 #endif
00176 }
00177 
00178 static void lmeter_init(void)
00179 {
00180 #if LV_USE_LMETER != 0
00181     static lv_style_t lmeter;
00182     lv_style_copy(&lmeter, &lv_style_pretty_color);
00183     lmeter.line.color      = lv_color_hex3(0xddd);
00184     lmeter.line.width      = 2;
00185     lmeter.body.main_color = lv_color_mix(lmeter.body.main_color, LV_COLOR_WHITE, LV_OPA_50);
00186     lmeter.body.grad_color = lv_color_mix(lmeter.body.grad_color, LV_COLOR_BLACK, LV_OPA_50);
00187 
00188     theme.style.lmeter = &lmeter;
00189 #endif
00190 }
00191 
00192 static void gauge_init(void)
00193 {
00194 #if LV_USE_GAUGE != 0
00195     static lv_style_t gauge;
00196     lv_style_copy(&gauge, theme.style.lmeter);
00197     gauge.line.color      = theme.style.lmeter->body.grad_color;
00198     gauge.line.width      = 2;
00199     gauge.body.main_color = lv_color_hex3(0x888);
00200     gauge.body.grad_color = theme.style.lmeter->body.main_color;
00201     gauge.text.color      = lv_color_hex3(0x888);
00202 
00203     theme.style.gauge = &gauge;
00204 #endif
00205 }
00206 
00207 static void chart_init(void)
00208 {
00209 #if LV_USE_CHART
00210 
00211     theme.style.chart = &lv_style_pretty;
00212 #endif
00213 }
00214 
00215 static void cb_init(void)
00216 {
00217 #if LV_USE_CB != 0
00218 
00219     theme.style.cb.bg          = &lv_style_transp;
00220     theme.style.cb.box.rel     = &lv_style_pretty;
00221     theme.style.cb.box.pr      = &lv_style_btn_pr;
00222     theme.style.cb.box.tgl_rel = &lv_style_btn_tgl_rel;
00223     theme.style.cb.box.tgl_pr  = &lv_style_btn_tgl_pr;
00224     theme.style.cb.box.ina     = &lv_style_btn_ina;
00225 #endif
00226 }
00227 
00228 static void btnm_init(void)
00229 {
00230 #if LV_USE_BTNM
00231 
00232     theme.style.btnm.bg          = &lv_style_pretty;
00233     theme.style.btnm.btn.rel     = &lv_style_btn_rel;
00234     theme.style.btnm.btn.pr      = &lv_style_btn_pr;
00235     theme.style.btnm.btn.tgl_rel = &lv_style_btn_tgl_rel;
00236     theme.style.btnm.btn.tgl_pr  = &lv_style_btn_tgl_pr;
00237     theme.style.btnm.btn.ina     = &lv_style_btn_ina;
00238 #endif
00239 }
00240 
00241 static void kb_init(void)
00242 {
00243 #if LV_USE_KB
00244 
00245     theme.style.kb.bg          = &lv_style_pretty;
00246     theme.style.kb.btn.rel     = &lv_style_btn_rel;
00247     theme.style.kb.btn.pr      = &lv_style_btn_pr;
00248     theme.style.kb.btn.tgl_rel = &lv_style_btn_tgl_rel;
00249     theme.style.kb.btn.tgl_pr  = &lv_style_btn_tgl_pr;
00250     theme.style.kb.btn.ina     = &lv_style_btn_ina;
00251 #endif
00252 }
00253 
00254 static void mbox_init(void)
00255 {
00256 #if LV_USE_MBOX
00257 
00258     theme.style.mbox.bg      = &lv_style_pretty;
00259     theme.style.mbox.btn.bg  = &lv_style_transp;
00260     theme.style.mbox.btn.rel = &lv_style_btn_rel;
00261     theme.style.mbox.btn.pr  = &lv_style_btn_tgl_pr;
00262 #endif
00263 }
00264 
00265 static void page_init(void)
00266 {
00267 #if LV_USE_PAGE
00268 
00269     theme.style.page.bg   = &lv_style_pretty;
00270     theme.style.page.scrl = &lv_style_transp_tight;
00271     theme.style.page.sb   = &sb;
00272 #endif
00273 }
00274 
00275 static void ta_init(void)
00276 {
00277 #if LV_USE_TA
00278 
00279     theme.style.ta.area    = &lv_style_pretty;
00280     theme.style.ta.oneline = &lv_style_pretty;
00281     theme.style.ta.cursor  = NULL;
00282     theme.style.ta.sb      = &sb;
00283 #endif
00284 }
00285 
00286 static void list_init(void)
00287 {
00288 #if LV_USE_LIST != 0
00289 
00290     theme.style.list.bg          = &lv_style_pretty;
00291     theme.style.list.scrl        = &lv_style_transp_fit;
00292     theme.style.list.sb          = &sb;
00293     theme.style.list.btn.rel     = &lv_style_btn_rel;
00294     theme.style.list.btn.pr      = &lv_style_btn_pr;
00295     theme.style.list.btn.tgl_rel = &lv_style_btn_tgl_rel;
00296     theme.style.list.btn.tgl_pr  = &lv_style_btn_tgl_pr;
00297     theme.style.list.btn.ina     = &lv_style_btn_ina;
00298 #endif
00299 }
00300 
00301 static void ddlist_init(void)
00302 {
00303 #if LV_USE_DDLIST != 0
00304 
00305     theme.style.ddlist.bg  = &lv_style_pretty;
00306     theme.style.ddlist.sel = &lv_style_plain_color;
00307     theme.style.ddlist.sb  = &sb;
00308 #endif
00309 }
00310 
00311 static void roller_init(void)
00312 {
00313 #if LV_USE_ROLLER != 0
00314 
00315     theme.style.roller.bg  = &lv_style_pretty;
00316     theme.style.roller.sel = &lv_style_plain_color;
00317 #endif
00318 }
00319 
00320 static void tabview_init(void)
00321 {
00322 #if LV_USE_TABVIEW != 0
00323 
00324     theme.style.tabview.bg          = &plain_bordered;
00325     theme.style.tabview.indic       = &lv_style_plain_color;
00326     theme.style.tabview.btn.bg      = &lv_style_transp;
00327     theme.style.tabview.btn.rel     = &lv_style_btn_rel;
00328     theme.style.tabview.btn.pr      = &lv_style_btn_pr;
00329     theme.style.tabview.btn.tgl_rel = &lv_style_btn_tgl_rel;
00330     theme.style.tabview.btn.tgl_pr  = &lv_style_btn_tgl_pr;
00331 #endif
00332 }
00333 
00334 static void table_init(void)
00335 {
00336 #if LV_USE_TABLE != 0
00337     theme.style.table.bg   = &lv_style_transp_tight;
00338     theme.style.table.cell = &lv_style_plain;
00339 #endif
00340 }
00341 
00342 static void win_init(void)
00343 {
00344 #if LV_USE_WIN != 0
00345 
00346     theme.style.win.bg      = &plain_bordered;
00347     theme.style.win.sb      = &sb;
00348     theme.style.win.header  = &lv_style_plain_color;
00349     theme.style.win.content = &lv_style_transp;
00350     theme.style.win.btn.rel = &lv_style_btn_rel;
00351     theme.style.win.btn.pr  = &lv_style_btn_pr;
00352 #endif
00353 }
00354 
00355 #if LV_USE_GROUP
00356 
00357 static void style_mod(lv_group_t * group, lv_style_t * style)
00358 {
00359     (void)group; /*Unused*/
00360 #if LV_COLOR_DEPTH != 1
00361     /*Make the style to be a little bit orange*/
00362     style->body.border.opa   = LV_OPA_COVER;
00363     style->body.border.color = LV_COLOR_ORANGE;
00364 
00365     /*If not empty or has border then emphasis the border*/
00366     if(style->body.opa != LV_OPA_TRANSP || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
00367 
00368     style->body.main_color   = lv_color_mix(style->body.main_color, LV_COLOR_ORANGE, LV_OPA_70);
00369     style->body.grad_color   = lv_color_mix(style->body.grad_color, LV_COLOR_ORANGE, LV_OPA_70);
00370     style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_ORANGE, LV_OPA_60);
00371 
00372     style->text.color = lv_color_mix(style->text.color, LV_COLOR_ORANGE, LV_OPA_70);
00373 #else
00374     style->body.border.opa   = LV_OPA_COVER;
00375     style->body.border.color = LV_COLOR_BLACK;
00376     style->body.border.width = 2;
00377 #endif
00378 }
00379 
00380 static void style_mod_edit(lv_group_t * group, lv_style_t * style)
00381 {
00382     (void)group; /*Unused*/
00383 #if LV_COLOR_DEPTH != 1
00384     /*Make the style to be a little bit orange*/
00385     style->body.border.opa   = LV_OPA_COVER;
00386     style->body.border.color = LV_COLOR_GREEN;
00387 
00388     /*If not empty or has border then emphasis the border*/
00389     if(style->body.opa != LV_OPA_TRANSP || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
00390 
00391     style->body.main_color   = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70);
00392     style->body.grad_color   = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70);
00393     style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60);
00394 
00395     style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70);
00396 #else
00397     style->body.border.opa   = LV_OPA_COVER;
00398     style->body.border.color = LV_COLOR_BLACK;
00399     style->body.border.width = 3;
00400 #endif
00401 }
00402 
00403 #endif /*LV_USE_GROUP*/
00404 
00405 /**********************
00406  *   GLOBAL FUNCTIONS
00407  **********************/
00408 
00409 /**
00410  * Initialize the default theme
00411  * @param hue [0..360] hue value from HSV color space to define the theme's base color
00412  * @param font pointer to a font (NULL to use the default)
00413  * @return pointer to the initialized theme
00414  */
00415 lv_theme_t * lv_theme_rb_init(uint16_t hue, lv_font_t * font)
00416 {
00417     if(font == NULL) font = LV_FONT_DEFAULT;
00418 
00419     _hue  = hue;
00420     _font = font;
00421 
00422     /*For backward compatibility initialize all theme elements with a default style */
00423     uint16_t i;
00424     lv_style_t ** style_p = (lv_style_t **)&theme.style;
00425     for(i = 0; i < LV_THEME_STYLE_COUNT; i++) {
00426         *style_p = &def;
00427         style_p++;
00428     }
00429 
00430     basic_init();
00431     btn_init();
00432     label_init();
00433     img_init();
00434     line_init();
00435     led_init();
00436     bar_init();
00437     slider_init();
00438     sw_init();
00439     lmeter_init();
00440     gauge_init();
00441     chart_init();
00442     cb_init();
00443     btnm_init();
00444     kb_init();
00445     mbox_init();
00446     page_init();
00447     ta_init();
00448     list_init();
00449     ddlist_init();
00450     roller_init();
00451     tabview_init();
00452     table_init();
00453     win_init();
00454 
00455 #if LV_USE_GROUP
00456     theme.group.style_mod_xcb      = style_mod;
00457     theme.group.style_mod_edit_xcb = style_mod_edit;
00458 #endif
00459 
00460     return &theme;
00461 }
00462 
00463 /**
00464  * Get a pointer to the theme
00465  * @return pointer to the theme
00466  */
00467 lv_theme_t * lv_theme_get_rb(void)
00468 {
00469     return &theme;
00470 }
00471 
00472 /**********************
00473  *   STATIC FUNCTIONS
00474  **********************/
00475