def draw_event_cb(e): obj = e.get_target() cont_a = lv.area_t() obj.get_coords(cont_a) #Add the faded area before the lines are drawn dsc = e.get_draw_part_dsc() if dsc.part == lv.PART.ITEMS: if not dsc.p1 or not dsc.p2: return # Add a line mask that keeps the area below the line line_mask_param = lv.draw_mask_line_param_t() line_mask_param.points_init(dsc.p1.x, dsc.p1.y, dsc.p2.x, dsc.p2.y, lv.DRAW_MASK_LINE_SIDE.BOTTOM) line_mask_id = lv.draw_mask_add(line_mask_param, None) #Draw a rectangle that will be affected by the mask draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_opa = lv.OPA.COVER draw_rect_dsc.bg_color = dsc.line_dsc.color a = lv.area_t() a.x1 = dsc.p1.x a.x2 = dsc.p2.x a.y1 = min(dsc.p1.y, dsc.p2.y) a.y2 = cont_a.y2 - 13 # -13 cuts off where the rectangle draws over the chart margin. Without this an area of 0 doesn't look like 0 lv.draw_rect(a, dsc.clip_area, draw_rect_dsc) # Remove the mask lv.draw_mask_free_param(line_mask_param) lv.draw_mask_remove_id(line_mask_id)
def draw_event_cb(e): obj = e.get_target() dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) # If the cells are drawn... if dsc.part == lv.PART.ITEMS: chk = obj.has_cell_ctrl(dsc.id, 0, lv.table.CELL_CTRL.CUSTOM_1) rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() if chk: rect_dsc.bg_color = lv.theme_get_color_primary(obj) else: rect_dsc.bg_color = lv.palette_lighten(lv.PALETTE.GREY,2) rect_dsc.radius = lv.RADIUS.CIRCLE sw_area = lv.area_t() sw_area.x1 = dsc.draw_area.x2 - 50; sw_area.x2 = sw_area.x1 + 40; sw_area.y1 = dsc.draw_area.y1 + dsc.draw_area.get_height() // 2 - 10 sw_area.y2 = sw_area.y1 + 20; lv.draw_rect(sw_area, dsc.clip_area, rect_dsc) rect_dsc.bg_color = lv.color_white() if chk: sw_area.x2 -= 2 sw_area.x1 = sw_area.x2 - 16 else: sw_area.x1 += 2 sw_area.x2 = sw_area.x1 + 16 sw_area.y1 += 2; sw_area.y2 -= 2; lv.draw_rect(sw_area, dsc.clip_area, rect_dsc)
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)
def chart_event_cb(e): dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) if (dsc.part == lv.PART.ITEMS): draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() a = lv.area_t() a.x1 = dsc.draw_area.x1 a.x2 = dsc.draw_area.x2 a.y1 = dsc.draw_area.y1 a.y2 = a.y1 + 6 draw_rect_dsc.bg_color = lv.color_white() draw_rect_dsc.radius = 0 draw_rect_dsc.shadow_opa = 0 lv.draw_rect(a, dsc.clip_area, draw_rect_dsc)
def draw_event_cb(e): obj = lv.obj.__cast__(e.get_target()) # Add the faded area before the lines are drawn dsc = lv.obj_draw_part_dsc_t.cast(e.get_param()) if dsc.part != lv.PART.ITEMS: return if not dsc.p1 or not dsc.p2: return # Add a line mask that keeps the area below the line line_mask_param = lv.draw_mask_line_param_t() line_mask_param.points_init(dsc.p1.x, dsc.p1.y, dsc.p2.x, dsc.p2.y, lv.DRAW_MASK_LINE_SIDE.BOTTOM) # line_mask_id = line_mask_param.draw_mask_add(None) line_mask_id = lv.draw_mask_add(line_mask_param, None) # Add a fade effect: transparent bottom covering top h = obj.get_height() fade_mask_param = lv.draw_mask_fade_param_t() coords = lv.area_t() obj.get_coords(coords) fade_mask_param.init(coords, lv.OPA.COVER, coords.y1 + h // 8, lv.OPA.TRANSP, coords.y2) fade_mask_id = lv.draw_mask_add(fade_mask_param, None) # Draw a rectangle that will be affected by the mask draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_opa = lv.OPA._20 draw_rect_dsc.bg_color = dsc.line_dsc.color a = lv.area_t() a.x1 = dsc.p1.x a.x2 = dsc.p2.x - 1 a.y1 = min(dsc.p1.y, dsc.p2.y) coords = lv.area_t() obj.get_coords(coords) a.y2 = coords.y2 lv.draw_rect(a, dsc.clip_area, draw_rect_dsc) # Remove the masks lv.draw_mask_remove_id(line_mask_id) lv.draw_mask_remove_id(fade_mask_id)
def event_cb(e): code = e.get_code() chart = e.get_target() if code == lv.EVENT.VALUE_CHANGED: chart.invalidate() if code == lv.EVENT.REFR_EXT_DRAW_SIZE: e.set_ext_draw_size(20) elif code == lv.EVENT.DRAW_POST_END: id = lv.chart.get_pressed_point(chart) if id == lv.CHART_POINT.NONE: return # print("Selected point ", id) for i in range(len(series)): p = lv.point_t() chart.get_point_pos_by_id(series[i], id, p) value = series_points[i][id] buf = lv.SYMBOL.DUMMY + "$" + str(value) draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_color = lv.color_black() draw_rect_dsc.bg_opa = lv.OPA._50 draw_rect_dsc.radius = 3 draw_rect_dsc.bg_img_src = buf draw_rect_dsc.bg_img_recolor = lv.color_white() a = lv.area_t() coords = lv.area_t() chart.get_coords(coords) a.x1 = coords.x1 + p.x - 20 a.x2 = coords.x1 + p.x + 20 a.y1 = coords.y1 + p.y - 30 a.y2 = coords.y1 + p.y - 10 clip_area = lv.area_t.cast(e.get_param()) lv.draw_rect(a, clip_area, draw_rect_dsc) elif code == lv.EVENT.RELEASED: chart.invalidate()