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_roller_2.py (2049B)

      1 import fs_driver
      2 
      3 
      4 def event_handler(e):
      5     code = e.get_code()
      6     obj = e.get_target()
      7     if code == lv.EVENT.VALUE_CHANGED:
      8         option = " "*10
      9         obj.get_selected_str(option, len(option))
     10         print("Selected value: %s\n" + option.strip())
     11 
     12 #
     13 # Roller with various alignments and larger text in the selected area
     14 #
     15 
     16 # A style to make the selected option larger
     17 style_sel = lv.style_t()
     18 style_sel.init()
     19 
     20 try:
     21     style_sel.set_text_font(lv.font_montserrat_22)
     22 except:
     23     fs_drv = lv.fs_drv_t()
     24     fs_driver.fs_register(fs_drv, 'S')
     25     print("montserrat-22 not enabled in lv_conf.h, dynamically loading the font")
     26     font_montserrat_22 = lv.font_load("S:" + "../../assets/font/montserrat-22.fnt")
     27     style_sel.set_text_font(font_montserrat_22)
     28 
     29 opts = "\n".join(["1","2","3","4","5","6","7","8","9","10"])
     30 
     31 # A roller on the left with left aligned text, and custom width
     32 roller = lv.roller(lv.scr_act())
     33 roller.set_options(opts, lv.roller.MODE.NORMAL)
     34 roller.set_visible_row_count(2)
     35 roller.set_width(100)
     36 roller.add_style(style_sel, lv.PART.SELECTED)
     37 roller.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
     38 roller.align(lv.ALIGN.LEFT_MID, 10, 0)
     39 roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
     40 roller.set_selected(2, lv.ANIM.OFF)
     41 
     42 # A roller in the middle with center aligned text, and auto (default) width
     43 roller = lv.roller(lv.scr_act())
     44 roller.set_options(opts, lv.roller.MODE.NORMAL)
     45 roller.set_visible_row_count(3)
     46 roller.add_style(style_sel, lv.PART.SELECTED)
     47 roller.align(lv.ALIGN.CENTER, 0, 0)
     48 roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
     49 roller.set_selected(5, lv.ANIM.OFF)
     50 
     51 # A roller on the right with right aligned text, and custom width
     52 roller = lv.roller(lv.scr_act())
     53 roller.set_options(opts, lv.roller.MODE.NORMAL)
     54 roller.set_visible_row_count(4)
     55 roller.set_width(80)
     56 roller.add_style(style_sel, lv.PART.SELECTED)
     57 roller.set_style_text_align(lv.TEXT_ALIGN.RIGHT, 0)
     58 roller.align(lv.ALIGN.RIGHT_MID, -10, 0)
     59 roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
     60 roller.set_selected(8, lv.ANIM.OFF)