2021-05-26 22:04:10 +02:00
|
|
|
#include "../lv_examples.h"
|
|
|
|
#if LV_BUILD_EXAMPLES && LV_USE_SWITCH
|
|
|
|
|
|
|
|
static void event_cb(lv_event_t * e)
|
|
|
|
{
|
|
|
|
LV_LOG_USER("Clicked");
|
|
|
|
|
2021-12-20 03:52:07 -05:00
|
|
|
static uint32_t cnt = 1;
|
2021-05-26 22:04:10 +02:00
|
|
|
lv_obj_t * btn = lv_event_get_target(e);
|
|
|
|
lv_obj_t * label = lv_obj_get_child(btn, 0);
|
2021-12-20 03:52:07 -05:00
|
|
|
lv_label_set_text_fmt(label, "%"LV_PRIu32, cnt);
|
2021-05-26 22:04:10 +02:00
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add click event to a button
|
|
|
|
*/
|
2024-09-12 09:27:25 +02:00
|
|
|
void lv_example_event_click(void)
|
2021-05-26 22:04:10 +02:00
|
|
|
{
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_t * btn = lv_button_create(lv_screen_active());
|
2021-05-26 22:04:10 +02:00
|
|
|
lv_obj_set_size(btn, 100, 50);
|
|
|
|
lv_obj_center(btn);
|
2023-11-28 15:36:51 +01:00
|
|
|
lv_obj_add_event_cb(btn, event_cb, LV_EVENT_CLICKED, NULL);
|
2021-05-26 22:04:10 +02:00
|
|
|
|
|
|
|
lv_obj_t * label = lv_label_create(btn);
|
|
|
|
lv_label_set_text(label, "Click me!");
|
|
|
|
lv_obj_center(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|