From 787dd591c159e0c4202b538fcffe97f6df691c25 Mon Sep 17 00:00:00 2001 From: melnse Date: Wed, 3 Apr 2019 19:34:58 +0300 Subject: [PATCH 1/6] Realization of extended clickable area. Suitable for small lonely objects, which must be clicked. For activation add "#define USE_LV_EXTENDED_CLICK_AREA 1" to lv_conf.h --- src/lv_core/lv_indev.c | 6 +++- src/lv_core/lv_obj.c | 73 ++++++++++++++++++++++++++++++++++++++++++ src/lv_core/lv_obj.h | 23 +++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index 551a79c02..c45fab75c 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -976,7 +976,11 @@ static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj) /*If the point is on this object*/ /*Check its children too*/ - if(lv_area_is_point_on(&obj->coords, &proc->types.pointer.act_point)) { +#if USE_LV_EXTENDED_CLICK_AREA + if(lv_area_is_point_on(&obj->ext_coords, &proc->act_point)) { +#else + if(lv_area_is_point_on(&obj->coords, &proc->act_point)) { +#endif lv_obj_t * i; LV_LL_READ(obj->child_ll, i) { diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index df3f80156..aade84c41 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -55,6 +55,20 @@ static const void * event_act_data; /*Stores the data passed to the ev /********************** * MACROS **********************/ +#if USE_LV_EXTENDED_CLICK_AREA +/** + * Update coordinates of extended clickable area from object's coordinates and ext_paddings + * @param coords coordinates of an object + * @param ext_coords extended coordinates, which will be updated + * @param paddings paddings of extended clickable area + */ +#define UPDATE_EXT_COORDS(coords, ext_coords, paddings) do{\ + ext_coords.x1 = paddings.x1 > coords.x1 ? 0 : coords.x1 - paddings.x1; \ + ext_coords.x2 = coords.x2 + paddings.x2; \ + ext_coords.y1 = paddings.y1 > coords.y1 ? 0 : coords.y1 - paddings.y1; \ + ext_coords.y2 = coords.y2 + paddings.y2; \ + } while(0) +#endif /********************** * GLOBAL FUNCTIONS @@ -147,6 +161,13 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) new_obj->coords.y2 = lv_disp_get_ver_res(NULL) - 1; new_obj->ext_size = 0; +#if USE_LV_EXTENDED_CLICK_AREA + lv_area_copy(&(new_obj->ext_coords), &(new_obj->coords)); + new_obj->ext_paddings.x1 = 0; + new_obj->ext_paddings.x2 = 0; + new_obj->ext_paddings.y1 = 0; + new_obj->ext_paddings.y2 = 0; +#endif /*Init realign*/ #if LV_OBJ_REALIGN new_obj->realign.align = LV_ALIGN_CENTER; @@ -218,6 +239,13 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) LV_OBJ_DEF_HEIGHT; new_obj->ext_size = 0; +#if USE_LV_EXTENDED_CLICK_AREA + lv_area_copy(&(new_obj->ext_coords), &(new_obj->coords)); + new_obj->ext_paddings.x1 = 0; + new_obj->ext_paddings.x2 = 0; + new_obj->ext_paddings.y1 = 0; + new_obj->ext_paddings.y2 = 0; +#endif /*Init realign*/ #if LV_OBJ_REALIGN new_obj->realign.align = LV_ALIGN_CENTER; @@ -273,6 +301,11 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) lv_area_copy(&new_obj->coords, ©->coords); new_obj->ext_size = copy->ext_size; +#if USE_LV_EXTENDED_CLICK_AREA + lv_area_copy(&new_obj->ext_coords, ©->ext_coords); + lv_area_copy(&new_obj->ext_paddings, ©->ext_paddings); +#endif + /*Set free data*/ #if LV_USE_USER_DATA_SINGLE memcpy(&new_obj->user_data, ©->user_data, sizeof(lv_obj_user_data_t)); @@ -559,6 +592,10 @@ void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) obj->coords.x2 += diff.x; obj->coords.y2 += diff.y; +#if USE_LV_EXTENDED_CLICK_AREA + UPDATE_EXT_COORDS(obj->coords, obj->ext_coords, obj->ext_paddings); +#endif + refresh_children_position(obj, diff.x, diff.y); /*Inform the object about its new coordinates*/ @@ -620,6 +657,9 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) obj->coords.x2 = obj->coords.x1 + w - 1; obj->coords.y2 = obj->coords.y1 + h - 1; +#if USE_LV_EXTENDED_CLICK_AREA + UPDATE_EXT_COORDS(obj->coords, obj->ext_coords, obj->ext_paddings); +#endif /*Send a signal to the object with its new coordinates*/ obj->signal_cb(obj, LV_SIGNAL_CORD_CHG, &ori); @@ -643,6 +683,24 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) #endif } +#if USE_LV_EXTENDED_CLICK_AREA +/** + * Set the size of an extended clickable area + * @param obj pointer to an object + * @param w extended width to both sides + * @param h extended height to both sides + */ +void lv_obj_set_ext_paddinds(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) +{ + obj->ext_paddings.x1 = w; + obj->ext_paddings.x2 = w; + obj->ext_paddings.y1 = h; + obj->ext_paddings.y2 = h; + + UPDATE_EXT_COORDS(obj->coords, obj->ext_coords, obj->ext_paddings); +} +#endif + /** * Set the width of an object * @param obj pointer to an object @@ -1571,6 +1629,18 @@ lv_coord_t lv_obj_get_height_fit(lv_obj_t * obj) return lv_obj_get_width(obj) - style->body.padding.top - style->body.padding.bottom; } + +#if USE_LV_EXTENDED_CLICK_AREA +/** + * Copy the extended clickable area size of an object to an area + * @param obj pointer to an object + * @param cords_p pointer to an area to store the size + */ +void lv_obj_get_ext_paddings(const lv_obj_t * obj, lv_area_t * cords_p) +{ + lv_area_copy(cords_p, &obj->ext_paddings); +} + /** * Get the extended size attribute of an object * @param obj pointer to an object @@ -1971,6 +2041,9 @@ static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coor i->coords.x2 += x_diff; i->coords.y2 += y_diff; +#if USE_LV_EXTENDED_CLICK_AREA + UPDATE_EXT_COORDS(i->coords, i->ext_coords, i->ext_paddings); +#endif refresh_children_position(i, x_diff, y_diff); } } diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index febd01a16..417b98817 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -176,6 +176,10 @@ typedef struct _lv_obj_t lv_ll_t child_ll; /*Linked list to store the children objects*/ lv_area_t coords; /*Coordinates of the object (x1, y1, x2, y2)*/ +#if USE_LV_EXTENDED_CLICK_AREA + lv_area_t ext_coords; + lv_area_t ext_paddings; +#endif lv_event_cb_t event_cb; lv_signal_cb_t signal_cb; /*Object type specific signal function*/ @@ -337,6 +341,16 @@ void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y); */ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); +#if USE_LV_EXTENDED_CLICK_AREA +/** + * Set the size of an extended clickable area + * @param obj pointer to an object + * @param w extended width to both sides + * @param h extended height to both sides + */ +void lv_obj_set_ext_paddinds(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); +#endif + /** * Set the width of an object * @param obj pointer to an object @@ -673,6 +687,15 @@ lv_coord_t lv_obj_get_width_fit(lv_obj_t * obj); */ lv_coord_t lv_obj_get_height_fit(lv_obj_t * obj); +#if USE_LV_EXTENDED_CLICK_AREA +/** + * Copy the extended clickable area size of an object to an area + * @param obj pointer to an object + * @param cords_p pointer to an area to store the size + */ +void lv_obj_get_ext_paddings(const lv_obj_t * obj, lv_area_t * cords_p); +#endif + /** * Get the extended size attribute of an object * @param obj pointer to an object From 6e047e6d27280b32c760ec438f141d8feff87ec1 Mon Sep 17 00:00:00 2001 From: melnse Date: Wed, 3 Apr 2019 20:09:33 +0300 Subject: [PATCH 2/6] Fixed typos, changed macro to static function. --- src/lv_core/lv_obj.c | 43 ++++++++++++++++++++++++------------------- src/lv_core/lv_obj.h | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index aade84c41..bbd769700 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -44,6 +44,9 @@ static void refresh_children_style(lv_obj_t * obj); static void delete_children(lv_obj_t * obj); static bool lv_obj_design(lv_obj_t * obj, const lv_area_t * mask_p, lv_design_mode_t mode); static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param); +#if USE_LV_EXTENDED_CLICK_AREA +static void update_ext_coords(lv_area_t *coords, lv_area_t *ext_coords, lv_area_t *paddings); +#endif /********************** * STATIC VARIABLES @@ -55,20 +58,6 @@ static const void * event_act_data; /*Stores the data passed to the ev /********************** * MACROS **********************/ -#if USE_LV_EXTENDED_CLICK_AREA -/** - * Update coordinates of extended clickable area from object's coordinates and ext_paddings - * @param coords coordinates of an object - * @param ext_coords extended coordinates, which will be updated - * @param paddings paddings of extended clickable area - */ -#define UPDATE_EXT_COORDS(coords, ext_coords, paddings) do{\ - ext_coords.x1 = paddings.x1 > coords.x1 ? 0 : coords.x1 - paddings.x1; \ - ext_coords.x2 = coords.x2 + paddings.x2; \ - ext_coords.y1 = paddings.y1 > coords.y1 ? 0 : coords.y1 - paddings.y1; \ - ext_coords.y2 = coords.y2 + paddings.y2; \ - } while(0) -#endif /********************** * GLOBAL FUNCTIONS @@ -593,7 +582,7 @@ void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) obj->coords.y2 += diff.y; #if USE_LV_EXTENDED_CLICK_AREA - UPDATE_EXT_COORDS(obj->coords, obj->ext_coords, obj->ext_paddings); + update_ext_coords(&(obj->coords), &(obj->ext_coords), &(obj->ext_paddings)); #endif refresh_children_position(obj, diff.x, diff.y); @@ -658,7 +647,7 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) obj->coords.y2 = obj->coords.y1 + h - 1; #if USE_LV_EXTENDED_CLICK_AREA - UPDATE_EXT_COORDS(obj->coords, obj->ext_coords, obj->ext_paddings); + update_ext_coords(&(obj->coords), &(obj->ext_coords), &(obj->ext_paddings)); #endif /*Send a signal to the object with its new coordinates*/ @@ -690,14 +679,14 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) * @param w extended width to both sides * @param h extended height to both sides */ -void lv_obj_set_ext_paddinds(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) +void lv_obj_set_ext_paddings(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) { obj->ext_paddings.x1 = w; obj->ext_paddings.x2 = w; obj->ext_paddings.y1 = h; obj->ext_paddings.y2 = h; - UPDATE_EXT_COORDS(obj->coords, obj->ext_coords, obj->ext_paddings); + update_ext_coords(&(obj->coords), &(obj->ext_coords), &(obj->ext_paddings)); } #endif @@ -2042,7 +2031,7 @@ static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coor i->coords.y2 += y_diff; #if USE_LV_EXTENDED_CLICK_AREA - UPDATE_EXT_COORDS(i->coords, i->ext_coords, i->ext_paddings); + update_ext_coords(&(i->coords), &(i->ext_coords), &(i->ext_paddings)); #endif refresh_children_position(i, x_diff, y_diff); } @@ -2154,3 +2143,19 @@ static void delete_children(lv_obj_t * obj) lv_mem_free(obj); /*Free the object itself*/ } + +#if USE_LV_EXTENDED_CLICK_AREA +/** + * Update coordinates of extended clickable area from object's coordinates and ext_paddings + * @param coords coordinates of an object + * @param ext_coords extended coordinates, which will be updated + * @param paddings paddings of extended clickable area + */ +static void update_ext_coords(lv_area_t *coords, lv_area_t *ext_coords, lv_area_t *paddings) +{ + ext_coords->x1 = paddings->x1 > coords->x1 ? 0 : coords->x1 - paddings->x1; + ext_coords->x2 = coords->x2 + paddings->x2; + ext_coords->y1 = paddings->y1 > coords->y1 ? 0 : coords->y1 - paddings->y1; + ext_coords->y2 = coords->y2 + paddings->y2; +} +#endif diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 417b98817..2f96c919a 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -348,7 +348,7 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); * @param w extended width to both sides * @param h extended height to both sides */ -void lv_obj_set_ext_paddinds(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); +void lv_obj_set_ext_paddings(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); #endif /** From bc8cd2068ecf22f1ae4ae6c17c4683c19aed2217 Mon Sep 17 00:00:00 2001 From: melnse Date: Thu, 4 Apr 2019 14:14:40 +0300 Subject: [PATCH 3/6] Realized alternative version of extended clickable area: "USE_LV_EXTENDED_CLICKABLE_AREA_TINY". It doesn't store extended coordinates, but calculates them on the fly. Also ext_paddings changed from lv_area to two uint8_t in both versions. --- src/lv_core/lv_indev.c | 2 ++ src/lv_core/lv_obj.c | 61 ++++++++++++++++++++++++++---------------- src/lv_core/lv_obj.h | 25 ++++++++++++----- src/lv_misc/lv_area.c | 22 +++++++++++++++ src/lv_misc/lv_area.h | 12 +++++++++ 5 files changed, 92 insertions(+), 30 deletions(-) diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index c45fab75c..627d35dec 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -978,6 +978,8 @@ static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj) /*Check its children too*/ #if USE_LV_EXTENDED_CLICK_AREA if(lv_area_is_point_on(&obj->ext_coords, &proc->act_point)) { +#elif USE_LV_EXTENDED_CLICK_AREA_TINY + if(lv_area_ext_is_point_on(&obj->ext_coords, &proc->act_point, obj->ext_padding_hor, obj->ext_padding_ver)) { #else if(lv_area_is_point_on(&obj->coords, &proc->act_point)) { #endif diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index bbd769700..012094bc3 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -45,7 +45,7 @@ static void delete_children(lv_obj_t * obj); static bool lv_obj_design(lv_obj_t * obj, const lv_area_t * mask_p, lv_design_mode_t mode); static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param); #if USE_LV_EXTENDED_CLICK_AREA -static void update_ext_coords(lv_area_t *coords, lv_area_t *ext_coords, lv_area_t *paddings); +static void update_ext_coords(lv_area_t *coords, lv_area_t *ext_coords, uint8_t hor_pad, uint8_t ver_pad); #endif /********************** @@ -152,11 +152,12 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) #if USE_LV_EXTENDED_CLICK_AREA lv_area_copy(&(new_obj->ext_coords), &(new_obj->coords)); - new_obj->ext_paddings.x1 = 0; - new_obj->ext_paddings.x2 = 0; - new_obj->ext_paddings.y1 = 0; - new_obj->ext_paddings.y2 = 0; #endif +#if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY + new_obj->hor_pad = 0; + new_obj->ver_pad = 0; +#endif + /*Init realign*/ #if LV_OBJ_REALIGN new_obj->realign.align = LV_ALIGN_CENTER; @@ -230,10 +231,10 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) #if USE_LV_EXTENDED_CLICK_AREA lv_area_copy(&(new_obj->ext_coords), &(new_obj->coords)); - new_obj->ext_paddings.x1 = 0; - new_obj->ext_paddings.x2 = 0; - new_obj->ext_paddings.y1 = 0; - new_obj->ext_paddings.y2 = 0; +#endif +#if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY + new_obj->hor_pad = 0; + new_obj->ver_pad = 0; #endif /*Init realign*/ #if LV_OBJ_REALIGN @@ -292,7 +293,10 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) #if USE_LV_EXTENDED_CLICK_AREA lv_area_copy(&new_obj->ext_coords, ©->ext_coords); - lv_area_copy(&new_obj->ext_paddings, ©->ext_paddings); +#endif +#if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY + new_obj->hor_pad = copy->hor_pad; + new_obj->ver_pad = copy->ver_pad; #endif /*Set free data*/ @@ -582,7 +586,7 @@ void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) obj->coords.y2 += diff.y; #if USE_LV_EXTENDED_CLICK_AREA - update_ext_coords(&(obj->coords), &(obj->ext_coords), &(obj->ext_paddings)); + update_ext_coords(&(obj->coords), &(obj->ext_coords), obj->hor_pad, obj->ver_pad); #endif refresh_children_position(obj, diff.x, diff.y); @@ -647,7 +651,7 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) obj->coords.y2 = obj->coords.y1 + h - 1; #if USE_LV_EXTENDED_CLICK_AREA - update_ext_coords(&(obj->coords), &(obj->ext_coords), &(obj->ext_paddings)); + update_ext_coords(&(obj->coords), &(obj->ext_coords), obj->hor_pad, obj->ver_pad); #endif /*Send a signal to the object with its new coordinates*/ @@ -1619,17 +1623,28 @@ lv_coord_t lv_obj_get_height_fit(lv_obj_t * obj) return lv_obj_get_width(obj) - style->body.padding.top - style->body.padding.bottom; } -#if USE_LV_EXTENDED_CLICK_AREA +#if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY /** - * Copy the extended clickable area size of an object to an area + * Get the horizontal padding of extended clickable area * @param obj pointer to an object - * @param cords_p pointer to an area to store the size + * @return the horizontal padding */ -void lv_obj_get_ext_paddings(const lv_obj_t * obj, lv_area_t * cords_p) +uint8_t lv_obj_get_ext_hor_padding(const lv_obj_t * obj) { - lv_area_copy(cords_p, &obj->ext_paddings); + return obj->ext_padding_hor; } +/** + * Get the vertical padding of extended clickable area + * @param obj pointer to an object + * @return the vertical padding + */ +uint8_t lv_obj_get_ext_ver_padding(const lv_obj_t * obj) +{ + return obj->ext_padding_ver; +} +#endif + /** * Get the extended size attribute of an object * @param obj pointer to an object @@ -2031,7 +2046,7 @@ static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coor i->coords.y2 += y_diff; #if USE_LV_EXTENDED_CLICK_AREA - update_ext_coords(&(i->coords), &(i->ext_coords), &(i->ext_paddings)); + update_ext_coords(&(i->coords), &(i->ext_coords), i->hor_pad, i->ver_pad); #endif refresh_children_position(i, x_diff, y_diff); } @@ -2151,11 +2166,11 @@ static void delete_children(lv_obj_t * obj) * @param ext_coords extended coordinates, which will be updated * @param paddings paddings of extended clickable area */ -static void update_ext_coords(lv_area_t *coords, lv_area_t *ext_coords, lv_area_t *paddings) +static void update_ext_coords(lv_area_t *coords, lv_area_t *ext_coords, uint8_t hor_pad, uint8_t ver_pad) { - ext_coords->x1 = paddings->x1 > coords->x1 ? 0 : coords->x1 - paddings->x1; - ext_coords->x2 = coords->x2 + paddings->x2; - ext_coords->y1 = paddings->y1 > coords->y1 ? 0 : coords->y1 - paddings->y1; - ext_coords->y2 = coords->y2 + paddings->y2; + ext_coords->x1 = hor_pad > coords->x1 ? 0 : coords->x1 - hor_pad; + ext_coords->x2 = coords->x2 + hor_pad; + ext_coords->y1 = ver_pad > coords->y1 ? 0 : coords->y1 - ver_pad; + ext_coords->y2 = coords->y2 + ver_pad; } #endif diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 2f96c919a..958a58db2 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -178,7 +178,10 @@ typedef struct _lv_obj_t lv_area_t coords; /*Coordinates of the object (x1, y1, x2, y2)*/ #if USE_LV_EXTENDED_CLICK_AREA lv_area_t ext_coords; - lv_area_t ext_paddings; +#endif +#if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY + uint8_t ext_padding_hor; + uint8_t ext_padding_ver; #endif lv_event_cb_t event_cb; @@ -341,14 +344,14 @@ void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y); */ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); -#if USE_LV_EXTENDED_CLICK_AREA +#if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY /** * Set the size of an extended clickable area * @param obj pointer to an object * @param w extended width to both sides * @param h extended height to both sides */ -void lv_obj_set_ext_paddings(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); +void lv_obj_set_ext_paddings(lv_obj_t * obj, uint8_t w, uint8_t h); #endif /** @@ -687,13 +690,21 @@ lv_coord_t lv_obj_get_width_fit(lv_obj_t * obj); */ lv_coord_t lv_obj_get_height_fit(lv_obj_t * obj); -#if USE_LV_EXTENDED_CLICK_AREA +#if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY /** - * Copy the extended clickable area size of an object to an area + * Get the horizontal padding of extended clickable area * @param obj pointer to an object - * @param cords_p pointer to an area to store the size + * @return the horizontal padding */ -void lv_obj_get_ext_paddings(const lv_obj_t * obj, lv_area_t * cords_p); +uint8_t lv_obj_get_ext_hor_padding(const lv_obj_t * obj); + +/** + * Get the vertical padding of extended clickable area + * @param obj pointer to an object + * @return the vertical padding + */ +uint8_t lv_obj_get_ext_ver_padding(const lv_obj_t * obj); + #endif /** diff --git a/src/lv_misc/lv_area.c b/src/lv_misc/lv_area.c index f340690a4..60051669c 100644 --- a/src/lv_misc/lv_area.c +++ b/src/lv_misc/lv_area.c @@ -156,6 +156,28 @@ bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p) return is_on; } +#if USE_LV_EXTENDED_CLICK_AREA_TINY +/** + * Check if a point is on an area + * @param a_p pointer to an area + * @param p_p pointer to a point + * @param ext_hor extended horizontal padding + * @param ext_ver extended horizontal padding + * @return false:the point is out of the area + */ +bool lv_area_ext_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, unit8_t ext_hor, unit8_t ext_ver) +{ + bool is_on = false; + + if(( (p_p->x + ext_hor) >= a_p->x1 && p_p->x <= (a_p->x2 + ext_hor) ) && + ( (p_p->y + ext_ver) >= a_p->y1 && p_p->y <= (a_p->y2 + ext_ver)) ) { + is_on = true; + } + + return is_on; +} +#endif + /** * Check if two area has common parts * @param a1_p pointer to an area. diff --git a/src/lv_misc/lv_area.h b/src/lv_misc/lv_area.h index fc8b7dec8..47674bad1 100644 --- a/src/lv_misc/lv_area.h +++ b/src/lv_misc/lv_area.h @@ -141,6 +141,18 @@ void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * */ bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p); +#if USE_LV_EXTENDED_CLICK_AREA_TINY +/** + * Check if a point is on an area + * @param a_p pointer to an area + * @param p_p pointer to a point + * @param ext_hor extended horizontal padding + * @param ext_ver extended horizontal padding + * @return false:the point is out of the area + */ +bool lv_area_ext_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, unit8_t ext_hor, unit8_t ext_ver); +#endif + /** * Check if two area has common parts * @param a1_p pointer to an area. From 3f2b6bb685344051563924d13264f131fb7a4e46 Mon Sep 17 00:00:00 2001 From: melnse Date: Thu, 4 Apr 2019 14:34:29 +0300 Subject: [PATCH 4/6] Added defines of extended clickable area to conf template and to conf checker. --- lv_conf_template.h | 4 ++++ src/lv_conf_checker.h | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lv_conf_template.h b/lv_conf_template.h index 3227bb42c..0273f4a7b 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -342,6 +342,10 @@ typedef void * lv_obj_user_data_t; /*Declare the type of the user data /*Switch (dependencies: lv_slider)*/ #define LV_USE_SW 1 +/* Extended clickable area */ +#define USE_LV_EXTENDED_CLICK_AREA 0 /* Enables obj extension to realize extended clickable area with additional extended coords (1: enabled) */ +#define USE_LV_EXTENDED_CLICK_AREA_TINY 0 /* Enables obj extension to realize extended clickable area with calculation of the fly (1: enabled) */ + /************************* * Non-user section *************************/ diff --git a/src/lv_conf_checker.h b/src/lv_conf_checker.h index 13b9cc252..6ffe0edef 100644 --- a/src/lv_conf_checker.h +++ b/src/lv_conf_checker.h @@ -584,6 +584,15 @@ #define LV_USE_SW 1 #endif +/*Extended clickable area */ +#ifndef USE_LV_EXTENDED_CLICK_AREA +#define USE_LV_EXTENDED_CLICK_AREA 0 +#endif + +#ifndef USE_LV_EXTENDED_CLICK_AREA_TINY +#define USE_LV_EXTENDED_CLICK_AREA_TINY 0 +#endif + /************************* * Non-user section *************************/ From 9af730c6cb1816a103506d085804b9b955179f8f Mon Sep 17 00:00:00 2001 From: GreyMS Date: Wed, 10 Apr 2019 15:32:36 +0300 Subject: [PATCH 5/6] Fixed usage of _lv_indev_proc_t --- src/lv_core/lv_indev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index 7d2b907f6..30a94f521 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -992,11 +992,11 @@ static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj) /*If the point is on this object*/ /*Check its children too*/ #if USE_LV_EXTENDED_CLICK_AREA - if(lv_area_is_point_on(&obj->ext_coords, &proc->act_point)) { + if(lv_area_is_point_on(&obj->ext_coords, &proc->types.pointer.act_point)) { #elif USE_LV_EXTENDED_CLICK_AREA_TINY - if(lv_area_ext_is_point_on(&obj->ext_coords, &proc->act_point, obj->ext_padding_hor, obj->ext_padding_ver)) { + if(lv_area_ext_is_point_on(&obj->ext_coords, &proc->types.pointer.act_point, obj->ext_padding_hor, obj->ext_padding_ver)) { #else - if(lv_area_is_point_on(&obj->coords, &proc->act_point)) { + if(lv_area_is_point_on(&obj->coords, &proc->types.pointer.act_point)) { #endif lv_obj_t * i; From de12c95a80622c35ceaa764ace62ca2fce79d19b Mon Sep 17 00:00:00 2001 From: GreyMS Date: Wed, 10 Apr 2019 19:01:47 +0300 Subject: [PATCH 6/6] Fixed typos and include added. --- src/lv_core/lv_indev.c | 2 +- src/lv_core/lv_obj.c | 26 +++++++++++++------------- src/lv_misc/lv_area.c | 4 +++- src/lv_misc/lv_area.h | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index 30a94f521..a52322110 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -994,7 +994,7 @@ static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj) #if USE_LV_EXTENDED_CLICK_AREA if(lv_area_is_point_on(&obj->ext_coords, &proc->types.pointer.act_point)) { #elif USE_LV_EXTENDED_CLICK_AREA_TINY - if(lv_area_ext_is_point_on(&obj->ext_coords, &proc->types.pointer.act_point, obj->ext_padding_hor, obj->ext_padding_ver)) { + if(lv_area_ext_is_point_on(&obj->coords, &proc->types.pointer.act_point, obj->ext_padding_hor, obj->ext_padding_ver)) { #else if(lv_area_is_point_on(&obj->coords, &proc->types.pointer.act_point)) { #endif diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 9bc4e715e..38ce15d21 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -152,8 +152,8 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) lv_area_copy(&(new_obj->ext_coords), &(new_obj->coords)); #endif #if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY - new_obj->hor_pad = 0; - new_obj->ver_pad = 0; + new_obj->ext_padding_hor = 0; + new_obj->ext_padding_ver = 0; #endif /*Init realign*/ @@ -228,8 +228,8 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) lv_area_copy(&(new_obj->ext_coords), &(new_obj->coords)); #endif #if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY - new_obj->hor_pad = 0; - new_obj->ver_pad = 0; + new_obj->ext_padding_hor = 0; + new_obj->ext_padding_ver = 0; #endif /*Init realign*/ #if LV_OBJ_REALIGN @@ -291,8 +291,8 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) lv_area_copy(&new_obj->ext_coords, ©->ext_coords); #endif #if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY - new_obj->hor_pad = copy->hor_pad; - new_obj->ver_pad = copy->ver_pad; + new_obj->ext_padding_hor = copy->ext_padding_hor; + new_obj->ext_padding_ver = copy->ext_padding_ver; #endif /*Set free data*/ @@ -670,21 +670,21 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) #endif } -#if USE_LV_EXTENDED_CLICK_AREA +#if USE_LV_EXTENDED_CLICK_AREA || USE_LV_EXTENDED_CLICK_AREA_TINY /** * Set the size of an extended clickable area * @param obj pointer to an object * @param w extended width to both sides * @param h extended height to both sides */ -void lv_obj_set_ext_paddings(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) +void lv_obj_set_ext_paddings(lv_obj_t * obj, uint8_t w, uint8_t h) { - obj->ext_paddings.x1 = w; - obj->ext_paddings.x2 = w; - obj->ext_paddings.y1 = h; - obj->ext_paddings.y2 = h; - + obj->ext_padding_hor = w; + obj->ext_padding_ver = h; + +#if USE_LV_EXTENDED_CLICK_AREA update_ext_coords(&(obj->coords), &(obj->ext_coords), &(obj->ext_paddings)); +#endif } #endif diff --git a/src/lv_misc/lv_area.c b/src/lv_misc/lv_area.c index 735cc37f7..48047eecc 100644 --- a/src/lv_misc/lv_area.c +++ b/src/lv_misc/lv_area.c @@ -6,6 +6,7 @@ /********************* * INCLUDES *********************/ +#include "lv_conf.h" #include "lv_area.h" #include "lv_math.h" @@ -162,7 +163,7 @@ bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p) * @param ext_ver extended horizontal padding * @return false:the point is out of the area */ -bool lv_area_ext_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, unit8_t ext_hor, unit8_t ext_ver) +bool lv_area_ext_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, uint8_t ext_hor, uint8_t ext_ver) { bool is_on = false; @@ -173,6 +174,7 @@ bool lv_area_ext_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, unit return is_on; } + #endif /** diff --git a/src/lv_misc/lv_area.h b/src/lv_misc/lv_area.h index b21398435..7082cbc2d 100644 --- a/src/lv_misc/lv_area.h +++ b/src/lv_misc/lv_area.h @@ -149,7 +149,7 @@ bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p); * @param ext_ver extended horizontal padding * @return false:the point is out of the area */ -bool lv_area_ext_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, unit8_t ext_hor, unit8_t ext_ver); +bool lv_area_ext_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, uint8_t ext_hor, uint8_t ext_ver); #endif /**