From 0e7d25ba85e47a28c2449dd098314ff48235cca5 Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Sun, 28 Oct 2018 15:27:41 -0700 Subject: [PATCH] Group refocus on deletion --- lv_core/lv_group.c | 18 +++++++++++++++--- lv_core/lv_group.h | 13 +++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index 7b399a978..d29af1fcd 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); } } @@ -122,7 +123,7 @@ void lv_group_remove_obj(lv_obj_t * obj) if(g->obj_focus == NULL) return; /*Just to be sure (Not possible if there is at least one object in the group)*/ if(*g->obj_focus == obj) { - lv_group_focus_next(g); + 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 +321,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 diff --git a/lv_core/lv_group.h b/lv_core/lv_group.h index 2efd023ed..e9d815798 100644 --- a/lv_core/lv_group.h +++ b/lv_core/lv_group.h @@ -56,8 +56,14 @@ typedef struct _lv_group_t uint8_t frozen :1; /*1: can't focus to new object*/ uint8_t editing :1; /*1: Edit mode, 0: Navigate mode*/ uint8_t click_focus :1; /*1: If an object in a group is clicked by an indev then it will be focused */ + uint8_t refocus_policy :1; /*1: Focus prev if focused on deletion. 0: Focus prev if focused on deletion.*/ } lv_group_t; +typedef enum _lv_group_refocus_policy_t { + LV_GROUP_REFOCUS_POLICY_NEXT = 0, + LV_GROUP_REFOCUS_POLICY_PREV = 1 +} lv_group_refocus_policy_t; + /********************** * GLOBAL PROTOTYPES **********************/ @@ -140,6 +146,13 @@ void lv_group_set_style_mod_edit_cb(lv_group_t * group, lv_group_style_mod_func_ */ void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb); +/** + * Set whether the next or previous item in a group is focused if the currently focussed obj is deleted. + * @param group pointer to a group + * @param new refocus policy enum + */ +void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy); + /** * Manually set the current mode (edit or navigate). * @param group pointer to group