1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

Merge pull request #529 from joltwallet/rem_last_sel

Remember list last selected
This commit is contained in:
Gabor Kiss-Vamosi 2018-11-07 10:18:50 +01:00 committed by GitHub
commit 3f059575ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -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->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_ina;
ext->anim_time = LV_LIST_FOCUS_TIME; ext->anim_time = LV_LIST_FOCUS_TIME;
#if USE_LV_GROUP #if USE_LV_GROUP
ext->last_sel = NULL;
ext->selected_btn = NULL; ext->selected_btn = NULL;
#endif #endif
@ -712,8 +713,15 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
if(last_clicked_btn) { if(last_clicked_btn) {
lv_list_set_btn_selected(list, last_clicked_btn); lv_list_set_btn_selected(list, last_clicked_btn);
} else { } else {
/*Get the first button and mark it as selected*/ lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
lv_list_set_btn_selected(list, lv_list_get_next_btn(list, NULL)); 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 #endif
@ -767,6 +775,8 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
} }
if(btn != NULL) { if(btn != NULL) {
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
ext->last_sel = btn;
lv_action_t rel_action; lv_action_t rel_action;
rel_action = lv_btn_get_action(btn, LV_BTN_ACTION_CLICK); rel_action = lv_btn_get_action(btn, LV_BTN_ACTION_CLICK);
if(rel_action != NULL) rel_action(btn); if(rel_action != NULL) rel_action(btn);

View File

@ -58,6 +58,7 @@ typedef struct
lv_style_t *style_img; /*Style of the list element images on buttons*/ lv_style_t *style_img; /*Style of the list element images on buttons*/
uint32_t size; /*the number of items(buttons) in the list*/ uint32_t size; /*the number of items(buttons) in the list*/
#if USE_LV_GROUP #if USE_LV_GROUP
lv_obj_t * last_sel; /* Last btn selected */
lv_obj_t * selected_btn; lv_obj_t * selected_btn;
#endif #endif
} lv_list_ext_t; } lv_list_ext_t;