Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(obj): readjust scroll after layout when child removed #4916

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(obj): readjust scroll after layout when child removed
  • Loading branch information
niklasf committed Dec 2, 2023
commit f9ec084ed7266060b17977236e875179acf9a869
4 changes: 4 additions & 0 deletions src/core/lv_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ static void lv_obj_event(const lv_obj_class_t * class_p, lv_event_t * e)
lv_obj_mark_layout_as_dirty(obj);
}
}
else if(code == LV_EVENT_CHILD_DELETED) {
obj->readjust_scroll_after_layout = 1;
lv_obj_mark_layout_as_dirty(obj);
}
else if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) {
int32_t d = lv_obj_calculate_ext_draw_size(obj, LV_PART_MAIN);
lv_event_set_ext_draw_size(e, d);
Expand Down
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
8 changes: 1 addition & 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,8 +73,6 @@ 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);
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,7 +185,6 @@ 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);
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 +633,4 @@ static lv_obj_t * lv_obj_get_first_not_deleting_child(lv_obj_t * obj)
}

return NULL;
}
}
Loading