2021-04-08 13:07:48 +02:00
|
|
|
#include "../../lv_examples.h"
|
2021-02-14 14:56:34 +01:00
|
|
|
#if LV_USE_BTN && LV_BUILD_EXAMPLES
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-04-14 15:31:54 +02:00
|
|
|
static void event_handler(lv_event_t * e)
|
2021-02-08 09:53:03 +01:00
|
|
|
{
|
2021-04-14 15:31:54 +02:00
|
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
|
|
|
|
|
|
if(code == LV_EVENT_CLICKED) {
|
2021-02-24 15:12:36 +01:00
|
|
|
LV_LOG_USER("Clicked");
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
2021-04-14 15:31:54 +02:00
|
|
|
else if(code == LV_EVENT_VALUE_CHANGED) {
|
2021-02-24 15:12:36 +01:00
|
|
|
LV_LOG_USER("Toggled");
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lv_example_btn_1(void)
|
|
|
|
{
|
|
|
|
lv_obj_t * label;
|
2021-03-25 16:14:17 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
|
|
|
|
lv_obj_add_event_cb(btn1, event_handler, NULL);
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);
|
2021-03-25 13:36:50 +01:00
|
|
|
|
|
|
|
label = lv_label_create(btn1);
|
|
|
|
lv_label_set_text(label, "Button");
|
|
|
|
lv_obj_center(label);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * btn2 = lv_btn_create(lv_scr_act());
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_obj_add_event_cb(btn2, event_handler, NULL);
|
2021-03-25 20:53:45 +01:00
|
|
|
lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40);
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_set_height(btn2, LV_SIZE_CONTENT);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
label = lv_label_create(btn2);
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_label_set_text(label, "Toggle");
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_center(label);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
#endif
|