2021-04-08 13:07:48 +02:00
|
|
|
#include "../../lv_examples.h"
|
2021-02-14 14:56:34 +01:00
|
|
|
#if LV_USE_CHECKBOX && 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);
|
|
|
|
lv_obj_t * obj = lv_event_get_target(e);
|
|
|
|
if(code == LV_EVENT_VALUE_CHANGED) {
|
2021-02-08 09:53:03 +01:00
|
|
|
const char * txt = lv_checkbox_get_text(obj);
|
|
|
|
const char * state = lv_obj_get_state(obj) & LV_STATE_CHECKED ? "Checked" : "Unchecked";
|
2021-02-14 14:56:34 +01:00
|
|
|
LV_LOG_USER("%s: %s\n", txt, state);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lv_example_checkbox_1(void)
|
|
|
|
{
|
2021-03-23 20:51:39 +01:00
|
|
|
lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
|
2021-04-24 16:48:24 +02:00
|
|
|
lv_obj_set_flex_align(lv_scr_act(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
|
|
|
lv_obj_t * cb;
|
2021-03-25 13:36:50 +01:00
|
|
|
cb = lv_checkbox_create(lv_scr_act());
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_checkbox_set_text(cb, "Apple");
|
2021-04-19 11:15:28 +02:00
|
|
|
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
cb = lv_checkbox_create(lv_scr_act());
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_checkbox_set_text(cb, "Banana");
|
|
|
|
lv_obj_add_state(cb, LV_STATE_CHECKED);
|
2021-04-19 11:15:28 +02:00
|
|
|
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
cb = lv_checkbox_create(lv_scr_act());
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_checkbox_set_text(cb, "Lemon");
|
|
|
|
lv_obj_add_state(cb, LV_STATE_DISABLED);
|
2021-04-19 11:15:28 +02:00
|
|
|
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
cb = lv_checkbox_create(lv_scr_act());
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_obj_add_state(cb, LV_STATE_CHECKED | LV_STATE_DISABLED);
|
|
|
|
lv_checkbox_set_text(cb, "Melon");
|
2021-04-19 11:15:28 +02:00
|
|
|
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
|
2021-04-23 14:06:50 +02:00
|
|
|
|
|
|
|
lv_obj_update_layout(cb);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|