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_btnmatrix_3.py (1563B)

      1 def event_cb(e):
      2     obj = e.get_target()
      3     id = obj.get_selected_btn()
      4     if id == 0:
      5         prev = True
      6     else:
      7         prev = False
      8     if id == 6:
      9         next = True
     10     else:
     11         next = False
     12     if prev or next:
     13         # Find the checked butto
     14         for i in range(7):
     15             if obj.has_btn_ctrl(i, lv.btnmatrix.CTRL.CHECKED):
     16                 break
     17         if prev and i > 1:
     18             i-=1
     19         elif next and i < 5:
     20             i+=1
     21 
     22         obj.set_btn_ctrl(i, lv.btnmatrix.CTRL.CHECKED)
     23 
     24 #
     25 # Make a button group
     26 #
     27 
     28 style_bg = lv.style_t()
     29 style_bg.init()
     30 style_bg.set_pad_all(0)
     31 style_bg.set_pad_gap(0)
     32 style_bg.set_clip_corner(True)
     33 style_bg.set_radius(lv.RADIUS.CIRCLE)
     34 style_bg.set_border_width(0)
     35 
     36 
     37 style_btn = lv.style_t()
     38 style_btn.init()
     39 style_btn.set_radius(0)
     40 style_btn.set_border_width(1)
     41 style_btn.set_border_opa(lv.OPA._50)
     42 style_btn.set_border_color(lv.palette_main(lv.PALETTE.GREY))
     43 style_btn.set_border_side(lv.BORDER_SIDE.INTERNAL)
     44 style_btn.set_radius(0)
     45 
     46 map = [lv.SYMBOL.LEFT,"1","2", "3", "4", "5",lv.SYMBOL.RIGHT, ""]
     47 
     48 btnm = lv.btnmatrix(lv.scr_act())
     49 btnm.set_map(map)
     50 btnm.add_style(style_bg, 0)
     51 btnm.add_style(style_btn, lv.PART.ITEMS)
     52 btnm.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None)
     53 btnm.set_size(225, 35)
     54 
     55 # Allow selecting on one number at time
     56 btnm.set_btn_ctrl_all(lv.btnmatrix.CTRL.CHECKABLE)
     57 btnm.clear_btn_ctrl(0, lv.btnmatrix.CTRL.CHECKABLE)
     58 btnm.clear_btn_ctrl(6, lv.btnmatrix.CTRL.CHECKABLE)
     59 
     60 btnm.set_one_checked(True)
     61 btnm.set_btn_ctrl(1, lv.btnmatrix.CTRL.CHECKED)
     62 
     63 btnm.center()
     64