feat(event, widgets) improve the paramter of LV_EVENT_DRAW_PART_BEGIN/END
Add lv_<widget>_draw_part_type_t to widgets to precisly describe the hooked drawings. Also add class_p element to lv_obj_draw_part_dsc_t to show what widgets lv_<widget>_draw_part_type_t needs to be used. Related to: https://forum.lvgl.io/t/how-to-add-minor-division-lines-to-a-chart/5366/
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
|
||||
static void draw_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e);
|
||||
if(dsc->part == LV_PART_TICKS && dsc->id == LV_CHART_AXIS_PRIMARY_X) {
|
||||
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
|
||||
if(!lv_obj_draw_part_check_type(dsc, &lv_chart_class, LV_CHART_DRAW_PART_TICK_LABEL)) return;
|
||||
|
||||
if(dsc->id == LV_CHART_AXIS_PRIMARY_X && dsc->text) {
|
||||
const char * month[] = {"Jan", "Febr", "March", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec"};
|
||||
lv_snprintf(dsc->text, sizeof(dsc->text), "%s", month[dsc->value]);
|
||||
dsc->text = month[dsc->value];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,37 +19,38 @@ static void event_cb(lv_event_t * e)
|
||||
}
|
||||
else if(code == LV_EVENT_DRAW_PART_END) {
|
||||
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
|
||||
if(dsc->part == LV_PART_CURSOR && dsc->p1 && dsc->p2 && dsc->p1->y == dsc->p2->y && last_id >= 0) {
|
||||
lv_coord_t * data_array = lv_chart_get_y_array(chart, ser);
|
||||
lv_coord_t v = data_array[last_id];
|
||||
char buf[16];
|
||||
lv_snprintf(buf, sizeof(buf), "%d", v);
|
||||
if(!lv_obj_draw_part_check_type(dsc, &lv_chart_class, LV_CHART_DRAW_PART_CURSOR)) return;
|
||||
if(dsc->p1 == NULL || dsc->p2 == NULL || dsc->p1->y != dsc->p2->y || last_id < 0) return;
|
||||
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, buf, LV_FONT_DEFAULT, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE);
|
||||
lv_coord_t * data_array = lv_chart_get_y_array(chart, ser);
|
||||
lv_coord_t v = data_array[last_id];
|
||||
char buf[16];
|
||||
lv_snprintf(buf, sizeof(buf), "%d", v);
|
||||
|
||||
lv_area_t a;
|
||||
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;
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, buf, LV_FONT_DEFAULT, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE);
|
||||
|
||||
lv_draw_rect_dsc_t draw_rect_dsc;
|
||||
lv_draw_rect_dsc_init(&draw_rect_dsc);
|
||||
draw_rect_dsc.bg_color = lv_palette_main(LV_PALETTE_BLUE);
|
||||
draw_rect_dsc.radius = 3;
|
||||
lv_area_t a;
|
||||
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;
|
||||
|
||||
lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc);
|
||||
lv_draw_rect_dsc_t draw_rect_dsc;
|
||||
lv_draw_rect_dsc_init(&draw_rect_dsc);
|
||||
draw_rect_dsc.bg_color = lv_palette_main(LV_PALETTE_BLUE);
|
||||
draw_rect_dsc.radius = 3;
|
||||
|
||||
lv_draw_label_dsc_t draw_label_dsc;
|
||||
lv_draw_label_dsc_init(&draw_label_dsc);
|
||||
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, buf, NULL);
|
||||
}
|
||||
lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc);
|
||||
|
||||
lv_draw_label_dsc_t draw_label_dsc;
|
||||
lv_draw_label_dsc_init(&draw_label_dsc);
|
||||
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, buf, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user