1def sw_event_cb(e,panel):
2
3    code = e.get_code()
4    sw = e.get_target()
5
6    if code == lv.EVENT.VALUE_CHANGED:
7
8        if sw.has_state(lv.STATE.CHECKED):
9            panel.add_flag(lv.obj.FLAG.SCROLL_ONE)
10        else:
11            panel.clear_flag(lv.obj.FLAG.SCROLL_ONE)
12
13
14#
15# Show an example to scroll snap
16#
17
18panel = lv.obj(lv.scr_act())
19panel.set_size(280, 150)
20panel.set_scroll_snap_x(lv.SCROLL_SNAP.CENTER)
21panel.set_flex_flow(lv.FLEX_FLOW.ROW)
22panel.center()
23
24for i in range(10):
25    btn = lv.btn(panel)
26    btn.set_size(150, 100)
27
28    label = lv.label(btn)
29    if i == 3:
30        label.set_text("Panel {:d}\nno snap".format(i))
31        btn.clear_flag(lv.obj.FLAG.SNAPPABLE)
32    else:
33        label.set_text("Panel {:d}".format(i))
34    label.center()
35
36panel.update_snap(lv.ANIM.ON)
37
38
39# Switch between "One scroll" and "Normal scroll" mode
40sw = lv.switch(lv.scr_act())
41sw.align(lv.ALIGN.TOP_RIGHT, -20, 10)
42sw.add_event_cb(lambda evt:  sw_event_cb(evt,panel), lv.EVENT.ALL, None)
43label = lv.label(lv.scr_act())
44label.set_text("One scroll")
45label.align_to(sw, lv.ALIGN.OUT_BOTTOM_MID, 0, 5)
46
47
48