From 2345e0073d2414720cd3b6aca9fbf2517a84a88f Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Wed, 10 Apr 2019 19:52:11 -0400 Subject: [PATCH] lv_list: check actual object type instead of relying on signal handler --- src/lv_objx/lv_list.c | 65 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/lv_objx/lv_list.c b/src/lv_objx/lv_list.c index d5655fb79..3445be569 100644 --- a/src/lv_objx/lv_list.c +++ b/src/lv_objx/lv_list.c @@ -40,6 +40,9 @@ 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 lv_list_btn_single_selected(lv_obj_t * btn); +static bool lv_list_is_list_btn(lv_obj_t * list_btn); +static bool lv_list_is_list_img(lv_obj_t * list_btn); +static bool lv_list_is_list_label(lv_obj_t * list_btn); /********************** * STATIC VARIABLES @@ -426,7 +429,7 @@ lv_obj_t * lv_list_get_btn_label(const lv_obj_t * btn) lv_obj_t * label = lv_obj_get_child(btn, NULL); if(label == NULL) return NULL; - while(label->signal_cb != label_signal) { + while(lv_list_is_list_label(label)) { label = lv_obj_get_child(btn, label); if(label == NULL) break; } @@ -445,7 +448,7 @@ lv_obj_t * lv_list_get_btn_img(const lv_obj_t * btn) lv_obj_t * img = lv_obj_get_child(btn, NULL); if(img == NULL) return NULL; - while(img->signal_cb != img_signal) { + while(lv_list_is_list_img(img)) { img = lv_obj_get_child(btn, img); if(img == NULL) break; } @@ -473,7 +476,7 @@ lv_obj_t * lv_list_get_prev_btn(const lv_obj_t * list, lv_obj_t * prev_btn) btn = lv_obj_get_child(scrl, prev_btn); if(btn == NULL) return NULL; - while(btn->signal_cb != lv_list_btn_signal) { + while(lv_list_is_list_btn(btn)) { btn = lv_obj_get_child(scrl, btn); if(btn == NULL) break; } @@ -498,7 +501,7 @@ lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn) btn = lv_obj_get_child_back(scrl, prev_btn); if(btn == NULL) return NULL; - while(btn->signal_cb != lv_list_btn_signal) { + while(lv_list_is_list_btn(btn)) { btn = lv_obj_get_child_back(scrl, btn); if(btn == NULL) break; } @@ -934,4 +937,58 @@ static void lv_list_btn_single_selected(lv_obj_t * btn) } while(e != NULL); } +/** + * Check if this is really a list button or another object. + * @param list_btn List button + */ +static bool lv_list_is_list_btn(lv_obj_t * list_btn) +{ + lv_obj_type_t type; + + lv_obj_get_type(list_btn, &type); + uint8_t cnt; + for(cnt = 0; cnt < LV_MAX_ANCESTOR_NUM; cnt++) { + if(type.type[cnt] == NULL) break; + if(!strcmp(type.type[cnt], "lv_btn")) + return true; + } + return false; +} + +/** + * Check if this is really a list label or another object. + * @param list_label List label + */ +static bool lv_list_is_list_label(lv_obj_t * list_label) +{ + lv_obj_type_t type; + + lv_obj_get_type(list_label, &type); + uint8_t cnt; + for(cnt = 0; cnt < LV_MAX_ANCESTOR_NUM; cnt++) { + if(type.type[cnt] == NULL) break; + if(!strcmp(type.type[cnt], "lv_label")) + return true; + } + return false; +} + +/** + * Check if this is really a list image or another object. + * @param list_image List image + */ +static bool lv_list_is_list_img(lv_obj_t * list_img) +{ + lv_obj_type_t type; + + lv_obj_get_type(list_img, &type); + uint8_t cnt; + for(cnt = 0; cnt < LV_MAX_ANCESTOR_NUM; cnt++) { + if(type.type[cnt] == NULL) break; + if(!strcmp(type.type[cnt], "lv_img")) + return true; + } + return false; +} + #endif