From 1b38632b6f89d04a21c172092a88e52e4f6c01fd Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 12 May 2021 12:48:38 +0200 Subject: [PATCH 1/5] refactor(obj draw)rename lv_obj_draw_dsc_t to lv_obj_draw_part_dsc_t --- src/core/lv_obj_draw.c | 4 ++-- src/core/lv_obj_draw.h | 4 ++-- src/core/lv_obj_pos.c | 6 +++--- src/core/lv_obj_pos.h | 4 ++-- src/extra/widgets/calendar/lv_calendar.c | 2 +- src/extra/widgets/chart/lv_chart.c | 12 ++++++------ src/extra/widgets/meter/lv_meter.c | 2 +- src/widgets/lv_arc.c | 2 +- src/widgets/lv_bar.c | 4 ++-- src/widgets/lv_btnmatrix.c | 2 +- src/widgets/lv_checkbox.c | 2 +- src/widgets/lv_slider.c | 2 +- src/widgets/lv_table.c | 2 +- 13 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/core/lv_obj_draw.c b/src/core/lv_obj_draw.c index 4cd2f703b..7fce7714a 100644 --- a/src/core/lv_obj_draw.c +++ b/src/core/lv_obj_draw.c @@ -324,9 +324,9 @@ lv_coord_t lv_obj_calculate_ext_draw_size(lv_obj_t * obj, uint32_t part) return s; } -void lv_obj_draw_dsc_init(lv_obj_draw_dsc_t * dsc, const lv_area_t * clip_area) +void lv_obj_draw_dsc_init(lv_obj_draw_part_dsc_t * dsc, const lv_area_t * clip_area) { - lv_memset_00(dsc, sizeof(lv_obj_draw_dsc_t)); + lv_memset_00(dsc, sizeof(lv_obj_draw_part_dsc_t)); dsc->clip_area = clip_area; } diff --git a/src/core/lv_obj_draw.h b/src/core/lv_obj_draw.h index 27310b8a2..63d4c310f 100644 --- a/src/core/lv_obj_draw.h +++ b/src/core/lv_obj_draw.h @@ -49,7 +49,7 @@ typedef struct uint32_t id; uint32_t part; const void * sub_part_ptr; -}lv_obj_draw_dsc_t; +}lv_obj_draw_part_dsc_t; /********************** * GLOBAL PROTOTYPES @@ -118,7 +118,7 @@ lv_coord_t lv_obj_calculate_ext_draw_size(struct _lv_obj_t * obj, uint32_t part) * @param dsc pointer to a descriptor. Later it should be passed as parameter to an `LV_EEVNT_DRAW_PART_BEGIN/END` event. * @param clip_area the current clip area of the drawing */ -void lv_obj_draw_dsc_init(lv_obj_draw_dsc_t * dsc, const lv_area_t * clip_area); +void lv_obj_draw_dsc_init(lv_obj_draw_part_dsc_t * dsc, const lv_area_t * clip_area); /** * Send a 'LV_EVENT_REFR_EXT_DRAW_SIZE' Call the ancestor's event handler to the object to refresh the value of the extended draw size. diff --git a/src/core/lv_obj_pos.c b/src/core/lv_obj_pos.c index eebfc9950..eefd612df 100644 --- a/src/core/lv_obj_pos.c +++ b/src/core/lv_obj_pos.c @@ -590,21 +590,21 @@ void lv_obj_get_content_coords(const lv_obj_t * obj, lv_area_t * area) } -lv_coord_t lv_obj_get_self_width(struct _lv_obj_t * obj) +lv_coord_t lv_obj_get_self_width(const lv_obj_t * obj) { lv_point_t p = {0, LV_COORD_MIN}; lv_event_send((lv_obj_t * )obj, LV_EVENT_REFR_SELF_SIZE, &p); return p.x; } -lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj) +lv_coord_t lv_obj_get_self_height(const lv_obj_t * obj) { lv_point_t p = {LV_COORD_MIN, 0}; lv_event_send((lv_obj_t * )obj, LV_EVENT_REFR_SELF_SIZE, &p); return p.y; } -bool lv_obj_refresh_self_size(struct _lv_obj_t * obj) +bool lv_obj_refresh_self_size(lv_obj_t * obj) { lv_coord_t w_set = lv_obj_get_style_width(obj, LV_PART_MAIN); lv_coord_t h_set = lv_obj_get_style_height(obj, LV_PART_MAIN); diff --git a/src/core/lv_obj_pos.h b/src/core/lv_obj_pos.h index 6b2313053..ab2acb7f5 100644 --- a/src/core/lv_obj_pos.h +++ b/src/core/lv_obj_pos.h @@ -277,7 +277,7 @@ void lv_obj_get_content_coords(const struct _lv_obj_t * obj, lv_area_t * area); * @note This size independent from the real size of the widget. * It just tells how large the internal ("virtual") content is. */ -lv_coord_t lv_obj_get_self_width(struct _lv_obj_t * obj); +lv_coord_t lv_obj_get_self_width(const struct _lv_obj_t * obj); /** * Get the height occupied by the "parts" of the widget. E.g. the height of all rows of a table. @@ -286,7 +286,7 @@ lv_coord_t lv_obj_get_self_width(struct _lv_obj_t * obj); * @note This size independent from the real size of the widget. * It just tells how large the internal ("virtual") content is. */ -lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj); +lv_coord_t lv_obj_get_self_height(const struct _lv_obj_t * obj); /** * Handle if the size of the internal ("virtual") content of an object has changed. diff --git a/src/extra/widgets/calendar/lv_calendar.c b/src/extra/widgets/calendar/lv_calendar.c index 7e84fd285..b3278c746 100644 --- a/src/extra/widgets/calendar/lv_calendar.c +++ b/src/extra/widgets/calendar/lv_calendar.c @@ -255,7 +255,7 @@ static void lv_calendar_constructor(const lv_obj_class_t * class_p, lv_obj_t * o static void draw_part_begin_event_cb(lv_event_t * e) { lv_obj_t * obj = lv_event_get_target(e); - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); if(dsc->part == LV_PART_ITEMS) { /*Day name styles*/ if(dsc->id < 7) { diff --git a/src/extra/widgets/chart/lv_chart.c b/src/extra/widgets/chart/lv_chart.c index c5c59e28c..06cb55407 100644 --- a/src/extra/widgets/chart/lv_chart.c +++ b/src/extra/widgets/chart/lv_chart.c @@ -682,7 +682,7 @@ static void draw_div_lines(lv_obj_t * obj, const lv_area_t * clip_area) lv_draw_line_dsc_init(&line_dsc); lv_obj_init_draw_line_dsc(obj, LV_PART_MAIN, &line_dsc); - lv_obj_draw_dsc_t obj_draw_dsc; + lv_obj_draw_part_dsc_t obj_draw_dsc; lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area); obj_draw_dsc.line_dsc = &line_dsc; obj_draw_dsc.part = LV_PART_MAIN; @@ -804,7 +804,7 @@ static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area) y_tmp = y_tmp / (chart->ymax[ser->y_axis] - chart->ymin[ser->y_axis]); p2.y = h - y_tmp + y_ofs; - lv_obj_draw_dsc_t dsc; + lv_obj_draw_part_dsc_t dsc; lv_obj_draw_dsc_init(&dsc, clip_area); dsc.part = LV_PART_ITEMS; dsc.line_dsc = &line_dsc_default; @@ -941,7 +941,7 @@ static void draw_series_bar(lv_obj_t * obj, const lv_area_t * clip_area) bool mask_ret = _lv_area_intersect(&series_mask, &obj->coords, clip_area); if(mask_ret == false) return; - lv_obj_draw_dsc_t dsc; + lv_obj_draw_part_dsc_t dsc; lv_obj_draw_dsc_init(&dsc, &series_mask); dsc.part = LV_PART_ITEMS; @@ -1009,7 +1009,7 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area) lv_coord_t point_w = lv_obj_get_style_width(obj, LV_PART_CURSOR) / 2; lv_coord_t point_h = lv_obj_get_style_width(obj, LV_PART_CURSOR) / 2; - lv_obj_draw_dsc_t dsc; + lv_obj_draw_part_dsc_t dsc; lv_obj_draw_dsc_init(&dsc, clip_area); dsc.line_dsc = &line_dsc_tmp; dsc.rect_dsc = &point_dsc_tmp; @@ -1106,7 +1106,7 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a minor_len *= -1; } - lv_obj_draw_dsc_t dsc; + lv_obj_draw_part_dsc_t dsc; lv_obj_draw_dsc_init(&dsc, clip_area); dsc.id = axis; dsc.part = LV_PART_TICKS; @@ -1212,7 +1212,7 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area) line_dsc.dash_gap = 0; line_dsc.dash_width = 0; - lv_obj_draw_dsc_t dsc; + lv_obj_draw_part_dsc_t dsc; lv_obj_draw_dsc_init(&dsc, clip_area); dsc.id = LV_CHART_AXIS_X; dsc.part = LV_PART_TICKS; diff --git a/src/extra/widgets/meter/lv_meter.c b/src/extra/widgets/meter/lv_meter.c index ceb7ae9f0..36dfe7102 100644 --- a/src/extra/widgets/meter/lv_meter.c +++ b/src/extra/widgets/meter/lv_meter.c @@ -359,7 +359,7 @@ static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c lv_meter_scale_t * scale; - lv_obj_draw_dsc_t dsc; + lv_obj_draw_part_dsc_t dsc; lv_obj_draw_dsc_init(&dsc, clip_area); #if LV_DRAW_COMPLEX diff --git a/src/widgets/lv_arc.c b/src/widgets/lv_arc.c index 9d918b19b..d775260fc 100644 --- a/src/widgets/lv_arc.c +++ b/src/widgets/lv_arc.c @@ -687,7 +687,7 @@ static void lv_arc_draw(lv_event_t * e) lv_coord_t arc_r; get_center(obj, ¢er, &arc_r); - lv_obj_draw_dsc_t obj_draw_dsc; + lv_obj_draw_part_dsc_t obj_draw_dsc; lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area); /*Draw the background arc*/ diff --git a/src/widgets/lv_bar.c b/src/widgets/lv_bar.c index 2b380c16d..56ffd12d5 100644 --- a/src/widgets/lv_bar.c +++ b/src/widgets/lv_bar.c @@ -382,7 +382,7 @@ static void draw_indic(lv_event_t * e) /*Do not draw a zero length indicator but at least call the draw part events*/ if(!sym && indic_length_calc(&bar->indic_area) <= 1) { - lv_obj_draw_dsc_t obj_draw_dsc; + lv_obj_draw_part_dsc_t obj_draw_dsc; lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area); obj_draw_dsc.part = LV_PART_INDICATOR; obj_draw_dsc.draw_area = &bar->indic_area; @@ -403,7 +403,7 @@ static void draw_indic(lv_event_t * e) lv_draw_rect_dsc_init(&draw_rect_dsc); lv_obj_init_draw_rect_dsc(obj, LV_PART_INDICATOR, &draw_rect_dsc); - lv_obj_draw_dsc_t obj_draw_dsc; + lv_obj_draw_part_dsc_t obj_draw_dsc; lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area); obj_draw_dsc.part = LV_PART_INDICATOR; obj_draw_dsc.rect_dsc = &draw_rect_dsc; diff --git a/src/widgets/lv_btnmatrix.c b/src/widgets/lv_btnmatrix.c index 13fb992e2..955ed8e85 100644 --- a/src/widgets/lv_btnmatrix.c +++ b/src/widgets/lv_btnmatrix.c @@ -661,7 +661,7 @@ static void draw_main(lv_event_t * e) char * txt_ap = lv_mem_buf_get(txt_ap_size); #endif - lv_obj_draw_dsc_t dsc; + lv_obj_draw_part_dsc_t dsc; lv_obj_draw_dsc_init(&dsc, clip_area); dsc.part = LV_PART_ITEMS; dsc.rect_dsc = &draw_rect_dsc_act; diff --git a/src/widgets/lv_checkbox.c b/src/widgets/lv_checkbox.c index c173fd0e8..622ba55c5 100644 --- a/src/widgets/lv_checkbox.c +++ b/src/widgets/lv_checkbox.c @@ -234,7 +234,7 @@ static void lv_checkbox_draw(lv_event_t * e) marker_area_transf.y1 -= transf_h; marker_area_transf.y2 += transf_h; - lv_obj_draw_dsc_t obj_draw_dsc; + lv_obj_draw_part_dsc_t obj_draw_dsc; lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area); obj_draw_dsc.rect_dsc = &indic_dsc; obj_draw_dsc.draw_area = &marker_area_transf; diff --git a/src/widgets/lv_slider.c b/src/widgets/lv_slider.c index 835f82bb2..b7a8e66af 100644 --- a/src/widgets/lv_slider.c +++ b/src/widgets/lv_slider.c @@ -372,7 +372,7 @@ static void draw_knob(lv_event_t * e) position_knob(obj, &knob_area, knob_size, hor); lv_area_copy(&slider->right_knob_area, &knob_area); - lv_obj_draw_dsc_t dsc; + lv_obj_draw_part_dsc_t dsc; lv_obj_draw_dsc_init(&dsc, clip_area); dsc.part = LV_PART_KNOB; dsc.id = 0; diff --git a/src/widgets/lv_table.c b/src/widgets/lv_table.c index 16c53a666..a43a61d77 100644 --- a/src/widgets/lv_table.c +++ b/src/widgets/lv_table.c @@ -619,7 +619,7 @@ static void draw_main(lv_event_t * e) bool rtl = lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL ? true : false; /*Handle custom drawer*/ - lv_obj_draw_dsc_t dsc; + lv_obj_draw_part_dsc_t dsc; lv_obj_draw_dsc_init(&dsc, clip_area); dsc.part = LV_PART_ITEMS; dsc.rect_dsc = &rect_dsc_act; From 75d1c05a23a847aa9b63c97dbb1c777627da9166 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 12 May 2021 12:49:32 +0200 Subject: [PATCH 2/5] feat(event) add lv_event_get_indev/clip_area/draw_part_dsc --- examples/widgets/bar/lv_example_bar_6.c | 2 +- .../btnmatrix/lv_example_btnmatrix_2.c | 4 +- examples/widgets/chart/lv_example_chart_2.c | 2 +- examples/widgets/chart/lv_example_chart_3.c | 2 +- examples/widgets/chart/lv_example_chart_4.c | 2 +- examples/widgets/chart/lv_example_chart_6.c | 2 +- examples/widgets/slider/lv_example_slider_3.c | 2 +- examples/widgets/table/lv_example_table_1.c | 2 +- examples/widgets/table/lv_example_table_2.c | 2 +- src/core/lv_event.c | 55 +++++++++++++++++++ src/core/lv_event.h | 22 ++++++++ 11 files changed, 87 insertions(+), 10 deletions(-) diff --git a/examples/widgets/bar/lv_example_bar_6.c b/examples/widgets/bar/lv_example_bar_6.c index b79f52b13..fca3d5306 100644 --- a/examples/widgets/bar/lv_example_bar_6.c +++ b/examples/widgets/bar/lv_example_bar_6.c @@ -8,7 +8,7 @@ static void set_value(void *bar, int32_t v) static void event_cb(lv_event_t * e) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); if(dsc->part != LV_PART_INDICATOR) return; lv_obj_t * obj= lv_event_get_target(e); diff --git a/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c b/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c index cc63db9ab..620156207 100644 --- a/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c +++ b/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c @@ -7,7 +7,7 @@ static void event_cb(lv_event_t * e) lv_event_code_t code = lv_event_get_code(e); lv_obj_t * obj = lv_event_get_target(e); if(code == LV_EVENT_DRAW_PART_BEGIN) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); /*Change the draw descriptor the 2nd button*/ if(dsc->id == 1) { @@ -34,7 +34,7 @@ static void event_cb(lv_event_t * e) } } if(code == LV_EVENT_DRAW_PART_END) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); /*Add custom content to the 4th button when the button itself was drawn*/ if(dsc->id == 3) { diff --git a/examples/widgets/chart/lv_example_chart_2.c b/examples/widgets/chart/lv_example_chart_2.c index 029b5f3aa..cd1d85fef 100644 --- a/examples/widgets/chart/lv_example_chart_2.c +++ b/examples/widgets/chart/lv_example_chart_2.c @@ -10,7 +10,7 @@ static void draw_event_cb(lv_event_t * e) lv_obj_t * obj = lv_event_get_target(e); /*Add the faded area before the lines are drawn*/ - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e); if(dsc->part == LV_PART_ITEMS) { if(!dsc->p1 || !dsc->p2) return; diff --git a/examples/widgets/chart/lv_example_chart_3.c b/examples/widgets/chart/lv_example_chart_3.c index 8dec5591b..51842409b 100644 --- a/examples/widgets/chart/lv_example_chart_3.c +++ b/examples/widgets/chart/lv_example_chart_3.c @@ -3,7 +3,7 @@ static void draw_event_cb(lv_event_t * e) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); if(dsc->part == LV_PART_TICKS && dsc->id == LV_CHART_AXIS_X) { 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]); diff --git a/examples/widgets/chart/lv_example_chart_4.c b/examples/widgets/chart/lv_example_chart_4.c index e1f9cf48b..d447523df 100644 --- a/examples/widgets/chart/lv_example_chart_4.c +++ b/examples/widgets/chart/lv_example_chart_4.c @@ -45,7 +45,7 @@ static void event_cb(lv_event_t * e) a.y1 = chart->coords.y1 + p.y - 30; a.y2 = chart->coords.y1 + p.y - 10; - const lv_area_t * clip_area = lv_event_get_param(e); + const lv_area_t * clip_area = lv_event_get_clip_area(e); lv_draw_rect(&a, clip_area, &draw_rect_dsc); ser = lv_chart_get_series_next(chart, ser); diff --git a/examples/widgets/chart/lv_example_chart_6.c b/examples/widgets/chart/lv_example_chart_6.c index a4d2dd6eb..7c544bdbf 100644 --- a/examples/widgets/chart/lv_example_chart_6.c +++ b/examples/widgets/chart/lv_example_chart_6.c @@ -20,7 +20,7 @@ static void event_cb(lv_event_t * e) } } else if(code == LV_EVENT_DRAW_PART_END) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + 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_array(chart, ser); lv_coord_t v = data_array[last_id]; diff --git a/examples/widgets/slider/lv_example_slider_3.c b/examples/widgets/slider/lv_example_slider_3.c index cb854c4fe..6f97e0197 100644 --- a/examples/widgets/slider/lv_example_slider_3.c +++ b/examples/widgets/slider/lv_example_slider_3.c @@ -33,7 +33,7 @@ static void slider_event_cb(lv_event_t * e) *size = LV_MAX(*size, 50); } else if(code == LV_EVENT_DRAW_PART_END) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); if(dsc->part == LV_PART_INDICATOR) { char buf[16]; lv_snprintf(buf, sizeof(buf), "%d - %d", lv_slider_get_left_value(obj), lv_slider_get_value(obj)); diff --git a/examples/widgets/table/lv_example_table_1.c b/examples/widgets/table/lv_example_table_1.c index 3c32ad34f..823acd5c9 100644 --- a/examples/widgets/table/lv_example_table_1.c +++ b/examples/widgets/table/lv_example_table_1.c @@ -4,7 +4,7 @@ static void draw_part_event_cb(lv_event_t * e) { lv_obj_t * obj = lv_event_get_target(e); - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); /*If the cells are drawn...*/ if(dsc->part == LV_PART_ITEMS) { uint32_t row = dsc->id / lv_table_get_col_cnt(obj); diff --git a/examples/widgets/table/lv_example_table_2.c b/examples/widgets/table/lv_example_table_2.c index bb44600e2..483bbca2c 100644 --- a/examples/widgets/table/lv_example_table_2.c +++ b/examples/widgets/table/lv_example_table_2.c @@ -6,7 +6,7 @@ static void draw_event_cb(lv_event_t * e) { lv_obj_t * obj = lv_event_get_target(e); - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e); /*If the cells are drawn...*/ if(dsc->part == LV_PART_ITEMS) { bool chk = lv_table_has_cell_ctrl(obj, dsc->id, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); diff --git a/src/core/lv_event.c b/src/core/lv_event.c index d42ac0c79..982192b8a 100644 --- a/src/core/lv_event.c +++ b/src/core/lv_event.c @@ -212,6 +212,61 @@ bool lv_obj_remove_event_dsc(lv_obj_t * obj, struct _lv_event_dsc_t * event_dsc) return false; } +lv_indev_t * lv_event_get_indev(lv_event_t * e) +{ + + if(e->code == LV_EVENT_PRESSED || + e->code == LV_EVENT_PRESSING || + e->code == LV_EVENT_PRESS_LOST || + e->code == LV_EVENT_SHORT_CLICKED || + e->code == LV_EVENT_LONG_PRESSED || + e->code == LV_EVENT_LONG_PRESSED_REPEAT || + e->code == LV_EVENT_CLICKED || + e->code == LV_EVENT_RELEASED || + e->code == LV_EVENT_SCROLL_BEGIN || + e->code == LV_EVENT_SCROLL_END || + e->code == LV_EVENT_SCROLL || + e->code == LV_EVENT_GESTURE || + e->code == LV_EVENT_KEY || + e->code == LV_EVENT_FOCUSED || + e->code == LV_EVENT_DEFOCUSED || + e->code == LV_EVENT_LEAVE) + { + return lv_event_get_param(e); + } else { + LV_LOG_WARN("Not interpreted with this event code"); + return NULL; + } +} + +lv_obj_draw_part_dsc_t * lv_event_get_draw_part_dsc(lv_event_t * e) +{ + if(e->code == LV_EVENT_DRAW_PART_BEGIN|| + e->code == LV_EVENT_DRAW_PART_END) + { + return lv_event_get_param(e); + } else { + LV_LOG_WARN("Not interpreted with this event code"); + return NULL; + } +} + +const lv_area_t * lv_event_get_clip_area(lv_event_t * e) +{ + if(e->code == LV_EVENT_DRAW_MAIN || + e->code == LV_EVENT_DRAW_MAIN_BEGIN || + e->code == LV_EVENT_DRAW_MAIN_END || + e->code == LV_EVENT_DRAW_POST || + e->code == LV_EVENT_DRAW_POST_BEGIN || + e->code == LV_EVENT_DRAW_POST_END) + { + return lv_event_get_param(e); + } else { + LV_LOG_WARN("Not interpreted with this event code"); + return NULL; + } +} + /********************** * STATIC FUNCTIONS diff --git a/src/core/lv_event.h b/src/core/lv_event.h index efc319d11..6652bf8ae 100644 --- a/src/core/lv_event.h +++ b/src/core/lv_event.h @@ -206,6 +206,28 @@ bool lv_obj_remove_event_cb(struct _lv_obj_t * obj, lv_event_cb_t event_cb); */ bool lv_obj_remove_event_dsc(struct _lv_obj_t * obj, struct _lv_event_dsc_t * event_dsc); +/** + * Get the input device passed as parameter to indev related events. + * @param e pointer to an event + * @return the indev that triggered the event or NULL if called on a not indev related event + */ +lv_indev_t * lv_event_get_indev(lv_event_t * e); + +/** + * Get the part draw descriptor passed as parameter to `LV_EVENT_DRAW_PART_BEGIN/END`. + * @param e pointer to an event + * @return the part draw descriptor to hook the drawing or NULL if called on an unrelated event + */ +lv_obj_draw_part_dsc_t * lv_event_get_draw_part_dsc(lv_event_t * e); + +/** + * Get the clip area passed as parameter to draw events events. + * Namely: `LV_EVENT_DRAW_MAIN/POST`, `LV_EVENT_DRAW_MAIN/POST_BEGIN`, `LV_EVENT_DRAW_MAIN/POST_END` + * @param e pointer to an event + * @return the clip area to use during drawing or NULL if called on an unrelated event + */ +const lv_area_t * lv_event_get_clip_area(lv_event_t * e); + /********************** * MACROS **********************/ From 08a1b04fdf7c8dc4ff3c70f63ad847802f09348e Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 12 May 2021 12:57:12 +0200 Subject: [PATCH 3/5] feat(style) add user_data paramter to lv_style_transition_dsc_init --- examples/widgets/btn/lv_example_btn_2.c | 2 +- examples/widgets/btn/lv_example_btn_3.c | 4 ++-- examples/widgets/imgbtn/lv_example_imgbtn_1.c | 2 +- examples/widgets/slider/lv_example_slider_2.c | 2 +- src/extra/themes/default/lv_theme_default.c | 4 ++-- src/misc/lv_style.c | 5 ++++- src/misc/lv_style.h | 7 ++++--- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/widgets/btn/lv_example_btn_2.c b/examples/widgets/btn/lv_example_btn_2.c index 21e27ac82..addde71ab 100644 --- a/examples/widgets/btn/lv_example_btn_2.c +++ b/examples/widgets/btn/lv_example_btn_2.c @@ -47,7 +47,7 @@ void lv_example_btn_2(void) /*Add a transition to the the outline*/ static lv_style_transition_dsc_t trans; static lv_style_prop_t props[] = {LV_STYLE_OUTLINE_WIDTH, LV_STYLE_OUTLINE_OPA, 0}; - lv_style_transition_dsc_init(&trans, props, lv_anim_path_linear, 300, 0); + lv_style_transition_dsc_init(&trans, props, lv_anim_path_linear, 300, 0, NULL); lv_style_set_transition(&style_pr, &trans); diff --git a/examples/widgets/btn/lv_example_btn_3.c b/examples/widgets/btn/lv_example_btn_3.c index 49ee2b1e3..1b8ef662a 100644 --- a/examples/widgets/btn/lv_example_btn_3.c +++ b/examples/widgets/btn/lv_example_btn_3.c @@ -14,12 +14,12 @@ void lv_example_btn_3(void) /*Transition descriptor when going back to the default state. *Add some delay to be sure the press transition is visible even if the press was very short*/ static lv_style_transition_dsc_t transition_dsc_def; - lv_style_transition_dsc_init(&transition_dsc_def, props, lv_anim_path_overshoot, 250, 100); + lv_style_transition_dsc_init(&transition_dsc_def, props, lv_anim_path_overshoot, 250, 100, NULL); /*Transition descriptor when going to pressed state. *No delay, go to presses state immediately*/ static lv_style_transition_dsc_t transition_dsc_pr; - lv_style_transition_dsc_init(&transition_dsc_pr, props, lv_anim_path_ease_in_out, 250, 0); + lv_style_transition_dsc_init(&transition_dsc_pr, props, lv_anim_path_ease_in_out, 250, 0, NULL); /*Add only the new transition to he default state*/ static lv_style_t style_def; diff --git a/examples/widgets/imgbtn/lv_example_imgbtn_1.c b/examples/widgets/imgbtn/lv_example_imgbtn_1.c index ef51b3f5c..4fcb62e42 100644 --- a/examples/widgets/imgbtn/lv_example_imgbtn_1.c +++ b/examples/widgets/imgbtn/lv_example_imgbtn_1.c @@ -10,7 +10,7 @@ void lv_example_imgbtn_1(void) /*Create a transition animation on width transformation and recolor.*/ static lv_style_prop_t tr_prop[] = {LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_IMG_RECOLOR_OPA, 0}; static lv_style_transition_dsc_t tr; - lv_style_transition_dsc_init(&tr, tr_prop, lv_anim_path_linear, 200, 0); + lv_style_transition_dsc_init(&tr, tr_prop, lv_anim_path_linear, 200, 0, NULL); static lv_style_t style_def; lv_style_init(&style_def); diff --git a/examples/widgets/slider/lv_example_slider_2.c b/examples/widgets/slider/lv_example_slider_2.c index 183ca3b56..883d61f34 100644 --- a/examples/widgets/slider/lv_example_slider_2.c +++ b/examples/widgets/slider/lv_example_slider_2.c @@ -11,7 +11,7 @@ void lv_example_slider_2(void) /*Create a transition*/ static const lv_style_prop_t props[] = {LV_STYLE_BG_COLOR, 0}; static lv_style_transition_dsc_t transition_dsc; - lv_style_transition_dsc_init(&transition_dsc, props, lv_anim_path_linear, 300, 0); + lv_style_transition_dsc_init(&transition_dsc, props, lv_anim_path_linear, 300, 0, NULL); static lv_style_t style_main; static lv_style_t style_indicator; diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index 10be2b22c..99d809deb 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -213,10 +213,10 @@ static void style_init(void) color_grey = theme.flags & MODE_DARK ? DARK_COLOR_GREY : LIGHT_COLOR_GREY; static lv_style_transition_dsc_t trans_delayed; - lv_style_transition_dsc_init(&trans_delayed, trans_props, lv_anim_path_linear, TRANSITION_TIME, 70); + lv_style_transition_dsc_init(&trans_delayed, trans_props, lv_anim_path_linear, TRANSITION_TIME, 70, NULL); static lv_style_transition_dsc_t trans_normal; - lv_style_transition_dsc_init(&trans_normal, trans_props, lv_anim_path_linear, TRANSITION_TIME, 0); + lv_style_transition_dsc_init(&trans_normal, trans_props, lv_anim_path_linear, TRANSITION_TIME, 0, NULL); style_init_reset(&styles->transition_delayed); lv_style_set_transition(&styles->transition_delayed, &trans_delayed); /*Go back to default state with delay*/ diff --git a/src/misc/lv_style.c b/src/misc/lv_style.c index e77f5881d..2028e0f1a 100644 --- a/src/misc/lv_style.c +++ b/src/misc/lv_style.c @@ -210,13 +210,16 @@ lv_res_t lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_va return lv_style_get_prop_inlined(style, prop, value); } -void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay) +void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data) { lv_memset_00(tr, sizeof(lv_style_transition_dsc_t)); tr->props = props; tr->path_xcb = path_cb == NULL ? lv_anim_path_linear : path_cb; tr->time = time; tr->delay = delay; +#if LV_USE_USER_DATA + tr->user_data = user_data; +#endif } lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop) diff --git a/src/misc/lv_style.h b/src/misc/lv_style.h index 609676d63..ed0eb4c83 100644 --- a/src/misc/lv_style.h +++ b/src/misc/lv_style.h @@ -385,15 +385,16 @@ static inline lv_res_t lv_style_get_prop_inlined(lv_style_t * style, lv_style_pr * Initialize a transition descriptor. * @param tr pointer to a transition descriptor to initialize * @param props an array with the properties to transition. The last element must be zero. - * @param path_cb and animation path (ease) callback. If `NULL` liner path will be used. + * @param path_cb an animation path (ease) callback. If `NULL` liner path will be used. * @param time duration of the transition in [ms] * @param delay delay before the transition in [ms] + * @param user_data any custom data that will be saved in the transition animation and will be available when `path_cb` is called * @example * const static lv_style_prop_t trans_props[] = { LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR, 0 }; * static lv_style_transition_dsc_t trans1; - * lv_style_transition_dsc_init(&trans1, trans_props, NULL, 300, 0); + * lv_style_transition_dsc_init(&trans1, trans_props, NULL, 300, 0, NULL); */ -void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay); +void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data); /** * Get the default value of a property From 0117320c30c40f544c5cf9514cc5813e00abfe6d Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 12 May 2021 13:01:32 +0200 Subject: [PATCH 4/5] fix warning --- src/misc/lv_style.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/misc/lv_style.c b/src/misc/lv_style.c index 2028e0f1a..704ccee7c 100644 --- a/src/misc/lv_style.c +++ b/src/misc/lv_style.c @@ -219,6 +219,8 @@ void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style tr->delay = delay; #if LV_USE_USER_DATA tr->user_data = user_data; +#else + LV_UNUSED(user_data); #endif } From 039ed0baa6443e08da7e45f635e019e18af73bf8 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 12 May 2021 14:21:27 +0200 Subject: [PATCH 5/5] feat(indev) change the prototype of indev read_cb Instead of returning bool to indicate that there is more data to read set data->continue_reading = true. It's less error porne because if the user doesn't set the flag the indev will be read once which is usually the inteded behaviour. --- examples/porting/lv_port_indev_template.c | 33 +++++++---------------- src/core/lv_indev.c | 7 ++--- src/hal/lv_hal_indev.c | 9 ++----- src/hal/lv_hal_indev.h | 10 +++---- 4 files changed, 19 insertions(+), 40 deletions(-) diff --git a/examples/porting/lv_port_indev_template.c b/examples/porting/lv_port_indev_template.c index 2a6320cdd..53042bcf2 100644 --- a/examples/porting/lv_port_indev_template.c +++ b/examples/porting/lv_port_indev_template.c @@ -24,17 +24,17 @@ **********************/ static void touchpad_init(void); -static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); +static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); static bool touchpad_is_pressed(void); static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y); static void mouse_init(void); -static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); +static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); static bool mouse_is_pressed(void); static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y); static void keypad_init(void); -static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); +static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); static uint32_t keypad_get_key(void); static void encoder_init(void); @@ -42,7 +42,7 @@ static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); static void encoder_handler(void); static void button_init(void); -static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); +static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); static int8_t button_get_pressed_id(void); static bool button_is_pressed(uint8_t id); @@ -185,7 +185,7 @@ static void touchpad_init(void) } /*Will be called by the library to read the touchpad*/ -static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) +static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { static lv_coord_t last_x = 0; static lv_coord_t last_y = 0; @@ -201,9 +201,6 @@ static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) /*Set the last pressed coordinates*/ data->point.x = last_x; data->point.y = last_y; - - /*Return `false` because we are not buffering and no more data to read*/ - return false; } /*Return true is the touchpad is pressed*/ @@ -234,7 +231,7 @@ static void mouse_init(void) } /*Will be called by the library to read the mouse*/ -static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) +static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { /*Get the current x and y coordinates*/ mouse_get_xy(&data->point.x, &data->point.y); @@ -245,9 +242,6 @@ static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) } else { data->state = LV_INDEV_STATE_REL; } - - /*Return `false` because we are not buffering and no more data to read*/ - return false; } /*Return true is the mouse button is pressed*/ @@ -278,7 +272,7 @@ static void keypad_init(void) } /*Will be called by the library to read the mouse*/ -static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) +static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { static uint32_t last_key = 0; @@ -315,9 +309,6 @@ static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) } data->key = last_key; - - /*Return `false` because we are not buffering and no more data to read*/ - return false; } /*Get the currently being pressed key. 0 if no key is pressed*/ @@ -339,14 +330,11 @@ static void encoder_init(void) } /*Will be called by the library to read the encoder*/ -static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) +static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { data->enc_diff = encoder_diff; data->state = encoder_state; - - /*Return `false` because we are not buffering and no more data to read*/ - return false; } /*Call this function in an interrupt to process encoder events (turn, press)*/ @@ -369,7 +357,7 @@ static void button_init(void) } /*Will be called by the library to read the button*/ -static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) +static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { static uint8_t last_btn = 0; @@ -386,9 +374,6 @@ static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) /*Save the last pressed button's ID*/ data->btn_id = last_btn; - - /*Return `false` because we are not buffering and no more data to read*/ - return false; } /*Get ID (0, 1, 2 ..) of the pressed button*/ diff --git a/src/core/lv_indev.c b/src/core/lv_indev.c index a3fb56e95..3c22d1501 100644 --- a/src/core/lv_indev.c +++ b/src/core/lv_indev.c @@ -76,10 +76,11 @@ void lv_indev_read_timer_cb(lv_timer_t * timer) indev_proc_reset_query_handler(indev_act); if(indev_act->proc.disabled) return; - bool more_to_read; + bool continue_reading; do { /*Read the data*/ - more_to_read = _lv_indev_read(indev_act, &data); + _lv_indev_read(indev_act, &data); + continue_reading = data.continue_reading; /*The active object might deleted even in the read function*/ indev_proc_reset_query_handler(indev_act); @@ -109,7 +110,7 @@ void lv_indev_read_timer_cb(lv_timer_t * timer) } /*Handle reset query if it happened in during processing*/ indev_proc_reset_query_handler(indev_act); - } while(more_to_read); + } while(continue_reading); /*End of indev processing, so no act indev*/ indev_act = NULL; diff --git a/src/hal/lv_hal_indev.c b/src/hal/lv_hal_indev.c index b0779d1b6..72464f863 100644 --- a/src/hal/lv_hal_indev.c +++ b/src/hal/lv_hal_indev.c @@ -127,12 +127,9 @@ lv_indev_t * lv_indev_get_next(lv_indev_t * indev) * Read data from an input device. * @param indev pointer to an input device * @param data input device will write its data here - * @return false: no more data; true: there more data to read (buffered) */ -bool _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) +void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) { - bool cont = false; - lv_memset_00(data, sizeof(lv_indev_data_t)); /* For touchpad sometimes users don't set the last pressed coordinate on release. @@ -152,13 +149,11 @@ bool _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) if(indev->driver->read_cb) { INDEV_TRACE("calling indev_read_cb"); - cont = indev->driver->read_cb(indev->driver, data); + indev->driver->read_cb(indev->driver, data); } else { LV_LOG_WARN("indev_read_cb is not registered"); } - - return cont; } /********************** diff --git a/src/hal/lv_hal_indev.h b/src/hal/lv_hal_indev.h index 16df69810..d52b0e2df 100644 --- a/src/hal/lv_hal_indev.h +++ b/src/hal/lv_hal_indev.h @@ -81,6 +81,7 @@ typedef struct { int16_t enc_diff; /**< For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/ lv_indev_state_t state; /**< LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/ + bool continue_reading; /**< Call the read callback until it's set to true*/ } lv_indev_data_t; /** Initialized by the user and registered by 'lv_indev_add()'*/ @@ -89,10 +90,8 @@ typedef struct _lv_indev_drv_t { /**< Input device type*/ lv_indev_type_t type; - /**< Function pointer to read input device data. - * Return 'true' if there is more data to be read (buffered). - * Most drivers can safely return 'false'*/ - bool (*read_cb)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data); + /**< Function pointer to read input device data.*/ + void (*read_cb)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data); /** Called when an action happened on the input device. * The second parameter is the event from `lv_event_t`*/ @@ -220,9 +219,8 @@ lv_indev_t * lv_indev_get_next(lv_indev_t * indev); * Read data from an input device. * @param indev pointer to an input device * @param data input device will write its data here - * @return false: no more data; true: there more data to read (buffered) */ -bool _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data); +void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data); /********************** * MACROS