From ca01b558f70d2fa106f976c1d4564e26a57b1fb5 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Sat, 1 Jun 2019 21:37:04 -0400 Subject: [PATCH 1/3] Add lv_obj_adjust_coords() API for finding the object's "client area" --- src/lv_core/lv_obj.c | 19 +++++++++++++++++++ src/lv_core/lv_obj.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index c499786d8..3906bafa7 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -1592,6 +1592,25 @@ void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p) lv_area_copy(cords_p, &obj->coords); } +/** + * Adjust the coordinates retrieved from lv_obj_get_coords() according + * to the object's style. + */ +void lv_obj_adjust_coords(const lv_obj_t *obj, lv_area_t * cords_p) +{ + const lv_style_t *style = lv_obj_get_style(obj); + if(style->body.border.part & LV_BORDER_LEFT) + cords_p->x1 += style->body.border.width; + + if(style->body.border.part & LV_BORDER_RIGHT) + cords_p->x2 -= style->body.border.width; + if(style->body.border.part & LV_BORDER_TOP) + cords_p->y1 += style->body.border.width; + if(style->body.border.part & LV_BORDER_BOTTOM) + cords_p->y2 -= style->body.border.width; +} + + /** * Get the x coordinate of object * @param obj pointer to an object diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 56b395e8f..03ffa1978 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -666,6 +666,12 @@ uint16_t lv_obj_count_children_recursive(const lv_obj_t * obj); */ void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p); +/** + * Adjust the coordinates retrieved from lv_obj_get_coords() according + * to the object's style. + */ +void lv_obj_adjust_coords(const lv_obj_t *obj, lv_area_t * cords_p); + /** * Get the x coordinate of object * @param obj pointer to an object From 4075a7adfc71f9c2b52e2fbbf7c83f5442eeefc7 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Sat, 1 Jun 2019 21:37:25 -0400 Subject: [PATCH 2/3] Roller: do not draw rectangle highlight on borders --- src/lv_objx/lv_roller.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lv_objx/lv_roller.c b/src/lv_objx/lv_roller.c index 67c386cc3..a48e81092 100644 --- a/src/lv_objx/lv_roller.c +++ b/src/lv_objx/lv_roller.c @@ -328,8 +328,12 @@ static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_desig if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1--; /*Compensate the two rounding error*/ rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1; - rect_area.x1 = roller->coords.x1; - rect_area.x2 = roller->coords.x2; + lv_area_t roller_coords; + lv_obj_get_coords(roller, &roller_coords); + lv_obj_adjust_coords(roller, &roller_coords); + + rect_area.x1 = roller_coords.x1; + rect_area.x2 = roller_coords.x2; lv_draw_rect(&rect_area, mask, ext->ddlist.sel_style, opa_scale); } From 8254ee66619032db57d57f25f8de9ced933b64fa Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 7 Jun 2019 14:52:14 +0200 Subject: [PATCH 3/3] rename lv_obj_adjust_coords to lv_obj_get_inner_coords --- src/lv_core/lv_obj.c | 17 ++++++++++------- src/lv_core/lv_obj.h | 7 ++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 3906bafa7..bf7b63315 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -1593,21 +1593,24 @@ void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p) } /** - * Adjust the coordinates retrieved from lv_obj_get_coords() according - * to the object's style. + * Reduce area retried by `lv_obj_get_coords()` the get graphically usable area of an object. + * (Without the size of the border or other extra graphical elements) + * @param coords_p store the result area here */ -void lv_obj_adjust_coords(const lv_obj_t *obj, lv_area_t * cords_p) +void lv_obj_get_inner_coords(const lv_obj_t *obj, lv_area_t * coords_p) { const lv_style_t *style = lv_obj_get_style(obj); if(style->body.border.part & LV_BORDER_LEFT) - cords_p->x1 += style->body.border.width; + coords_p->x1 += style->body.border.width; if(style->body.border.part & LV_BORDER_RIGHT) - cords_p->x2 -= style->body.border.width; + coords_p->x2 -= style->body.border.width; + if(style->body.border.part & LV_BORDER_TOP) - cords_p->y1 += style->body.border.width; + coords_p->y1 += style->body.border.width; + if(style->body.border.part & LV_BORDER_BOTTOM) - cords_p->y2 -= style->body.border.width; + coords_p->y2 -= style->body.border.width; } diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 03ffa1978..e993aacb0 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -667,10 +667,11 @@ uint16_t lv_obj_count_children_recursive(const lv_obj_t * obj); void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p); /** - * Adjust the coordinates retrieved from lv_obj_get_coords() according - * to the object's style. + * Reduce area retried by `lv_obj_get_coords()` the get graphically usable area of an object. + * (Without the size of the border or other extra graphical elements) + * @param coords_p store the result area here */ -void lv_obj_adjust_coords(const lv_obj_t *obj, lv_area_t * cords_p); +void lv_obj_get_inner_coords(const lv_obj_t *obj, lv_area_t * coords_p); /** * Get the x coordinate of object