diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index c9fb42875..907f09e5d 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -78,6 +78,8 @@ lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy) ext->w = lv_obj_get_width(new_img); ext->h = lv_obj_get_height(new_img); ext->auto_size = 1; + ext->offset.x = 0; + ext->offset.y = 0; #if USE_LV_MULTI_LANG ext->lang_txt_id = LV_LANG_TXT_ID_NONE; #endif @@ -235,6 +237,19 @@ void lv_img_set_auto_size(lv_obj_t * img, bool en) ext->auto_size = (en == false ? 0 : 1); } +/** + * Set an offset for the source of an image. + * so the image will be displayed from this new origin. + * @param img pointer to an image + * @param en true: auto size enable, false: auto size disable + */ +void lv_img_set_offset(lv_obj_t *img, lv_point_t offset) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + if((ext->offset.x < ext->w - 1) && (ext->offset.y < ext->h - 1)) + ext->offset = offset; +} /*===================== * Getter functions @@ -325,6 +340,9 @@ static bool lv_img_design(lv_obj_t * img, const lv_area_t * mask, lv_design_mode 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; + LV_LOG_TRACE("lv_img_design: start to draw image"); lv_area_t cords_tmp; cords_tmp.y1 = coords.y1;