diff --git a/src/core/lv_group.c b/src/core/lv_group.c index f7b82751d..c1787b030 100644 --- a/src/core/lv_group.c +++ b/src/core/lv_group.c @@ -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); diff --git a/src/core/lv_group.h b/src/core/lv_group.h index 63dd37800..6e9a1667b 100644 --- a/src/core/lv_group.h +++ b/src/core/lv_group.h @@ -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 diff --git a/src/core/lv_obj_tree.c b/src/core/lv_obj_tree.c index a8141f617..c53d97a95 100644 --- a/src/core/lv_obj_tree.c +++ b/src/core/lv_obj_tree.c @@ -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)