1 #include "../../lv_examples.h"
2 #if LV_USE_CHECKBOX && LV_BUILD_EXAMPLES
3
event_handler(lv_event_t * e)4 static void event_handler(lv_event_t * e)
5 {
6 lv_event_code_t code = lv_event_get_code(e);
7 lv_obj_t * obj = lv_event_get_target(e);
8 if(code == LV_EVENT_VALUE_CHANGED) {
9 const char * txt = lv_checkbox_get_text(obj);
10 const char * state = lv_obj_get_state(obj) & LV_STATE_CHECKED ? "Checked" : "Unchecked";
11 LV_LOG_USER("%s: %s", txt, state);
12 }
13 }
14
lv_example_checkbox_1(void)15 void lv_example_checkbox_1(void)
16 {
17 lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
18 lv_obj_set_flex_align(lv_scr_act(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER);
19
20 lv_obj_t * cb;
21 cb = lv_checkbox_create(lv_scr_act());
22 lv_checkbox_set_text(cb, "Apple");
23 lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
24
25 cb = lv_checkbox_create(lv_scr_act());
26 lv_checkbox_set_text(cb, "Banana");
27 lv_obj_add_state(cb, LV_STATE_CHECKED);
28 lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
29
30 cb = lv_checkbox_create(lv_scr_act());
31 lv_checkbox_set_text(cb, "Lemon");
32 lv_obj_add_state(cb, LV_STATE_DISABLED);
33 lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
34
35 cb = lv_checkbox_create(lv_scr_act());
36 lv_obj_add_state(cb, LV_STATE_CHECKED | LV_STATE_DISABLED);
37 lv_checkbox_set_text(cb, "Melon\nand a new line");
38 lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
39
40 lv_obj_update_layout(cb);
41 }
42
43 #endif
44