1 #include "../../lv_examples.h"
2 #if LV_USE_SWITCH && 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 LV_LOG_USER("State: %s\n", lv_obj_has_state(obj, LV_STATE_CHECKED) ? "On" : "Off");
10 }
11 }
12
lv_example_switch_1(void)13 void lv_example_switch_1(void)
14 {
15 lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
16 lv_obj_set_flex_align(lv_scr_act(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
17
18 lv_obj_t * sw;
19
20 sw = lv_switch_create(lv_scr_act());
21 lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL);
22
23 sw = lv_switch_create(lv_scr_act());
24 lv_obj_add_state(sw, LV_STATE_CHECKED);
25 lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL);
26
27 sw = lv_switch_create(lv_scr_act());
28 lv_obj_add_state(sw, LV_STATE_DISABLED);
29 lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL);
30
31 sw = lv_switch_create(lv_scr_act());
32 lv_obj_add_state(sw, LV_STATE_CHECKED | LV_STATE_DISABLED);
33 lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL);
34 }
35
36 #endif
37