1 #include "../../lv_examples.h"
2 #if LV_USE_IMAGEBUTTON && LV_BUILD_EXAMPLES
3 
lv_example_imagebutton_1(void)4 void lv_example_imagebutton_1(void)
5 {
6     LV_IMAGE_DECLARE(imagebutton_left);
7     LV_IMAGE_DECLARE(imagebutton_right);
8     LV_IMAGE_DECLARE(imagebutton_mid);
9 
10     /*Create a transition animation on width transformation and recolor.*/
11     static lv_style_prop_t tr_prop[] = {LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_IMAGE_RECOLOR_OPA, 0};
12     static lv_style_transition_dsc_t tr;
13     lv_style_transition_dsc_init(&tr, tr_prop, lv_anim_path_linear, 200, 0, NULL);
14 
15     static lv_style_t style_def;
16     lv_style_init(&style_def);
17     lv_style_set_text_color(&style_def, lv_color_white());
18     lv_style_set_transition(&style_def, &tr);
19 
20     /*Darken the button when pressed and make it wider*/
21     static lv_style_t style_pr;
22     lv_style_init(&style_pr);
23     lv_style_set_image_recolor_opa(&style_pr, LV_OPA_30);
24     lv_style_set_image_recolor(&style_pr, lv_color_black());
25     lv_style_set_transform_width(&style_pr, 20);
26 
27     /*Create an image button*/
28     lv_obj_t * imagebutton1 = lv_imagebutton_create(lv_screen_active());
29     lv_imagebutton_set_src(imagebutton1, LV_IMAGEBUTTON_STATE_RELEASED, &imagebutton_left, &imagebutton_mid,
30                            &imagebutton_right);
31     lv_obj_add_style(imagebutton1, &style_def, 0);
32     lv_obj_add_style(imagebutton1, &style_pr, LV_STATE_PRESSED);
33 
34     lv_obj_set_width(imagebutton1, 100);
35     lv_obj_align(imagebutton1, LV_ALIGN_CENTER, 0, 0);
36 
37     /*Create a label on the image button*/
38     lv_obj_t * label = lv_label_create(imagebutton1);
39     lv_label_set_text(label, "Button");
40     lv_obj_align(label, LV_ALIGN_CENTER, 0, -4);
41 }
42 
43 #endif
44