From b44da3c27f296a5a0229b6e493c7f14e04776bc2 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sun, 11 Nov 2018 00:02:44 +0100 Subject: [PATCH] lv_group: fix lv_group_remove_obj() if there is only object is the group --- lv_core/lv_group.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index 7b399a978..4a87067e8 100644 --- a/lv_core/lv_group.c +++ b/lv_core/lv_group.c @@ -23,6 +23,7 @@ **********************/ static void style_mod_def(lv_style_t * style); static void style_mod_edit_def(lv_style_t * style); +static void lv_group_refocus(lv_group_t *g); /********************** * STATIC VARIABLES @@ -92,7 +93,7 @@ void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj) /*If the object is already in a group and focused then defocuse it*/ if(obj->group_p) { if(lv_obj_is_focused(obj)) { - lv_group_focus_next(obj->group_p); + lv_group_refocus(obj->group_p); LV_LOG_INFO("group: assign object to an other group"); } @@ -107,7 +108,7 @@ void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj) /* If the head and the tail is equal then there is only one object in the linked list. * In this case automatically activate it*/ if(lv_ll_get_head(&group->obj_ll) == next) { - lv_group_focus_next(group); + lv_group_refocus(group); } } @@ -121,8 +122,16 @@ void lv_group_remove_obj(lv_obj_t * obj) if(g == NULL) return; if(g->obj_focus == NULL) return; /*Just to be sure (Not possible if there is at least one object in the group)*/ + /*Focus on the next object*/ if(*g->obj_focus == obj) { - lv_group_focus_next(g); + /*If this is the only object in the group then focus to nothing.*/ + if(lv_ll_get_head(&g->obj_ll) == g->obj_focus && lv_ll_get_tail(&g->obj_ll) == g->obj_focus) { + (*g->obj_focus)->signal_func(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL); + } + /*If there more objects in the group then focus to the next/prev object*/ + else { + lv_group_refocus(g); + } } /* If the focuses object is still the same then it was the only object in the group but it will be deleted. @@ -320,6 +329,17 @@ void lv_group_set_click_focus(lv_group_t * group, bool en) group->click_focus = en ? 1 : 0; } +void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy) { + group->refocus_policy = policy & 0x01; +} + +static void lv_group_refocus(lv_group_t *g) { + if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_NEXT) + lv_group_focus_next(g); + else if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_PREV) + lv_group_focus_prev(g); +} + /** * Modify a style with the set 'style_mod' function. The input style remains unchanged. * @param group pointer to group