acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_scroll_2.py (1103B)

      1 def 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 
     18 panel = lv.obj(lv.scr_act())
     19 panel.set_size(280, 150)
     20 panel.set_scroll_snap_x(lv.SCROLL_SNAP.CENTER)
     21 panel.set_flex_flow(lv.FLEX_FLOW.ROW)
     22 panel.center()
     23 
     24 for 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 
     36 panel.update_snap(lv.ANIM.ON)
     37 
     38 
     39 # Switch between "One scroll" and "Normal scroll" mode
     40 sw = lv.switch(lv.scr_act())
     41 sw.align(lv.ALIGN.TOP_RIGHT, -20, 10)
     42 sw.add_event_cb(lambda evt:  sw_event_cb(evt,panel), lv.EVENT.ALL, None)
     43 label = lv.label(lv.scr_act())
     44 label.set_text("One scroll")
     45 label.align_to(sw, lv.ALIGN.OUT_BOTTOM_MID, 0, 5)
     46 
     47