def event_cb(e): dsc = lv.obj_draw_part_dsc_t.cast(e.get_param()) if dsc.part != lv.PART.INDICATOR: return obj = lv.bar.__cast__(e.get_target()) label_dsc = lv.draw_label_dsc_t() label_dsc.init() # label_dsc.font = LV_FONT_DEFAULT; value_txt = str(obj.get_value()) txt_size = lv.point_t() 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) txt_area = lv.area_t() # If the indicator is long enough put the text inside on the right if dsc.draw_area.get_width() > txt_size.x + 20: txt_area.x2 = dsc.draw_area.x2 - 5 txt_area.x1 = txt_area.x2 - txt_size.x + 1 label_dsc.color = lv.color_white() # If the indicator is still short put the text out of it on the right*/ else: txt_area.x1 = dsc.draw_area.x2 + 5 txt_area.x2 = txt_area.x1 + txt_size.x - 1 label_dsc.color = lv.color_black() txt_area.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - txt_size.y) // 2 txt_area.y2 = txt_area.y1 + txt_size.y - 1 lv.draw_label(txt_area, dsc.clip_area, label_dsc, value_txt, None)
def slider_event_cb(e): code = e.get_code() obj = e.get_target() # Provide some extra space for the value if code == lv.EVENT.REFR_EXT_DRAW_SIZE: e.set_ext_draw_size(50) elif code == lv.EVENT.DRAW_PART_END: # print("DRAW_PART_END") dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) # print(dsc) if dsc.part == lv.PART.INDICATOR: label_text = "{:d} - {:d}".format(obj.get_left_value(),slider.get_value()) label_size = lv.point_t() lv.txt_get_size(label_size, label_text, lv.font_default(), 0, 0, lv.COORD.MAX, 0) # print(label_size.x,label_size.y) label_area = lv.area_t() label_area.x1 = dsc.draw_area.x1 + dsc.draw_area.get_width() // 2 - label_size.x // 2 label_area.x2 = label_area.x1 + label_size.x label_area.y2 = dsc.draw_area.y1 - 10 label_area.y1 = label_area.y2 - label_size.y label_draw_dsc = lv.draw_label_dsc_t() label_draw_dsc.init() lv.draw_label(label_area, dsc.clip_area, label_draw_dsc, label_text, None)
def event_cb(self, e): code = e.get_code() chart = lv.chart.__cast__(e.get_target()) if code == lv.EVENT.VALUE_CHANGED: # print("last_id: ",self.last_id) self.last_id = chart.get_pressed_point() if self.last_id != lv.CHART_POINT.NONE: p = lv.point_t() chart.get_point_pos_by_id(self.ser, self.last_id, p) chart.set_cursor_point(self.cursor, None, self.last_id) elif code == lv.EVENT.DRAW_PART_END: # print("EVENT.DRAW_PART_END") dsc = lv.obj_draw_part_dsc_t.cast(e.get_param()) # if dsc.p1 and dsc.p2: # print("p1, p2", dsc.p1,dsc.p2) # print("p1.y, p2.y", dsc.p1.y, dsc.p2.y) # print("last_id: ",self.last_id) if dsc.part == lv.PART.CURSOR and dsc.p1 and dsc.p2 and dsc.p1.y == dsc.p2.y and self.last_id >= 0: v = self.ser_p[self.last_id] # print("value: ",v) value_txt = str(v) size = lv.point_t() lv.txt_get_size(size, value_txt, lv.font_default(), 0, 0, lv.COORD.MAX, lv.TEXT_FLAG.NONE) a = lv.area_t() a.y2 = dsc.p1.y - 5 a.y1 = a.y2 - size.y - 10 a.x1 = dsc.p1.x + 10 a.x2 = a.x1 + size.x + 10 draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE) draw_rect_dsc.radius = 3 lv.draw_rect(a, dsc.clip_area, draw_rect_dsc) draw_label_dsc = lv.draw_label_dsc_t() draw_label_dsc.init() draw_label_dsc.color = lv.color_white() a.x1 += 5 a.x2 -= 5 a.y1 += 5 a.y2 -= 5 lv.draw_label(a, dsc.clip_area, draw_label_dsc, value_txt, None)