From 06f553b3aa5a0e0004eacff637ee5d8e26bf3edd Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 21 Nov 2019 05:44:43 +0100 Subject: [PATCH] lv_img_set_offset_x/y: draw the partial image at the beginning with offset > 0 --- src/lv_objx/lv_img.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/lv_objx/lv_img.c b/src/lv_objx/lv_img.c index 06b81fad0..44cef517a 100644 --- a/src/lv_objx/lv_img.c +++ b/src/lv_objx/lv_img.c @@ -236,10 +236,10 @@ void lv_img_set_offset_x(lv_obj_t * img, lv_coord_t x) lv_img_ext_t * ext = lv_obj_get_ext_attr(img); - if(x < ext->w - 1) { - ext->offset.x = x; - lv_obj_invalidate(img); - } + x = x % ext->w; + + ext->offset.x = x; + lv_obj_invalidate(img); } /** @@ -254,10 +254,10 @@ void lv_img_set_offset_y(lv_obj_t * img, lv_coord_t y) lv_img_ext_t * ext = lv_obj_get_ext_attr(img); - if(y < ext->h - 1) { - ext->offset.y = y; - lv_obj_invalidate(img); - } + y = y % ext->h; + + ext->offset.y = y; + lv_obj_invalidate(img); } /** @@ -471,8 +471,11 @@ static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area lv_obj_get_coords(img, &coords); if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_VARIABLE) { - coords.x1 -= ext->offset.x; - coords.y1 -= ext->offset.y; + coords.x1 += ext->offset.x; + coords.y1 += ext->offset.y; + + if(coords.x1 > img->coords.x1) coords.x1 -= ext->w; + if(coords.y1 > img->coords.y1) coords.y1 -= ext->h; LV_LOG_TRACE("lv_img_design: start to draw image"); lv_area_t cords_tmp;