mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
fix(scroll) fix normalizing scroll position when size is recalculated
This commit is contained in:
parent
f78269c360
commit
95ae499a8f
@ -85,15 +85,15 @@ void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y)
|
||||
lv_obj_refr_pos(obj);
|
||||
}
|
||||
|
||||
void lv_obj_refr_size(lv_obj_t * obj)
|
||||
bool lv_obj_refr_size(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
/*If the width or height is set by a layout do not modify them*/
|
||||
if(obj->w_layout && obj->h_layout) return;
|
||||
if(obj->w_layout && obj->h_layout) return false;
|
||||
|
||||
lv_obj_t * parent = lv_obj_get_parent(obj);
|
||||
if(parent == NULL) return;
|
||||
if(parent == NULL) return false;
|
||||
|
||||
lv_coord_t w;
|
||||
lv_coord_t sl_ori = lv_obj_get_scroll_left(obj);
|
||||
@ -153,7 +153,7 @@ void lv_obj_refr_size(lv_obj_t * obj)
|
||||
|
||||
/*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;
|
||||
if(lv_obj_get_width(obj) == w && lv_obj_get_height(obj) == h) return false;
|
||||
|
||||
/*Invalidate the original area*/
|
||||
lv_obj_invalidate(obj);
|
||||
@ -190,10 +190,46 @@ void lv_obj_refr_size(lv_obj_t * obj)
|
||||
/*Invalidate the new area*/
|
||||
lv_obj_invalidate(obj);
|
||||
|
||||
|
||||
/*Be sure the bottom side is not remains scrolled in*/
|
||||
/*With snapping the content can't be scrolled in*/
|
||||
if(lv_obj_get_scroll_snap_y(obj) == LV_SCROLL_SNAP_NONE) {
|
||||
lv_coord_t st = lv_obj_get_scroll_top(obj);
|
||||
lv_coord_t sb = lv_obj_get_scroll_bottom(obj);
|
||||
if(sb < 0 && st > 0) {
|
||||
sb = LV_MIN(st, -sb);
|
||||
lv_obj_scroll_by(obj, 0, sb, LV_ANIM_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
if(lv_obj_get_scroll_snap_x(obj) == LV_SCROLL_SNAP_NONE) {
|
||||
lv_coord_t sl = lv_obj_get_scroll_left(obj);
|
||||
lv_coord_t sr = lv_obj_get_scroll_right(obj);
|
||||
if(lv_obj_get_base_dir(obj) != LV_BIDI_DIR_RTL) {
|
||||
/*Be sure the left side is not remains scrolled in*/
|
||||
if(sr < 0 && sl > 0) {
|
||||
sr = LV_MIN(sl, -sr);
|
||||
lv_obj_scroll_by(obj, sr, 0, LV_ANIM_OFF);
|
||||
}
|
||||
} else {
|
||||
/*Be sure the right side is not remains scrolled in*/
|
||||
if(sl < 0 && sr > 0) {
|
||||
sr = LV_MIN(sr, -sl);
|
||||
lv_obj_scroll_by(obj, sl, 0, LV_ANIM_OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*If the object was out of the parent invalidate the new scrollbar area too.
|
||||
*If it wasn't out of the parent but out now, also invalidate the srollbars*/
|
||||
bool on2 = _lv_area_is_in(&obj->coords, &parent_fit_area, 0);
|
||||
if(on1 || (!on1 && on2)) lv_obj_scrollbar_invalidate(parent);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
|
||||
@ -916,36 +952,6 @@ static void layout_update_core(lv_obj_t * obj)
|
||||
lv_obj_refr_size(obj);
|
||||
lv_obj_refr_pos(obj);
|
||||
|
||||
|
||||
/*Be sure the bottom side is not remains scrolled in*/
|
||||
/*With snapping the content can't be scrolled in*/
|
||||
if(lv_obj_get_scroll_snap_y(obj) == LV_SCROLL_SNAP_NONE) {
|
||||
lv_coord_t st = lv_obj_get_scroll_top(obj);
|
||||
lv_coord_t sb = lv_obj_get_scroll_bottom(obj);
|
||||
if(sb < 0 && st > 0) {
|
||||
sb = LV_MIN(st, -sb);
|
||||
lv_obj_scroll_by(obj, 0, sb, LV_ANIM_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
if(lv_obj_get_scroll_snap_x(obj) == LV_SCROLL_SNAP_NONE) {
|
||||
lv_coord_t sl = lv_obj_get_scroll_left(obj);
|
||||
lv_coord_t sr = lv_obj_get_scroll_right(obj);
|
||||
if(lv_obj_get_base_dir(obj) != LV_BIDI_DIR_RTL) {
|
||||
/*Be sure the left side is not remains scrolled in*/
|
||||
if(sr < 0 && sl > 0) {
|
||||
sr = LV_MIN(sl, -sr);
|
||||
lv_obj_scroll_by(obj, sr, 0, LV_ANIM_OFF);
|
||||
}
|
||||
} else {
|
||||
/*Be sure the right side is not remains scrolled in*/
|
||||
if(sl < 0 && sr > 0) {
|
||||
sr = LV_MIN(sr, -sl);
|
||||
lv_obj_scroll_by(obj, sl, 0, LV_ANIM_OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(lv_obj_get_child_cnt(obj) > 0) {
|
||||
uint32_t layout_id = lv_obj_get_style_layout(obj, LV_PART_MAIN);
|
||||
if(layout_id > 0 && layout_id <= layout_cnt) {
|
||||
|
@ -68,7 +68,12 @@ void lv_obj_set_y(struct _lv_obj_t * obj, lv_coord_t y);
|
||||
*/
|
||||
void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h);
|
||||
|
||||
void lv_obj_refr_size(struct _lv_obj_t * obj);
|
||||
/**
|
||||
* Recalculate the size of the object
|
||||
* @param obj pointer to an object
|
||||
* @return true: the size has been changed
|
||||
*/
|
||||
bool lv_obj_refr_size(struct _lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Set the width of an object
|
||||
|
Loading…
x
Reference in New Issue
Block a user