From 7da01d86836e4108e8fed244265ff4f85af5fb77 Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 3 Dec 2018 19:44:58 +0800 Subject: [PATCH 1/6] Update lv_list.c --- lv_objx/lv_list.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index b0f485ec4..63e706ab4 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -256,6 +256,29 @@ bool lv_list_remove(const lv_obj_t * list, uint32_t index) * Setter functions *====================*/ +/** + * Make a single button selected in the list, deselect others, should be called in list btns call back. + * @param btn pointer to the currently pressed list btn object + */ +void lv_list_set_btn_single_selected(lv_obj_t *btn) +{ + lv_obj_t *list = lv_obj_get_parent(lv_obj_get_parent(btn)); + + lv_obj_t * e = lv_list_get_next_btn(list, NULL); + do + { + if(e == btn) + { + lv_btn_set_state(e, LV_BTN_STATE_TGL_REL); + } + else + { + lv_btn_set_state(e, LV_BTN_STATE_REL); + } + e = lv_list_get_next_btn(list, e); + } while (e != NULL); +} + #if USE_LV_GROUP /** From cde5f311354c481160adc0e3df57553fca106626 Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 3 Dec 2018 19:45:47 +0800 Subject: [PATCH 2/6] Update lv_list.h --- lv_objx/lv_list.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index a1ecaf3ce..f6db5d4cb 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -119,6 +119,13 @@ bool lv_list_remove(const lv_obj_t * list, uint32_t index); /*===================== * Setter functions *====================*/ + +/** + * Make a single button selected in the list, deselect others, should be called in list btns call back. + * @param btn pointer to the currently pressed list btn object + */ +void lv_list_set_btn_single_selected(lv_obj_t *btn); + #if USE_LV_GROUP /** From be8d241e0605db465792cbb5b8222b85f14344d0 Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 7 Dec 2018 15:21:35 +0800 Subject: [PATCH 3/6] Update lv_list.h --- lv_objx/lv_list.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index f6db5d4cb..74026a7e3 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -121,10 +121,11 @@ bool lv_list_remove(const lv_obj_t * list, uint32_t index); *====================*/ /** - * Make a single button selected in the list, deselect others, should be called in list btns call back. - * @param btn pointer to the currently pressed list btn object + * Set single button selected mode, only one button will be selected if enabled. + * @param list pointer to the currently pressed list object + * @param mode, enable(true)/disable(false) single selected mode. */ -void lv_list_set_btn_single_selected(lv_obj_t *btn); +void lv_list_set_btn_single_selected_mode(lv_obj_t *list, bool mode); #if USE_LV_GROUP @@ -175,6 +176,12 @@ void lv_list_set_style(lv_obj_t *list, lv_list_style_t type, lv_style_t *style); * Getter functions *====================*/ +/** + * Get single button selected mode. + * @param list pointer to the currently pressed list object. + */ +bool lv_list_get_btn_single_selected_mode(lv_obj_t *list); + /** * Get the text of a list element * @param btn pointer to list element From c7846c827b7f03efc033d049eb9a8018dadbd41f Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 7 Dec 2018 15:22:07 +0800 Subject: [PATCH 4/6] Update lv_list.c Use setter function enable/disable single selected mode. --- lv_objx/lv_list.c | 71 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 63e706ab4..3e3e5578d 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -38,6 +38,7 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param); static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param); static void refr_btn_width(lv_obj_t * list); +static void lv_list_btn_single_selected(lv_obj_t *btn); /********************** * STATIC VARIABLES @@ -89,6 +90,8 @@ lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy) ext->styles_btn[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pr; ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_ina; ext->anim_time = LV_LIST_FOCUS_TIME; + ext->single_selected_mode = false; + #if USE_LV_GROUP ext->last_sel = NULL; ext->selected_btn = NULL; @@ -257,26 +260,15 @@ bool lv_list_remove(const lv_obj_t * list, uint32_t index) *====================*/ /** - * Make a single button selected in the list, deselect others, should be called in list btns call back. - * @param btn pointer to the currently pressed list btn object + * Set single button selected mode, only one button will be selected if enabled. + * @param list pointer to the currently pressed list object + * @param mode, enable(true)/disable(false) single selected mode. */ -void lv_list_set_btn_single_selected(lv_obj_t *btn) +void lv_list_set_btn_single_selected_mode(lv_obj_t *list, bool mode) { - lv_obj_t *list = lv_obj_get_parent(lv_obj_get_parent(btn)); + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); - lv_obj_t * e = lv_list_get_next_btn(list, NULL); - do - { - if(e == btn) - { - lv_btn_set_state(e, LV_BTN_STATE_TGL_REL); - } - else - { - lv_btn_set_state(e, LV_BTN_STATE_REL); - } - e = lv_list_get_next_btn(list, e); - } while (e != NULL); + ext->single_selected_mode = mode; } #if USE_LV_GROUP @@ -388,6 +380,17 @@ void lv_list_set_style(lv_obj_t * list, lv_list_style_t type, lv_style_t * style * Getter functions *====================*/ +/** + * Get single button selected mode. + * @param list pointer to the currently pressed list object. + */ +bool lv_list_get_btn_single_selected_mode(lv_obj_t *list) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + + return (ext->single_selected_mode); +} + /** * Get the text of a list element * @param btn pointer to list element @@ -850,8 +853,9 @@ static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * para res = ancestor_btn_signal(btn, sign, param); if(res != LV_RES_OK) return res; -#if USE_LV_GROUP if(sign == LV_SIGNAL_RELEASED) { + +#if USE_LV_GROUP lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn)); lv_group_t * g = lv_obj_get_group(list); if(lv_group_get_focused(g) == list && lv_indev_is_dragging(lv_indev_get_act()) == false) { @@ -872,8 +876,15 @@ static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * para /* If `click_focus == 1` then LV_SIGNAL_FOCUS need to know which button triggered the focus * to mark it as selected (pressed state)*/ last_clicked_btn = btn; - +#endif + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + if(lv_indev_is_dragging(lv_indev_get_act()) == false && ext->single_selected_mode) + { + lv_list_btn_single_selected(btn); + } } + +#if USE_LV_GROUP if(sign == LV_SIGNAL_CLEANUP) { lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn)); @@ -907,5 +918,27 @@ static void refr_btn_width(lv_obj_t * list) } } +/** + * Make a single button selected in the list, deselect others, should be called in list btns call back. + * @param btn pointer to the currently pressed list btn object + */ +static void lv_list_btn_single_selected(lv_obj_t *btn) +{ + lv_obj_t *list = lv_obj_get_parent(lv_obj_get_parent(btn)); + + lv_obj_t * e = lv_list_get_next_btn(list, NULL); + do + { + if(e == btn) + { + lv_btn_set_state(e, LV_BTN_STATE_TGL_REL); + } + else + { + lv_btn_set_state(e, LV_BTN_STATE_REL); + } + e = lv_list_get_next_btn(list, e); + } while (e != NULL); +} #endif From 648c3430ef86253518400719739d3132258e8815 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Sat, 8 Dec 2018 09:22:41 -0500 Subject: [PATCH 5/6] Add `bool single_selected_mode` to `lv_list_ext_t` --- lv_objx/lv_list.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index 74026a7e3..b79491b47 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*/ uint32_t size; /*the number of items(buttons) in the list*/ + bool single_selected_mode; /* whether single selected mode is enabled */ #if USE_LV_GROUP lv_obj_t * last_sel; /* Last btn selected */ lv_obj_t * selected_btn; From e5dabf716aea3307b01e4599e640b2542e071002 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Sun, 9 Dec 2018 20:30:36 -0500 Subject: [PATCH 6/6] Rename `btn_single_selected_mode` to `single_mode` --- lv_objx/lv_list.c | 12 ++++++------ lv_objx/lv_list.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 87a91ea75..62b258503 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -90,7 +90,7 @@ lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy) ext->styles_btn[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pr; ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_ina; ext->anim_time = LV_LIST_FOCUS_TIME; - ext->single_selected_mode = false; + ext->single_mode = false; #if USE_LV_GROUP ext->last_sel = NULL; @@ -264,11 +264,11 @@ bool lv_list_remove(const lv_obj_t * list, uint32_t index) * @param list pointer to the currently pressed list object * @param mode, enable(true)/disable(false) single selected mode. */ -void lv_list_set_btn_single_selected_mode(lv_obj_t *list, bool mode) +void lv_list_set_single_mode(lv_obj_t *list, bool mode) { lv_list_ext_t * ext = lv_obj_get_ext_attr(list); - ext->single_selected_mode = mode; + ext->single_mode = mode; } #if USE_LV_GROUP @@ -387,11 +387,11 @@ void lv_list_set_style(lv_obj_t * list, lv_list_style_t type, lv_style_t * style * Get single button selected mode. * @param list pointer to the currently pressed list object. */ -bool lv_list_get_btn_single_selected_mode(lv_obj_t *list) +bool lv_list_get_single_mode(lv_obj_t *list) { lv_list_ext_t * ext = lv_obj_get_ext_attr(list); - return (ext->single_selected_mode); + return (ext->single_mode); } /** @@ -885,7 +885,7 @@ static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * para * to mark it as selected (pressed state)*/ last_clicked_btn = btn; #endif - if(lv_indev_is_dragging(lv_indev_get_act()) == false && ext->single_selected_mode) + if(lv_indev_is_dragging(lv_indev_get_act()) == false && ext->single_mode) { lv_list_btn_single_selected(btn); } diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index 20fa98cc7..572f0189e 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -57,7 +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*/ uint32_t size; /*the number of items(buttons) in the list*/ - bool single_selected_mode; /* whether single selected mode is enabled */ + bool single_mode; /* whether single selected mode is enabled */ #if USE_LV_GROUP lv_obj_t * last_sel; /* Last btn selected */ lv_obj_t * selected_btn; @@ -127,7 +127,7 @@ bool lv_list_remove(const lv_obj_t * list, uint32_t index); * @param list pointer to the currently pressed list object * @param mode, enable(true)/disable(false) single selected mode. */ -void lv_list_set_btn_single_selected_mode(lv_obj_t *list, bool mode); +void lv_list_set_single_mode(lv_obj_t *list, bool mode); #if USE_LV_GROUP @@ -192,7 +192,7 @@ void lv_list_set_style(lv_obj_t *list, lv_list_style_t type, lv_style_t *style); * Get single button selected mode. * @param list pointer to the currently pressed list object. */ -bool lv_list_get_btn_single_selected_mode(lv_obj_t *list); +bool lv_list_get_single_mode(lv_obj_t *list); /** * Get the text of a list element