2021-06-07 13:56:08 +02:00
|
|
|
def sw_event_cb(e,panel):
|
|
|
|
|
|
|
|
code = e.get_code()
|
2023-02-20 20:50:58 +01:00
|
|
|
sw = e.get_target_obj()
|
2021-06-07 13:56:08 +02:00
|
|
|
|
|
|
|
if code == lv.EVENT.VALUE_CHANGED:
|
|
|
|
|
|
|
|
if sw.has_state(lv.STATE.CHECKED):
|
|
|
|
panel.add_flag(lv.obj.FLAG.SCROLL_ONE)
|
|
|
|
else:
|
2023-10-12 20:37:27 +02:00
|
|
|
panel.remove_flag(lv.obj.FLAG.SCROLL_ONE)
|
2021-06-07 13:56:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Show an example to scroll snap
|
|
|
|
#
|
|
|
|
|
2023-10-12 20:37:27 +02:00
|
|
|
panel = lv.obj(lv.screen_active())
|
2021-06-07 13:56:08 +02:00
|
|
|
panel.set_size(280, 150)
|
|
|
|
panel.set_scroll_snap_x(lv.SCROLL_SNAP.CENTER)
|
|
|
|
panel.set_flex_flow(lv.FLEX_FLOW.ROW)
|
|
|
|
panel.center()
|
|
|
|
|
2022-03-21 18:25:51 +08:00
|
|
|
for i in range(10):
|
2023-09-14 20:12:31 +02:00
|
|
|
button = lv.button(panel)
|
|
|
|
button.set_size(150, 100)
|
2021-06-07 13:56:08 +02:00
|
|
|
|
2023-09-14 20:12:31 +02:00
|
|
|
label = lv.label(button)
|
2021-06-07 13:56:08 +02:00
|
|
|
if i == 3:
|
|
|
|
label.set_text("Panel {:d}\nno snap".format(i))
|
2023-10-12 20:37:27 +02:00
|
|
|
button.remove_flag(lv.obj.FLAG.SNAPPABLE)
|
2021-06-07 13:56:08 +02:00
|
|
|
else:
|
|
|
|
label.set_text("Panel {:d}".format(i))
|
|
|
|
label.center()
|
|
|
|
|
|
|
|
panel.update_snap(lv.ANIM.ON)
|
|
|
|
|
|
|
|
|
|
|
|
# Switch between "One scroll" and "Normal scroll" mode
|
2023-10-12 20:37:27 +02:00
|
|
|
sw = lv.switch(lv.screen_active())
|
2021-06-07 13:56:08 +02:00
|
|
|
sw.align(lv.ALIGN.TOP_RIGHT, -20, 10)
|
2023-11-28 15:36:51 +01:00
|
|
|
sw.add_event_cb(lambda evt: sw_event_cb(evt,panel), lv.EVENT.ALL, None)
|
2023-10-12 20:37:27 +02:00
|
|
|
label = lv.label(lv.screen_active())
|
2021-06-07 13:56:08 +02:00
|
|
|
label.set_text("One scroll")
|
|
|
|
label.align_to(sw, lv.ALIGN.OUT_BOTTOM_MID, 0, 5)
|
|
|
|
|
|
|
|
|