acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_style_14.c (1610B)

      1 #include "../lv_examples.h"
      2 #if LV_BUILD_EXAMPLES && LV_USE_IMG
      3 
      4 
      5 static lv_style_t style_btn;
      6 
      7 /*Will be called when the styles of the base theme are already added
      8   to add new styles*/
      9 static void new_theme_apply_cb(lv_theme_t * th, lv_obj_t * obj)
     10 {
     11     LV_UNUSED(th);
     12 
     13     if(lv_obj_check_type(obj, &lv_btn_class)) {
     14         lv_obj_add_style(obj, &style_btn, 0);
     15     }
     16 }
     17 
     18 static void new_theme_init_and_set(void)
     19 {
     20     /*Initialize the styles*/
     21     lv_style_init(&style_btn);
     22     lv_style_set_bg_color(&style_btn, lv_palette_main(LV_PALETTE_GREEN));
     23     lv_style_set_border_color(&style_btn, lv_palette_darken(LV_PALETTE_GREEN, 3));
     24     lv_style_set_border_width(&style_btn, 3);
     25 
     26     /*Initialize the new theme from the current theme*/
     27     lv_theme_t * th_act = lv_disp_get_theme(NULL);
     28     static lv_theme_t th_new;
     29     th_new = *th_act;
     30 
     31     /*Set the parent theme and the style apply callback for the new theme*/
     32     lv_theme_set_parent(&th_new, th_act);
     33     lv_theme_set_apply_cb(&th_new, new_theme_apply_cb);
     34 
     35     /*Assign the new theme to the current display*/
     36     lv_disp_set_theme(NULL, &th_new);
     37 }
     38 
     39 
     40 
     41 /**
     42  * Extending the current theme
     43  */
     44 void lv_example_style_14(void)
     45 {
     46     lv_obj_t * btn;
     47     lv_obj_t * label;
     48 
     49     btn = lv_btn_create(lv_scr_act());
     50     lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, 20);
     51 
     52     label = lv_label_create(btn);
     53     lv_label_set_text(label, "Original theme");
     54 
     55     new_theme_init_and_set();
     56 
     57     btn = lv_btn_create(lv_scr_act());
     58     lv_obj_align(btn, LV_ALIGN_BOTTOM_MID, 0, -20);
     59 
     60     label = lv_label_create(btn);
     61     lv_label_set_text(label, "New theme");
     62 }
     63 
     64 #endif