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_bar_6.py (1619B)
1 def set_value(bar, v): 2 bar.set_value(v, lv.ANIM.OFF) 3 4 def event_cb(e): 5 dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) 6 if dsc.part != lv.PART.INDICATOR: 7 return 8 9 obj= e.get_target() 10 11 label_dsc = lv.draw_label_dsc_t() 12 label_dsc.init() 13 # label_dsc.font = LV_FONT_DEFAULT; 14 15 value_txt = str(obj.get_value()) 16 txt_size = lv.point_t() 17 lv.txt_get_size(txt_size, value_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, lv.COORD.MAX, label_dsc.flag) 18 19 txt_area = lv.area_t() 20 # If the indicator is long enough put the text inside on the right 21 if dsc.draw_area.get_width() > txt_size.x + 20: 22 txt_area.x2 = dsc.draw_area.x2 - 5 23 txt_area.x1 = txt_area.x2 - txt_size.x + 1 24 label_dsc.color = lv.color_white() 25 # If the indicator is still short put the text out of it on the right*/ 26 else: 27 txt_area.x1 = dsc.draw_area.x2 + 5 28 txt_area.x2 = txt_area.x1 + txt_size.x - 1 29 label_dsc.color = lv.color_black() 30 31 txt_area.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - txt_size.y) // 2 32 txt_area.y2 = txt_area.y1 + txt_size.y - 1 33 34 dsc.draw_ctx.label(label_dsc, txt_area, value_txt, None) 35 36 # 37 # Custom drawer on the bar to display the current value 38 # 39 40 bar = lv.bar(lv.scr_act()) 41 bar.add_event_cb(event_cb, lv.EVENT.DRAW_PART_END, None) 42 bar.set_size(200, 20) 43 bar.center() 44 45 a = lv.anim_t() 46 a.init() 47 a.set_var(bar) 48 a.set_values(0, 100) 49 a.set_custom_exec_cb(lambda a,val: set_value(bar,val)) 50 a.set_time(2000) 51 a.set_playback_time(2000) 52 a.set_repeat_count(lv.ANIM_REPEAT.INFINITE) 53 lv.anim_t.start(a) 54