From 96c0050cb8d884240eae633d23184e22132f7e55 Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Mon, 5 Nov 2018 08:46:17 -0800 Subject: [PATCH 1/3] Remember list last selected --- lv_objx/lv_list.c | 17 ++++++++++++++--- lv_objx/lv_list.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index c0c994b65..71dc2fe40 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -655,8 +655,15 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) if(last_clicked_btn) { lv_list_set_btn_selected(list, last_clicked_btn); } else { - /*Get the first button and mark it as selected*/ - lv_list_set_btn_selected(list, lv_list_get_next_btn(list, NULL)); + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + if(NULL != ext->last_sel) { + /* Select the last used button */ + lv_list_set_btn_selected(list, ext->last_sel); + } + else { + /*Get the first button and mark it as selected*/ + lv_list_set_btn_selected(list, lv_list_get_next_btn(list, NULL)); + } } } #endif @@ -712,7 +719,11 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) if(btn != NULL) { lv_action_t rel_action; rel_action = lv_btn_get_action(btn, LV_BTN_ACTION_CLICK); - if(rel_action != NULL) rel_action(btn); + if(rel_action != NULL) { + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + ext->last_sel = btn; + rel_action(btn); + } } } #endif diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index 44ecf1f95..1e123e198 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -57,6 +57,7 @@ typedef struct lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of the list element buttons*/ lv_style_t *style_img; /*Style of the list element images on buttons*/ #if USE_LV_GROUP + lv_obj_t * last_sel; /* Last btn selected */ lv_obj_t * selected_btn; #endif } lv_list_ext_t; From e37e0079bec91c38eeb3be71a079f6670d043145 Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Mon, 5 Nov 2018 09:32:35 -0800 Subject: [PATCH 2/3] Set lv_list last_sel to NULL upon creation --- lv_objx/lv_list.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 71dc2fe40..183e0060d 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -90,6 +90,7 @@ lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy) ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_ina; ext->anim_time = LV_LIST_FOCUS_TIME; #if USE_LV_GROUP + ext->last_sel = NULL; ext->selected_btn = NULL; #endif From 9c2b0ac5ea1483c068bfa90afe86a4418e73f55b Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Tue, 6 Nov 2018 08:23:21 -0800 Subject: [PATCH 3/3] valid action not necessary to save last_sel --- lv_objx/lv_list.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 183e0060d..59c4d29eb 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -718,13 +718,11 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) } if(btn != NULL) { + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + ext->last_sel = btn; lv_action_t rel_action; rel_action = lv_btn_get_action(btn, LV_BTN_ACTION_CLICK); - if(rel_action != NULL) { - lv_list_ext_t * ext = lv_obj_get_ext_attr(list); - ext->last_sel = btn; - rel_action(btn); - } + if(rel_action != NULL) rel_action(btn); } } #endif