From d479927e96a7930d8a1799be42734940c7fde962 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Sat, 23 Mar 2019 09:20:41 -0400 Subject: [PATCH 1/2] Make ddlist more aesthetic --- src/lv_objx/lv_ddlist.c | 35 +++++++++++++++++++++++++++++++---- src/lv_objx/lv_ddlist.h | 1 + 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/lv_objx/lv_ddlist.c b/src/lv_objx/lv_ddlist.c index 205272aa8..07b494db9 100644 --- a/src/lv_objx/lv_ddlist.c +++ b/src/lv_objx/lv_ddlist.c @@ -44,6 +44,8 @@ static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * static lv_res_t release_handler(lv_obj_t * ddlist); static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en); static void lv_ddlist_pos_current_option(lv_obj_t * ddlist); +static void lv_ddlist_anim_cb(lv_obj_t * ddlist); +static void lv_ddlist_adjust_height(lv_obj_t * ddlist, int32_t height); /********************** * STATIC VARIABLES @@ -523,7 +525,7 @@ 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) { + if(ext->opened != 0 || ext->force_sel) { lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); const lv_font_t * font = style->text.font; lv_coord_t font_h = lv_font_get_height(font); @@ -548,7 +550,7 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_desig lv_opa_t opa_scale = lv_obj_get_opa_scale(ddlist); /*Redraw only in opened state*/ - if(ext->opened) { + if(ext->opened || ext->force_sel) { lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); const lv_font_t * font = style->text.font; lv_coord_t font_h = lv_font_get_height(font); @@ -859,9 +861,9 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en) a.var = ddlist; a.start = lv_obj_get_height(ddlist); a.end = new_height; - a.fp = (lv_anim_fp_t)lv_obj_set_height; + a.fp = (lv_anim_fp_t)lv_ddlist_adjust_height; a.path = lv_anim_path_linear; - a.end_cb = (lv_anim_cb_t)lv_ddlist_pos_current_option; + a.end_cb = (lv_anim_cb_t)lv_ddlist_anim_cb; a.act_time = 0; a.time = ext->anim_time; a.playback = 0; @@ -869,11 +871,36 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en) a.repeat = 0; a.repeat_pause = 0; + ext->force_sel = 1; /*Keep the list item selected*/ lv_anim_create(&a); #endif } } +/** + * Position the list and remove the selection highlight if it's closed. + * Called at end of list animation. + * @param ddlist pointer to a drop down list + */ +static void lv_ddlist_anim_cb(lv_obj_t * ddlist) { + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + lv_ddlist_pos_current_option(ddlist); + + ext->force_sel = 0; /*Turn off drawing of selection*/ +} + +/** + * Adjusts the ddlist's height and then positions the option within it's new height. + * This keeps the option visible during animation. + * @param ddlist Drop down list object + * @param height New drop down list height + */ +static void lv_ddlist_adjust_height(lv_obj_t * ddlist, int32_t height) { + lv_obj_set_height(ddlist, height); + lv_ddlist_pos_current_option(ddlist); +} + /** * Set the position of list when it is closed to show the selected item * @param ddlist pointer to a drop down list diff --git a/src/lv_objx/lv_ddlist.h b/src/lv_objx/lv_ddlist.h index 5a516a932..799df11e5 100644 --- a/src/lv_objx/lv_ddlist.h +++ b/src/lv_objx/lv_ddlist.h @@ -53,6 +53,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 force_sel :1; /*1: Keep the selection highlight even if the list is closed*/ uint8_t draw_arrow :1; /*1: Draw arrow*/ uint8_t stay_open :1; /*1: Don't close the list when a new item is selected*/ lv_coord_t fix_height; /*Height of the ddlist when opened. (0: auto-size)*/ From 13e7f162a05cc93632fb9992c8941d93a8fc4cb8 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sun, 24 Mar 2019 06:11:09 +0100 Subject: [PATCH 2/2] lv_ddlist: fixes for scrollbar visibility --- src/lv_objx/lv_ddlist.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lv_objx/lv_ddlist.c b/src/lv_objx/lv_ddlist.c index 07b494db9..ed1d7d8f8 100644 --- a/src/lv_objx/lv_ddlist.c +++ b/src/lv_objx/lv_ddlist.c @@ -841,7 +841,6 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en) style->body.padding.top + style->body.padding.bottom; else new_height = ext->fix_height; - lv_page_set_sb_mode(ddlist, LV_SB_MODE_UNHIDE); } else { /*Close the list*/ const lv_font_t * font = style->text.font; lv_style_t * label_style = lv_obj_get_style(ext->label); @@ -854,6 +853,7 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en) if(anim_en == 0) { lv_obj_set_height(ddlist, new_height); lv_ddlist_pos_current_option(ddlist); + if(ext->opened) lv_page_set_sb_mode(ddlist, LV_SB_MODE_UNHIDE); #if LV_USE_ANIMATION lv_anim_del(ddlist, (lv_anim_fp_t)lv_obj_set_height); /*If an animation is in progress then it will overwrite this changes*/ } else { @@ -888,6 +888,8 @@ static void lv_ddlist_anim_cb(lv_obj_t * ddlist) { lv_ddlist_pos_current_option(ddlist); ext->force_sel = 0; /*Turn off drawing of selection*/ + + if(ext->opened) lv_page_set_sb_mode(ddlist, LV_SB_MODE_UNHIDE); } /**