diff --git a/src/core/lv_obj_pos.c b/src/core/lv_obj_pos.c index 99ca8b5efa..11dcac65f3 100644 --- a/src/core/lv_obj_pos.c +++ b/src/core/lv_obj_pos.c @@ -96,45 +96,59 @@ void lv_obj_refr_size(lv_obj_t * obj) if(parent == NULL) return; lv_coord_t w; - lv_coord_t h; - if(obj->w_layout) w = lv_obj_get_width(obj); - else w = lv_obj_get_style_width(obj, LV_PART_MAIN); - if(obj->h_layout) h = lv_obj_get_height(obj); - else h = lv_obj_get_style_height(obj, LV_PART_MAIN); - - /*Calculate the required auto sizes*/ - bool w_content = w == LV_SIZE_CONTENT ? true : false; - bool h_content = h == LV_SIZE_CONTENT ? true : false; - - /*Be sure the object is not scrolled when it has auto size*/ lv_coord_t sl_ori = lv_obj_get_scroll_left(obj); - if(w_content) lv_obj_scroll_to_x(obj, 0, LV_ANIM_OFF); + bool w_content = false; + if(obj->w_layout) { + w = lv_obj_get_width(obj); + } else { + w = lv_obj_get_style_width(obj, LV_PART_MAIN); + w_content = w == LV_SIZE_CONTENT ? true : false; + + /*Be sure the object is not scrolled when it has auto size*/ + if(w_content) { + lv_obj_scroll_to_x(obj, 0, LV_ANIM_OFF); + calc_auto_size(obj, &w, NULL); + } + + /*Calculate the sizes in percentage*/ + bool pct_w = LV_COORD_IS_PCT(w) ? true : false; + + lv_coord_t parent_w = lv_obj_get_width_fit(parent); + if(pct_w) w = (LV_COORD_GET_PCT(w) * parent_w) / 100; + + w += lv_obj_get_style_transform_width(obj, LV_PART_MAIN); + + lv_coord_t minw = lv_obj_get_style_min_width(obj, LV_PART_MAIN); + lv_coord_t maxw = lv_obj_get_style_max_width(obj, LV_PART_MAIN); + w = lv_clamp_width(w, minw, maxw, parent_w); + } + + lv_coord_t h; lv_coord_t st_ori = lv_obj_get_scroll_top(obj); - if(h_content) lv_obj_scroll_to_y(obj, 0, LV_ANIM_OFF); + bool h_content = false; + if(obj->h_layout) { + h = lv_obj_get_height(obj); + } else { + h = lv_obj_get_style_height(obj, LV_PART_MAIN); + h_content = h == LV_SIZE_CONTENT ? true : false; - if(w_content && h_content) calc_auto_size(obj, &w, &h); - else if(w_content) calc_auto_size(obj, &w, NULL); - else if(h_content) calc_auto_size(obj, NULL, &h); + /*Be sure the object is not scrolled when it has auto size*/ + if(h_content) { + lv_obj_scroll_to_y(obj, 0, LV_ANIM_OFF); + calc_auto_size(obj, NULL, &h); + } - /*Calculate the required auto sizes*/ - bool pct_w = LV_COORD_IS_PCT(w) ? true : false; - bool pct_h = LV_COORD_IS_PCT(h) ? true : false; + /*Calculate the sizes in percentage*/ + bool pct_h = LV_COORD_IS_PCT(h) ? true : false; + lv_coord_t parent_h = lv_obj_get_height_fit(parent); + if(pct_h) h = (LV_COORD_GET_PCT(h) * parent_h) / 100; - lv_coord_t parent_w = lv_obj_get_width_fit(parent); - lv_coord_t parent_h = lv_obj_get_height_fit(parent); - if(pct_w) w = (LV_COORD_GET_PCT(w) * parent_w) / 100; - if(pct_h) h = (LV_COORD_GET_PCT(h) * parent_h) / 100; + h += lv_obj_get_style_transform_height(obj, LV_PART_MAIN); - w += lv_obj_get_style_transform_width(obj, LV_PART_MAIN); - h += lv_obj_get_style_transform_height(obj, LV_PART_MAIN); - - lv_coord_t minw = lv_obj_get_style_min_width(obj, LV_PART_MAIN); - lv_coord_t maxw = lv_obj_get_style_max_width(obj, LV_PART_MAIN); - w = lv_clamp_width(w, minw, maxw, parent_w); - - lv_coord_t minh = lv_obj_get_style_min_height(obj, LV_PART_MAIN); - lv_coord_t maxh = lv_obj_get_style_max_height(obj, LV_PART_MAIN); - h = lv_clamp_width(h, minh, maxh, parent_h); + lv_coord_t minh = lv_obj_get_style_min_height(obj, LV_PART_MAIN); + lv_coord_t maxh = lv_obj_get_style_max_height(obj, LV_PART_MAIN); + h = lv_clamp_width(h, minh, maxh, parent_h); + } /*calc_auto_size set the scroll x/y to 0 so revert the original value*/ if(w_content || h_content) {