1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

add offset function

This commit is contained in:
Ali Rostami 2019-03-04 12:41:28 +03:30 committed by GitHub
parent 69b07acc4e
commit e298f493ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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->w = lv_obj_get_width(new_img);
ext->h = lv_obj_get_height(new_img); ext->h = lv_obj_get_height(new_img);
ext->auto_size = 1; ext->auto_size = 1;
ext->offset.x = 0;
ext->offset.y = 0;
#if USE_LV_MULTI_LANG #if USE_LV_MULTI_LANG
ext->lang_txt_id = LV_LANG_TXT_ID_NONE; ext->lang_txt_id = LV_LANG_TXT_ID_NONE;
#endif #endif
@ -235,6 +237,19 @@ void lv_img_set_auto_size(lv_obj_t * img, bool en)
ext->auto_size = (en == false ? 0 : 1); 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 * 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); lv_obj_get_coords(img, &coords);
if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_VARIABLE) { 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_LOG_TRACE("lv_img_design: start to draw image");
lv_area_t cords_tmp; lv_area_t cords_tmp;
cords_tmp.y1 = coords.y1; cords_tmp.y1 = coords.y1;