From 4ac1c29ca917d14f1d8711f698949361f04956eb Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sun, 17 Jun 2018 16:43:28 +0200 Subject: [PATCH] lv_group_remove_obj: fix when delete the last object from the group --- lv_core/lv_group.c | 13 +++++++++++-- lv_core/lv_group.h | 2 +- lv_core/lv_indev.c | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index 16f365e71..53464e6cf 100644 --- a/lv_core/lv_group.c +++ b/lv_core/lv_group.c @@ -58,7 +58,7 @@ lv_group_t * lv_group_create(void) */ void lv_group_del(lv_group_t * group) { - /*Defocus the the currently focussed object*/ + /*Defocus the the currently focused object*/ if(group->obj_focus != NULL) { (*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL); lv_obj_invalidate(*group->obj_focus); @@ -81,6 +81,8 @@ void lv_group_del(lv_group_t * group) */ void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj) { + if(group == NULL) return; + obj->group_p = group; lv_obj_t ** next = lv_ll_ins_tail(&group->obj_ll); *next = obj; @@ -100,10 +102,17 @@ void lv_group_remove_obj(lv_obj_t * obj) { lv_group_t * g = obj->group_p; 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)*/ if(*g->obj_focus == obj) { lv_group_focus_next(g); - } + } + + /* If the focuses object is still the same then it was the only object in the group but it will be deleted. + * Set the `obj_focus` to NULL to get back to the initial state of the group with zero objects*/ + if(*g->obj_focus == obj) { + g->obj_focus = NULL; + } /*Search the object and remove it from its group */ lv_obj_t ** i; diff --git a/lv_core/lv_group.h b/lv_core/lv_group.h index f8ff0dc4e..c027bb9d0 100644 --- a/lv_core/lv_group.h +++ b/lv_core/lv_group.h @@ -45,7 +45,7 @@ typedef struct _lv_group_t { lv_ll_t obj_ll; /*Linked list to store the objects in the group */ lv_obj_t ** obj_focus; /*The object in focus*/ - lv_group_style_mod_func_t style_mod; /*A function which modifies the style of the focused object*/ + lv_group_style_mod_func_t style_mod; /*A function which modifies the style of the focused object*/ lv_group_focus_cb_t focus_cb; /*A function to call when a new object is focused (optional)*/ lv_style_t style_tmp; /*Stores the modified style of the focused object */ uint8_t frozen:1; /*1: can't focus to new object*/ diff --git a/lv_core/lv_indev.c b/lv_core/lv_indev.c index 6650b85f4..1cc9cdfe5 100644 --- a/lv_core/lv_indev.c +++ b/lv_core/lv_indev.c @@ -367,6 +367,8 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) lv_group_send_data(i->group, data->key); } + if(i->proc.reset_query) return; /*The object might be deleted in `focus_cb` or due to any other user event*/ + i->proc.pr_timestamp = 0; i->proc.long_pr_sent = 0; }