1 #include "../../lv_examples.h"
2 #if LV_BUILD_EXAMPLES && LV_USE_BTN
3 
4 /**
5  * Create a style transition on a button to act like a gum when clicked
6  */
lv_example_btn_3(void)7 void lv_example_btn_3(void)
8 {
9     /*Properties to transition*/
10     static lv_style_prop_t props[] = {
11         LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_TRANSFORM_HEIGHT, LV_STYLE_TEXT_LETTER_SPACE, 0
12     };
13 
14     /*Transition descriptor when going back to the default state.
15      *Add some delay to be sure the press transition is visible even if the press was very short*/
16     static lv_style_transition_dsc_t transition_dsc_def;
17     lv_style_transition_dsc_init(&transition_dsc_def, props, lv_anim_path_overshoot, 250, 100, NULL);
18 
19     /*Transition descriptor when going to pressed state.
20      *No delay, go to presses state immediately*/
21     static lv_style_transition_dsc_t transition_dsc_pr;
22     lv_style_transition_dsc_init(&transition_dsc_pr, props, lv_anim_path_ease_in_out, 250, 0, NULL);
23 
24     /*Add only the new transition to he default state*/
25     static lv_style_t style_def;
26     lv_style_init(&style_def);
27     lv_style_set_transition(&style_def, &transition_dsc_def);
28 
29     /*Add the transition and some transformation to the presses state.*/
30     static lv_style_t style_pr;
31     lv_style_init(&style_pr);
32     lv_style_set_transform_width(&style_pr, 10);
33     lv_style_set_transform_height(&style_pr, -10);
34     lv_style_set_text_letter_space(&style_pr, 10);
35     lv_style_set_transition(&style_pr, &transition_dsc_pr);
36 
37     lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
38     lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -80);
39     lv_obj_add_style(btn1, &style_pr, LV_STATE_PRESSED);
40     lv_obj_add_style(btn1, &style_def, 0);
41 
42     lv_obj_t * label = lv_label_create(btn1);
43     lv_label_set_text(label, "Gum");
44 }
45 #endif
46