From 92e85d1b9eb5283779857f873c009f74ba70dbf0 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 6 Apr 2021 15:47:05 +0200 Subject: [PATCH] fix(scroll) fix scroll minor scrolling issues --- src/core/lv_obj_pos.c | 16 ++++++++++++++-- src/core/lv_obj_scroll.c | 6 +++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/core/lv_obj_pos.c b/src/core/lv_obj_pos.c index 7572427bd..8c2464481 100644 --- a/src/core/lv_obj_pos.c +++ b/src/core/lv_obj_pos.c @@ -107,7 +107,9 @@ void lv_obj_refr_size(lv_obj_t * obj) 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); + lv_coord_t st_ori = lv_obj_get_scroll_top(obj); if(h_content) lv_obj_scroll_to_y(obj, 0, LV_ANIM_OFF); if(w_content && h_content) calc_auto_size(obj, &w, &h); @@ -131,6 +133,11 @@ void lv_obj_refr_size(lv_obj_t * obj) lv_coord_t maxh = lv_obj_get_style_max_height(obj, LV_PART_MAIN); h = LV_CLAMP(minh, h, maxh); + /*calc_auto_size set the scroll x/y to 0 so revert the original value*/ + if(w_content || h_content) { + lv_obj_scroll_to(obj, sl_ori, st_ori, LV_ANIM_OFF); + } + /*Do nothing if the size is not changed*/ /*It is very important else recursive resizing can occur without size change*/ if(lv_obj_get_width(obj) == w && lv_obj_get_height(obj) == h) return; @@ -647,8 +654,13 @@ void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) lv_coord_t pad_left = lv_obj_get_style_pad_left(parent, LV_PART_MAIN); lv_coord_t pad_top = lv_obj_get_style_pad_top(parent, LV_PART_MAIN); - x += pad_left + parent->coords.x1 - lv_obj_get_scroll_x(parent); - y += pad_top + parent->coords.y1 - lv_obj_get_scroll_y(parent); + if(lv_obj_has_flag(obj, LV_OBJ_FLAG_FLOATING)) { + x += pad_left + parent->coords.x1; + y += pad_top + parent->coords.y1; + } else { + x += pad_left + parent->coords.x1 - lv_obj_get_scroll_x(parent); + y += pad_top + parent->coords.y1 - lv_obj_get_scroll_y(parent); + } } /*Calculate and set the movement*/ diff --git a/src/core/lv_obj_scroll.c b/src/core/lv_obj_scroll.c index db65db6af..295c1ac22 100644 --- a/src/core/lv_obj_scroll.c +++ b/src/core/lv_obj_scroll.c @@ -16,9 +16,9 @@ * DEFINES *********************/ #define MY_CLASS &lv_obj_class -#define SCROLL_ANIM_TIME_MIN 200 /*ms*/ -#define SCROLL_ANIM_TIME_MAX 400 /*ms*/ -#define SCROLLBAR_MIN_SIZE (LV_DPX(10)) +#define SCROLL_ANIM_TIME_MIN 200 /*ms*/ +#define SCROLL_ANIM_TIME_MAX 400 /*ms*/ +#define SCROLLBAR_MIN_SIZE (LV_DPX(10)) /********************** * TYPEDEFS