2021-04-08 13:07:48 +02:00
|
|
|
#include "../lv_examples.h"
|
2021-03-23 20:51:39 +01:00
|
|
|
#if LV_BUILD_EXAMPLES && LV_USE_BTN
|
2021-02-08 09:53:03 +01:00
|
|
|
|
|
|
|
static void btn_event_cb(lv_obj_t * btn, lv_event_t event)
|
|
|
|
{
|
|
|
|
if(event == LV_EVENT_CLICKED) {
|
|
|
|
static uint8_t cnt = 0;
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
/*Get the first child of the button which is the label and change its text*/
|
|
|
|
lv_obj_t * label = lv_obj_get_child(btn, 0);
|
|
|
|
lv_label_set_text_fmt(label, "Button: %d", cnt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-16 20:41:11 +01:00
|
|
|
* Create a button with a label and react on click event.
|
2021-02-08 09:53:03 +01:00
|
|
|
*/
|
|
|
|
void lv_example_get_started_1(void)
|
|
|
|
{
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_obj_set_pos(btn, 10, 10); /*Set its position*/
|
|
|
|
lv_obj_set_size(btn, 120, 50); /*Set its size*/
|
2021-02-16 20:41:11 +01:00
|
|
|
lv_obj_add_event_cb(btn, btn_event_cb, NULL); /*Assign a callback to the button*/
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_label_set_text(label, "Button"); /*Set the labels text*/
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_center(label);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 14:23:18 +01:00
|
|
|
#endif
|
|
|
|
|