Skip to content

Commit

Permalink
fix(obj) swap objects in the group too in lv_obj_swap()
Browse files Browse the repository at this point in the history
fix #2462
  • Loading branch information
kisvegabor committed Aug 19, 2021
1 parent 906448e commit 52c7558
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/core/lv_group.c
Expand Up @@ -139,6 +139,21 @@ void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj)
LV_LOG_TRACE("finished");
}

void lv_group_swap_obj(lv_obj_t * obj1, lv_obj_t * obj2)
{
lv_group_t * g1 = lv_obj_get_group(obj1);
lv_group_t * g2 = lv_obj_get_group(obj2);
if(g1 != g2) return;
if(g1 == NULL) return;

/*Do not add the object twice*/
lv_obj_t ** obj_i;
_LV_LL_READ(&g1->obj_ll, obj_i) {
if((*obj_i) == obj1) (*obj_i) = obj2;
else if((*obj_i) == obj2) (*obj_i) = obj1;
}
}

void lv_group_remove_obj(lv_obj_t * obj)
{
lv_group_t * g = lv_obj_get_group(obj);
Expand Down
7 changes: 7 additions & 0 deletions src/core/lv_group.h
Expand Up @@ -119,6 +119,13 @@ lv_group_t * lv_group_get_default(void);
*/
void lv_group_add_obj(lv_group_t * group, struct _lv_obj_t * obj);

/**
* Swap 2 object in a group. The object must be in the same group
* @param obj1 pointer to an object
* @param obj2 pointer to an other object
*/
void lv_group_swap_obj(struct _lv_obj_t * obj1, struct _lv_obj_t * obj2);

/**
* Remove an object from its group
* @param obj pointer to an object to remove
Expand Down
5 changes: 3 additions & 2 deletions src/core/lv_obj_tree.c
Expand Up @@ -253,10 +253,11 @@ void lv_obj_swap(lv_obj_t * obj1, lv_obj_t * obj2)
lv_event_send(parent2, LV_EVENT_CHILD_CHANGED, obj1);

lv_obj_invalidate(parent);
if( parent != parent2)
{
if( parent != parent2) {
lv_obj_invalidate(parent2);
}

lv_group_swap_obj(obj1, obj2);
}

lv_obj_t * lv_obj_get_screen(const lv_obj_t * obj)
Expand Down

0 comments on commit 52c7558

Please sign in to comment.