switch_demo.lua 720 B

12345678910111213141516171819202122232425
  1. local switch_demo = {}
  2. local function event_handler(obj, event)
  3. if(event == lvgl.EVENT_VALUE_CHANGED) then
  4. if lvgl.switch_get_state(obj) == true then
  5. print("State: On\n")
  6. else
  7. print("State: Off\n")
  8. end
  9. end
  10. end
  11. function switch_demo.demo()
  12. --Create a switch and apply the styles
  13. local sw1 = lvgl.switch_create(lvgl.scr_act(), nil);
  14. lvgl.obj_align(sw1, nil, lvgl.ALIGN_CENTER, 0, -50);
  15. lvgl.obj_set_event_cb(sw1, event_handler);
  16. --Copy the first switch and turn it ON
  17. local sw2 = lvgl.switch_create(lvgl.scr_act(), sw1);
  18. lvgl.switch_on(sw2, lvgl.ANIM_ON);
  19. lvgl.obj_align(sw2, nil, lvgl.ALIGN_CENTER, 0, 50);
  20. end
  21. return switch_demo