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_slider_3.py (1503B)

      1 def slider_event_cb(e):
      2     code = e.get_code()
      3     obj = e.get_target()
      4 
      5     # Provide some extra space for the value
      6     if code == lv.EVENT.REFR_EXT_DRAW_SIZE:
      7         e.set_ext_draw_size(50)
      8 
      9     elif code == lv.EVENT.DRAW_PART_END:
     10         # print("DRAW_PART_END")
     11         dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param())
     12         # print(dsc)
     13         if dsc.part == lv.PART.INDICATOR:
     14             label_text = "{:d} - {:d}".format(obj.get_left_value(),slider.get_value())
     15             label_size = lv.point_t()
     16             lv.txt_get_size(label_size, label_text, lv.font_default(), 0, 0, lv.COORD.MAX, 0)
     17             # print(label_size.x,label_size.y)
     18             label_area = lv.area_t()
     19             label_area.x1 = dsc.draw_area.x1 + dsc.draw_area.get_width() // 2 - label_size.x // 2
     20             label_area.x2 = label_area.x1 + label_size.x
     21             label_area.y2 = dsc.draw_area.y1 - 10
     22             label_area.y1 = label_area.y2 - label_size.y
     23 
     24             label_draw_dsc = lv.draw_label_dsc_t()
     25             label_draw_dsc.init()
     26 
     27             dsc.draw_ctx.label(label_draw_dsc, label_area, label_text, None)
     28 #
     29 # Show the current value when the slider if pressed by extending the drawer
     30 #
     31 #
     32 #Create a slider in the center of the display
     33 
     34 slider = lv.slider(lv.scr_act())
     35 slider.center()
     36 
     37 slider.set_mode(lv.slider.MODE.RANGE)
     38 slider.set_value(70, lv.ANIM.OFF)
     39 slider.set_left_value(20, lv.ANIM.OFF)
     40 
     41 slider.add_event_cb(slider_event_cb, lv.EVENT.ALL, None)
     42 slider.refresh_ext_draw_size()
     43