1 #include "../../lv_examples.h"
2 #if LV_USE_BTN && LV_BUILD_EXAMPLES
3 
4 /**
5  * Style a button from scratch
6  */
lv_example_btn_2(void)7 void lv_example_btn_2(void)
8 {
9     /*Init the style for the default state*/
10     static lv_style_t style;
11     lv_style_init(&style);
12 
13     lv_style_set_radius(&style, 3);
14 
15     lv_style_set_bg_opa(&style, LV_OPA_100);
16     lv_style_set_bg_color(&style, lv_palette_main(LV_PALETTE_BLUE));
17     lv_style_set_bg_grad_color(&style, lv_palette_darken(LV_PALETTE_BLUE, 2));
18     lv_style_set_bg_grad_dir(&style, LV_GRAD_DIR_VER);
19 
20     lv_style_set_border_opa(&style, LV_OPA_40);
21     lv_style_set_border_width(&style, 2);
22     lv_style_set_border_color(&style, lv_palette_main(LV_PALETTE_GREY));
23 
24     lv_style_set_shadow_width(&style, 8);
25     lv_style_set_shadow_color(&style, lv_palette_main(LV_PALETTE_GREY));
26     lv_style_set_shadow_ofs_y(&style, 8);
27 
28     lv_style_set_outline_opa(&style, LV_OPA_COVER);
29     lv_style_set_outline_color(&style, lv_palette_main(LV_PALETTE_BLUE));
30 
31     lv_style_set_text_color(&style, lv_color_white());
32     lv_style_set_pad_all(&style, 10);
33 
34     /*Init the pressed style*/
35     static lv_style_t style_pr;
36     lv_style_init(&style_pr);
37 
38     /*Add a large outline when pressed*/
39     lv_style_set_outline_width(&style_pr, 30);
40     lv_style_set_outline_opa(&style_pr, LV_OPA_TRANSP);
41 
42     lv_style_set_translate_y(&style_pr, 5);
43     lv_style_set_shadow_ofs_y(&style_pr, 3);
44     lv_style_set_bg_color(&style_pr, lv_palette_darken(LV_PALETTE_BLUE, 2));
45     lv_style_set_bg_grad_color(&style_pr, lv_palette_darken(LV_PALETTE_BLUE, 4));
46 
47     /*Add a transition to the outline*/
48     static lv_style_transition_dsc_t trans;
49     static lv_style_prop_t props[] = {LV_STYLE_OUTLINE_WIDTH, LV_STYLE_OUTLINE_OPA, 0};
50     lv_style_transition_dsc_init(&trans, props, lv_anim_path_linear, 300, 0, NULL);
51 
52     lv_style_set_transition(&style_pr, &trans);
53 
54     lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
55     lv_obj_remove_style_all(btn1);                          /*Remove the style coming from the theme*/
56     lv_obj_add_style(btn1, &style, 0);
57     lv_obj_add_style(btn1, &style_pr, LV_STATE_PRESSED);
58     lv_obj_set_size(btn1, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
59     lv_obj_center(btn1);
60 
61     lv_obj_t * label = lv_label_create(btn1);
62     lv_label_set_text(label, "Button");
63     lv_obj_center(label);
64 }
65 #endif
66