diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 73441bd26..8f6d23fb6 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -1598,6 +1598,28 @@ void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p) lv_area_copy(cords_p, &obj->coords); } +/** + * 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_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) + coords_p->x1 += style->body.border.width; + + if(style->body.border.part & LV_BORDER_RIGHT) + coords_p->x2 -= style->body.border.width; + + if(style->body.border.part & LV_BORDER_TOP) + coords_p->y1 += style->body.border.width; + + if(style->body.border.part & LV_BORDER_BOTTOM) + coords_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 add883d4b..1269976aa 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -663,6 +663,13 @@ 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); +/** + * 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_get_inner_coords(const lv_obj_t *obj, lv_area_t * coords_p); + /** * Get the x coordinate of object * @param obj pointer to an object diff --git a/src/lv_objx/lv_roller.c b/src/lv_objx/lv_roller.c index e8d80ef8c..a649cbcd4 100644 --- a/src/lv_objx/lv_roller.c +++ b/src/lv_objx/lv_roller.c @@ -324,8 +324,12 @@ static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_desig rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->text.line_space / 2; 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); }