1 #include "../lv_examples.h"
2 #if LV_BUILD_EXAMPLES && LV_USE_BTN
3 
btn_event_cb(lv_event_t * e)4 static void btn_event_cb(lv_event_t * e)
5 {
6     lv_event_code_t code = lv_event_get_code(e);
7     lv_obj_t * btn = lv_event_get_target(e);
8     if(code == LV_EVENT_CLICKED) {
9         static uint8_t cnt = 0;
10         cnt++;
11 
12         /*Get the first child of the button which is the label and change its text*/
13         lv_obj_t * label = lv_obj_get_child(btn, 0);
14         lv_label_set_text_fmt(label, "Button: %d", cnt);
15     }
16 }
17 
18 /**
19  * Create a button with a label and react on click event.
20  */
lv_example_get_started_1(void)21 void lv_example_get_started_1(void)
22 {
23     lv_obj_t * btn = lv_btn_create(lv_scr_act());     /*Add a button the current screen*/
24     lv_obj_set_pos(btn, 10, 10);                            /*Set its position*/
25     lv_obj_set_size(btn, 120, 50);                          /*Set its size*/
26     lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL);           /*Assign a callback to the button*/
27 
28     lv_obj_t * label = lv_label_create(btn);          /*Add a label to the button*/
29     lv_label_set_text(label, "Button");                     /*Set the labels text*/
30     lv_obj_center(label);
31 }
32 
33 #endif
34 
35