From 29a695b4a6ab6d2a8d627fdf2b38c6b79b56e2ce Mon Sep 17 00:00:00 2001 From: Samuel Date: Thu, 8 Nov 2018 22:39:08 +0800 Subject: [PATCH] Add files via upload --- lv_objx/lv_ddlist.c | 105 +++++++++++++++++++++++++++++--------------- lv_objx/lv_ddlist.h | 1 + lv_objx/lv_roller.c | 44 +++++++------------ 3 files changed, 86 insertions(+), 64 deletions(-) diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index c55d8f603..952d98b3e 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -92,6 +92,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy) ext->option_cnt = 0; ext->anim_time = LV_DDLIST_ANIM_TIME; ext->sel_style = &lv_style_plain_color; + ext->roller_ddlist = 1; /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_func(new_ddlist, lv_ddlist_signal); @@ -366,25 +367,21 @@ uint16_t lv_ddlist_get_anim_time(const lv_obj_t * ddlist) */ lv_style_t * lv_ddlist_get_style(const lv_obj_t * ddlist, lv_ddlist_style_t type) { - lv_style_t * style = NULL; lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); switch(type) { case LV_DDLIST_STYLE_BG: - style = lv_page_get_style(ddlist, LV_PAGE_STYLE_BG); - break; + return lv_page_get_style(ddlist, LV_PAGE_STYLE_BG); case LV_DDLIST_STYLE_SB: - style = lv_page_get_style(ddlist, LV_PAGE_STYLE_SB); - break; + return lv_page_get_style(ddlist, LV_PAGE_STYLE_SB); case LV_DDLIST_STYLE_SEL: - style = ext->sel_style; - break; + return ext->sel_style; default: - style = NULL; - break; + return NULL; } - return style; + /*To avoid warning*/ + return NULL; } /*===================== * Other functions @@ -420,6 +417,23 @@ void lv_ddlist_close(lv_obj_t * ddlist, bool anim_en) ext->opened = 0; lv_obj_set_drag(lv_page_get_scrl(ddlist), false); lv_ddlist_refr_size(ddlist, anim_en); + //modify2 + lv_area_t area_off; + area_off.y1 = ext->label->coords.y1; + area_off.y1 = ext->label->coords.y1; + area_off.x1 = ext->label->coords.x2; + area_off.x2 = area_off.x1 + 12; + area_off.y2 = ext->label->coords.y2; + lv_style_t * sel_style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); + lv_style_t new_style; + lv_style_copy(&new_style, sel_style); + new_style.text.color = sel_style->text.color; + new_style.text.opa = sel_style->text.opa; + lv_obj_t *t; + t = lv_label_create(ddlist,NULL); + lv_obj_set_style(t, &new_style); + lv_label_set_text(t, CUSTOM_SYMBOL_DOWN); + lv_obj_set_pos(t, area_off.x1,area_off.y2); } /********************** @@ -448,7 +462,6 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_desig lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); lv_opa_t opa_scale = lv_obj_get_opa_scale(ddlist); - /*If the list is opened draw a rectangle under the selected item*/ if(ext->opened != 0) { lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); @@ -501,6 +514,41 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_desig lv_label_get_text(ext->label), LV_TXT_FLAG_NONE, NULL); } } + //Add a down symbol in ddlist + else + { + if(ext->roller_ddlist) + { + lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); + const lv_font_t * font = style->text.font; + lv_style_t * sel_style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); + lv_coord_t font_h = lv_font_get_height(font); + lv_style_t new_style; + lv_style_copy(&new_style, style); + new_style.text.color = sel_style->text.color; + new_style.text.opa = sel_style->text.opa; + lv_area_t area_sel; + area_sel.y1 = ext->label->coords.y1; + area_sel.y1 += ext->sel_opt_id * (font_h + style->text.line_space); + area_sel.y1 -= style->text.line_space / 2; + + area_sel.y2 = area_sel.y1 + font_h + style->text.line_space - 1; + area_sel.x1 = ddlist->coords.x1; + area_sel.x2 = ddlist->coords.x2; + lv_coord_t w = lv_obj_get_width(ddlist); + area_sel.x1 = ddlist->coords.x2 - 20; + area_sel.x2 = ddlist->coords.x2 + w; + area_sel.y1 += 2; + lv_area_t mask_sel; + bool area_ok; + area_ok = lv_area_intersect(&mask_sel, mask, &area_sel); + if (area_ok) + { + lv_draw_label(&area_sel, &mask_sel, &new_style, opa_scale, + CUSTOM_SYMBOL_DOWN, LV_TXT_FLAG_NONE, NULL); + } + } + } /*Draw the scrollbar in the ancestor page design function*/ ancestor_design(ddlist, mask, mode); @@ -530,12 +578,10 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par } else if(sign == LV_SIGNAL_CLEANUP) { ext->label = NULL; } else if(sign == LV_SIGNAL_FOCUS) { - bool editing = false; -#if USE_LV_GROUP lv_group_t * g = lv_obj_get_group(ddlist); - editing = lv_group_get_editing(g); -#endif + bool editing = lv_group_get_editing(g); lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); + /*Encoders need special handling*/ if(indev_type == LV_INDEV_TYPE_ENCODER) { /*Open the list if editing*/ @@ -592,19 +638,16 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par if(ext->opened) { ext->sel_opt_id_ori = ext->sel_opt_id; ext->opened = 0; - if(ext->action) res = ext->action(ddlist); -#if USE_LV_GROUP - if(res == LV_RES_OK) { - lv_group_t * g = lv_obj_get_group(ddlist); - bool editing = lv_group_get_editing(g); - if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/ - } -#endif + if(ext->action) ext->action(ddlist); + + lv_group_t * g = lv_obj_get_group(ddlist); + bool editing = lv_group_get_editing(g); + if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/ } else { ext->opened = 1; } - if(res == LV_RES_OK) lv_ddlist_refr_size(ddlist, true); + lv_ddlist_refr_size(ddlist, true); } else if(c == LV_GROUP_KEY_ESC) { if(ext->opened) { ext->opened = 0; @@ -664,7 +707,6 @@ static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * static lv_res_t lv_ddlist_release_action(lv_obj_t * ddlist) { lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - lv_res_t res = LV_RES_OK; if(ext->opened == 0) { /*Open the list*/ ext->opened = 1; @@ -695,13 +737,12 @@ static lv_res_t lv_ddlist_release_action(lv_obj_t * ddlist) ext->sel_opt_id = new_opt; if(ext->action != NULL) { - res = ext->action(ddlist); + ext->action(ddlist); } } + lv_ddlist_refr_size(ddlist, true); - if(res == LV_RES_OK) lv_ddlist_refr_size(ddlist, true); - - return res; + return LV_RES_OK; } @@ -716,9 +757,6 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en) anim_en = false; #endif lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - - if(ext->label == NULL) return; /*Probably the ddlist is being deleted if the label is NULL.*/ - lv_style_t * style = lv_obj_get_style(ddlist); lv_coord_t new_height; if(ext->opened) { /*Open the list*/ @@ -767,9 +805,6 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en) static void lv_ddlist_pos_current_option(lv_obj_t * ddlist) { lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - - if(ext->label == NULL) return; /*Probably the ddlist is being deleted if the label is NULL.*/ - lv_style_t * style = lv_obj_get_style(ddlist); const lv_font_t * font = style->text.font; lv_coord_t font_h = lv_font_get_height(font); diff --git a/lv_objx/lv_ddlist.h b/lv_objx/lv_ddlist.h index 4833707f2..ddb436898 100644 --- a/lv_objx/lv_ddlist.h +++ b/lv_objx/lv_ddlist.h @@ -54,6 +54,7 @@ typedef struct uint16_t sel_opt_id_ori; /*Store the original index on focus*/ uint16_t anim_time; /*Open/Close animation time [ms]*/ uint8_t opened :1; /*1: The list is opened (handled by the library)*/ + uint8_t roller_ddlist :1; /*0: The list is roller, otherwise ddlist*/ lv_coord_t fix_height; /*Height of the ddlist when opened. (0: auto-size)*/ } lv_ddlist_ext_t; diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index cf35adddf..3bc354c72 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -75,6 +75,7 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy) lv_mem_assert(ext); if(ext == NULL) return NULL; + ext->ddlist.roller_ddlist = 0; /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_func(new_roller, lv_roller_signal); lv_obj_set_design_func(new_roller, lv_roller_design); @@ -192,21 +193,17 @@ bool lv_roller_get_hor_fit(const lv_obj_t * roller) * */ lv_style_t * lv_roller_get_style(const lv_obj_t * roller, lv_roller_style_t type) { - lv_style_t * style = NULL; - switch(type) { case LV_ROLLER_STYLE_BG: - style = lv_obj_get_style(roller); - break; + return lv_obj_get_style(roller); case LV_ROLLER_STYLE_SEL: - style = lv_ddlist_get_style(roller, LV_DDLIST_STYLE_SEL); - break; + return lv_ddlist_get_style(roller, LV_DDLIST_STYLE_SEL); default: - style = NULL; - break; + return NULL; } - return style; + /*To avoid warning*/ + return NULL; } /********************** @@ -319,11 +316,8 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par refr_position(roller, false); } } else if(sign == LV_SIGNAL_FOCUS) { - bool editing = false; -#if USE_LV_GROUP lv_group_t * g = lv_obj_get_group(roller); - editing = lv_group_get_editing(g); -#endif + bool editing = lv_group_get_editing(g); lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); /*Encoders need special handling*/ @@ -363,15 +357,11 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par } } else if(c == LV_GROUP_KEY_ENTER) { ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; /*Set the entered value as default*/ - if(ext->ddlist.action) res = ext->ddlist.action(roller); -#if USE_LV_GROUP - if(res == LV_RES_OK) { - lv_group_t * g = lv_obj_get_group(roller); - bool editing = lv_group_get_editing(g); + if(ext->ddlist.action) ext->ddlist.action(roller); - if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/ - } -#endif + lv_group_t * g = lv_obj_get_group(roller); + bool editing = lv_group_get_editing(g); + if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/ } } else if(sign == LV_SIGNAL_GET_TYPE) { lv_obj_type_t * buf = param; @@ -420,8 +410,7 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, if(id < 0) id = 0; if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1; ext->ddlist.sel_opt_id = id; - ext->ddlist.sel_opt_id_ori = id; - if(ext->ddlist.action) res = ext->ddlist.action(roller); + if(ext->ddlist.action) ext->ddlist.action(roller); } else if(sign == LV_SIGNAL_RELEASED) { /*If picked an option by clicking then set it*/ if(!lv_indev_is_dragging(indev)) { @@ -432,13 +421,12 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, if(id < 0) id = 0; if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1; ext->ddlist.sel_opt_id = id; - ext->ddlist.sel_opt_id_ori = id; - if(ext->ddlist.action) res = ext->ddlist.action(roller); + if(ext->ddlist.action) ext->ddlist.action(roller); } } /*Position the scrollable according to the new selected option*/ - if(id != -1 && res == LV_RES_OK) { + if(id != -1) { refr_position(roller, true); } @@ -511,10 +499,8 @@ static void refr_position(lv_obj_t * roller, bool anim_en) #if USE_LV_ANIMATION == 0 anim_en = false; #endif - lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); - if(ext->ddlist.label == NULL) return; /*Probably the roller is being deleted if the label is NULL.*/ - lv_obj_t * roller_scrl = lv_page_get_scrl(roller); + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); const lv_font_t * font = style_label->text.font; lv_coord_t font_h = lv_font_get_height(font);