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