1 #include "../lv_examples.h"
2 #if LV_BUILD_EXAMPLES && LV_USE_IMAGE
3 #include "../../lvgl_private.h"
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*/
new_theme_apply_cb(lv_theme_t * th,lv_obj_t * obj)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_button_class)) {
14         lv_obj_add_style(obj, &style_btn, 0);
15     }
16 }
17 
new_theme_init_and_set(void)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_display_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_display_set_theme(NULL, &th_new);
37 }
38 
39 /**
40  * Extending the current theme
41  */
lv_example_style_14(void)42 void lv_example_style_14(void)
43 {
44     lv_obj_t * btn;
45     lv_obj_t * label;
46 
47     btn = lv_button_create(lv_screen_active());
48     lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, 20);
49 
50     label = lv_label_create(btn);
51     lv_label_set_text(label, "Original theme");
52 
53     new_theme_init_and_set();
54 
55     btn = lv_button_create(lv_screen_active());
56     lv_obj_align(btn, LV_ALIGN_BOTTOM_MID, 0, -20);
57 
58     label = lv_label_create(btn);
59     lv_label_set_text(label, "New theme");
60 }
61 
62 #endif
63