Skip to content

Commit

Permalink
fix(group) keep the focused object in lv_group_swap_obj
Browse files Browse the repository at this point in the history
fixes #2462
kisvegabor committed Aug 19, 2021
1 parent f85ae9d commit a997147
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions examples/widgets/list/lv_example_list_2.c
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ void lv_example_list_2(void)
{
/*Create a list*/
list1 = lv_list_create(lv_scr_act());
lv_obj_set_size(list1, lv_pct(70), lv_pct(100));
lv_obj_set_size(list1, lv_pct(60), lv_pct(100));
lv_obj_set_style_pad_row(list1, 5, 0);

/*Add buttons to the list*/
@@ -94,15 +94,17 @@ void lv_example_list_2(void)

/*Create a second list with up and down buttons*/
list2 = lv_list_create(lv_scr_act());
lv_obj_set_size(list2, lv_pct(30), lv_pct(100));
lv_obj_set_size(list2, lv_pct(40), lv_pct(100));
lv_obj_align(list2, LV_ALIGN_TOP_RIGHT, 0, 0);
lv_obj_set_flex_flow(list2, LV_FLEX_FLOW_COLUMN);

btn = lv_list_add_btn(list2, LV_SYMBOL_UP, "Up");
lv_obj_add_event_cb(btn, event_handler_mu, LV_EVENT_ALL, NULL);
lv_group_remove_obj(btn);

btn = lv_list_add_btn(list2, LV_SYMBOL_DOWN, "Down");
lv_obj_add_event_cb(btn, event_handler_dn, LV_EVENT_ALL, NULL);
lv_group_remove_obj(btn);
}

#endif
4 changes: 4 additions & 0 deletions src/core/lv_group.c
Original file line number Diff line number Diff line change
@@ -152,6 +152,10 @@ void lv_group_swap_obj(lv_obj_t * obj1, lv_obj_t * obj2)
if((*obj_i) == obj1) (*obj_i) = obj2;
else if((*obj_i) == obj2) (*obj_i) = obj1;
}

if(*g1->obj_focus == obj1) lv_group_focus_obj(obj2);
else if(*g1->obj_focus == obj2) lv_group_focus_obj(obj1);

}

void lv_group_remove_obj(lv_obj_t * obj)

0 comments on commit a997147

Please sign in to comment.