init lvgl code
This commit is contained in:
7
LVGL.Simulator/lvgl/examples/widgets/switch/index.rst
Normal file
7
LVGL.Simulator/lvgl/examples/widgets/switch/index.rst
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
Simple Switch
|
||||
"""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/switch/lv_example_switch_1
|
||||
:language: c
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_SWITCH && LV_BUILD_EXAMPLES
|
||||
|
||||
static void event_handler(lv_event_t * e)
|
||||
{
|
||||
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) {
|
||||
LV_LOG_USER("State: %s\n", lv_obj_has_state(obj, LV_STATE_CHECKED) ? "On" : "Off");
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_switch_1(void)
|
||||
{
|
||||
lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(lv_scr_act(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
|
||||
lv_obj_t * sw;
|
||||
|
||||
sw = lv_switch_create(lv_scr_act());
|
||||
lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
sw = lv_switch_create(lv_scr_act());
|
||||
lv_obj_add_state(sw, LV_STATE_CHECKED);
|
||||
lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
sw = lv_switch_create(lv_scr_act());
|
||||
lv_obj_add_state(sw, LV_STATE_DISABLED);
|
||||
lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
sw = lv_switch_create(lv_scr_act());
|
||||
lv_obj_add_state(sw, LV_STATE_CHECKED | LV_STATE_DISABLED);
|
||||
lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
def event_handler(e):
|
||||
code = e.get_code()
|
||||
obj = e.get_target()
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
if obj.has_state(lv.STATE.CHECKED):
|
||||
print("State: on")
|
||||
else:
|
||||
print("State: off")
|
||||
|
||||
|
||||
lv.scr_act().set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
lv.scr_act().set_flex_align(lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
|
||||
|
||||
sw = lv.switch(lv.scr_act())
|
||||
sw.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
|
||||
sw = lv.switch(lv.scr_act())
|
||||
sw.add_state(lv.STATE.CHECKED)
|
||||
sw.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
sw = lv.switch(lv.scr_act())
|
||||
sw.add_state(lv.STATE.DISABLED)
|
||||
sw.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
sw = lv.switch(lv.scr_act())
|
||||
sw.add_state(lv.STATE.CHECKED | lv.STATE.DISABLED)
|
||||
sw.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
Reference in New Issue
Block a user