Skip to content

Commit

Permalink
fix(obj): readjust scroll after layout when child removed
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Dec 2, 2023
1 parent b2fe03f commit ec08925
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/core/lv_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ typedef struct _lv_obj_t {
lv_obj_flag_t flags;
lv_state_t state;
uint16_t layout_inv : 1;
uint16_t readjust_scroll_after_layout : 1;
uint16_t scr_layout_inv : 1;
uint16_t skip_trans : 1;
uint16_t style_cnt : 6;
Expand Down
20 changes: 12 additions & 8 deletions src/core/lv_obj_pos.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ bool lv_obj_refr_size(lv_obj_t * obj)
/*Invalidate the new area*/
lv_obj_invalidate(obj);

lv_obj_readjust_scroll(obj, LV_ANIM_OFF);
obj->readjust_scroll_after_layout = 1;

/*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 scrollbars*/
Expand Down Expand Up @@ -1098,15 +1098,19 @@ static void layout_update_core(lv_obj_t * obj)
layout_update_core(child);
}

if(obj->layout_inv == 0) return;
if(obj->layout_inv) {
obj->layout_inv = 0;
lv_obj_refr_size(obj);
lv_obj_refr_pos(obj);

obj->layout_inv = 0;

lv_obj_refr_size(obj);
lv_obj_refr_pos(obj);
if(child_cnt > 0) {
_lv_layout_apply(obj);
}
}

if(child_cnt > 0) {
_lv_layout_apply(obj);
if(obj->readjust_scroll_after_layout) {
obj->readjust_scroll_after_layout = 0;
lv_obj_readjust_scroll(obj, LV_ANIM_OFF);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/lv_obj_scroll.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void lv_obj_get_scrollbar_area(struct _lv_obj_t * obj, lv_area_t * hor, lv_area_
void lv_obj_scrollbar_invalidate(struct _lv_obj_t * obj);

/**
* Checked if the content is scrolled "in" and adjusts it to a normal position.
* Checks if the content is scrolled "in" and adjusts it to a normal position.
* @param obj pointer to an object
* @param anim_en LV_ANIM_ON/OFF
*/
Expand Down
12 changes: 5 additions & 7 deletions src/core/lv_obj_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ void lv_obj_delete(lv_obj_t * obj)
lv_obj_invalidate(obj);

lv_obj_t * par = lv_obj_get_parent(obj);
if(par && !par->is_deleting) {
lv_obj_scrollbar_invalidate(par);
}

lv_display_t * disp = NULL;
bool act_screen_del = false;
Expand All @@ -76,9 +73,9 @@ void lv_obj_delete(lv_obj_t * obj)

/*Call the ancestor's event handler to the parent to notify it about the child delete*/
if(par && !par->is_deleting) {
lv_obj_update_layout(par);
lv_obj_readjust_scroll(par, LV_ANIM_OFF);
lv_obj_scrollbar_invalidate(par);
par->readjust_scroll_after_layout = 1;
lv_obj_mark_layout_as_dirty(par);
lv_obj_send_event(par, LV_EVENT_CHILD_CHANGED, NULL);
lv_obj_send_event(par, LV_EVENT_CHILD_DELETED, NULL);
}
Expand Down Expand Up @@ -190,8 +187,9 @@ void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent)
obj->parent = parent;

/*Notify the original parent because one of its children is lost*/
lv_obj_readjust_scroll(old_parent, LV_ANIM_OFF);
lv_obj_scrollbar_invalidate(old_parent);
old_parent->readjust_scroll_after_layout = 1;
lv_obj_mark_layout_as_dirty(old_parent);
lv_obj_send_event(old_parent, LV_EVENT_CHILD_CHANGED, obj);
lv_obj_send_event(old_parent, LV_EVENT_CHILD_DELETED, NULL);

Expand Down Expand Up @@ -639,4 +637,4 @@ static lv_obj_t * lv_obj_get_first_not_deleting_child(lv_obj_t * obj)
}

return NULL;
}
}

0 comments on commit ec08925

Please sign in to comment.