From 686c6c9033d70641afba0e1039156ec41ef1b1a8 Mon Sep 17 00:00:00 2001 From: fallstool Date: Tue, 30 Oct 2018 16:38:00 +0800 Subject: [PATCH 1/6] Update lv_list.h --- lv_objx/lv_list.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index 44ecf1f95..53e9b1aed 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -56,6 +56,7 @@ typedef struct uint16_t anim_time; /*Scroll animation time*/ 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*/ #if USE_LV_GROUP lv_obj_t * selected_btn; #endif @@ -106,6 +107,14 @@ void lv_list_clean(lv_obj_t *obj); */ lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, lv_action_t rel_action); +/** + * Remove the index of the button in the list + * @param list pointer to a list object + * @param index pointer to a the button's index in the list, index must be 0 <= index < lv_list_ext_t.size + * @return true: successfully deleted + */ +bool lv_list_remove(const lv_obj_t * list, uint32_t index); + /*===================== * Setter functions *====================*/ @@ -184,6 +193,21 @@ lv_obj_t * lv_list_get_prev_btn(const lv_obj_t * list, lv_obj_t * prev_btn); */ lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn); +/** + * Get the index of the button in the list + * @param list pointer to a list object + * @param btn pointer to a list element (button) + * @return the index of the button in the list, or -1 of the button not in this list + */ +int lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn); + +/** + * Get the number of buttons in the list + * @param list pointer to a list object + * @return the number of buttons in the list + */ +uint32_t lv_list_get_size(const lv_obj_t * list); + #if USE_LV_GROUP /** * Get the currently selected button From 5b05afe948309d53e2e70cfefbc0d0fe4ea3fcc6 Mon Sep 17 00:00:00 2001 From: fallstool Date: Tue, 30 Oct 2018 16:38:39 +0800 Subject: [PATCH 2/6] Update lv_list.c --- lv_objx/lv_list.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index c0c994b65..b3d779210 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -174,7 +174,7 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, { lv_style_t * style = lv_obj_get_style(list); lv_list_ext_t * ext = lv_obj_get_ext_attr(list); - + ext->size ++; /*Create a list element with the image an the text*/ lv_obj_t * liste; liste = lv_btn_create(list, NULL); @@ -225,6 +225,31 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, return liste; } +/** + * Remove the index of the button in the list + * @param list pointer to a list object + * @param index pointer to a the button's index in the list, index must be 0 <= index < lv_list_ext_t.size + * @return true: successfully deleted + */ +bool lv_list_remove(const lv_obj_t * list, uint32_t index) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + if(index < 0 && index >= ext->size) return false; + int count = 0; + lv_obj_t * e = lv_list_get_next_btn(list, NULL); + while(e != NULL) { + if(count == index) + { + lv_obj_del(e); + ext->size --; + return true; + } + e = lv_list_get_next_btn(list, e); + count ++; + } + return false; +} + /*===================== * Setter functions *====================*/ @@ -441,6 +466,38 @@ lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn) return btn; } +/** + * Get the index of the button in the list + * @param list pointer to a list object + * @param btn pointer to a list element (button) + * @return the index of the button in the list, or -1 of the button not in this list + */ +int lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn) +{ + int index = 0; + lv_obj_t * e = lv_list_get_next_btn(list, NULL); + while(e != NULL) { + if(e == btn) + { + return index; + } + index ++; + e = lv_list_get_next_btn(list, e); + } + return -1; +} + +/** + * Get the number of buttons in the list + * @param list pointer to a list object + * @return the number of buttons in the list + */ +uint32_t lv_list_get_size(const lv_obj_t * list) +{ + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); + return ext->size; +} + #if USE_LV_GROUP /** * Get the currently selected button From 34f8013465350e864671b626134ec24a49ce1dff Mon Sep 17 00:00:00 2001 From: fallstool Date: Tue, 30 Oct 2018 17:04:11 +0800 Subject: [PATCH 3/6] Update lv_list.h --- lv_objx/lv_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index 53e9b1aed..fec507003 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -199,7 +199,7 @@ lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn); * @param btn pointer to a list element (button) * @return the index of the button in the list, or -1 of the button not in this list */ -int lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn); +int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn); /** * Get the number of buttons in the list From 17bc493612eebd1f27027e3c20a53f031d912e15 Mon Sep 17 00:00:00 2001 From: fallstool Date: Tue, 30 Oct 2018 17:05:27 +0800 Subject: [PATCH 4/6] Update lv_list.c --- lv_objx/lv_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index b3d779210..891a9d31a 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -472,7 +472,7 @@ lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn) * @param btn pointer to a list element (button) * @return the index of the button in the list, or -1 of the button not in this list */ -int lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn) +int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn) { int index = 0; lv_obj_t * e = lv_list_get_next_btn(list, NULL); From 6ecd3f1f8a8c68a9edb687188b89aaace26c7b20 Mon Sep 17 00:00:00 2001 From: fallstool Date: Tue, 30 Oct 2018 18:08:38 +0800 Subject: [PATCH 5/6] Update lv_list.c --- lv_objx/lv_list.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 891a9d31a..971d41ab5 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -156,6 +156,8 @@ void lv_list_clean(lv_obj_t * obj) { lv_obj_t * scrl = lv_page_get_scrl(obj); lv_obj_clean(scrl); + lv_list_ext_t * ext = lv_obj_get_ext_attr(obj); + ext->size = 0; } /*====================== From 46b41862162b13201ff72f590d85438858ea6c12 Mon Sep 17 00:00:00 2001 From: fallstool Date: Thu, 1 Nov 2018 09:58:55 +0800 Subject: [PATCH 6/6] Update lv_list.c change the code style --- lv_objx/lv_list.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 971d41ab5..4ccb5ab20 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -240,8 +240,7 @@ bool lv_list_remove(const lv_obj_t * list, uint32_t index) int count = 0; lv_obj_t * e = lv_list_get_next_btn(list, NULL); while(e != NULL) { - if(count == index) - { + if(count == index) { lv_obj_del(e); ext->size --; return true; @@ -479,8 +478,7 @@ int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn) int index = 0; lv_obj_t * e = lv_list_get_next_btn(list, NULL); while(e != NULL) { - if(e == btn) - { + if(e == btn) { return index; } index ++;