From d950ae0ee41ab4caf61dcd5a1ffe9dc3d04d34b0 Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Fri, 22 Sep 2017 23:54:31 +0200 Subject: [PATCH 1/5] lv_obj_set_style refresh NULL styles behind glass styles --- lv_obj/lv_obj.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index 0b9bf896b..8f4e682f1 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -1526,13 +1526,14 @@ static void lv_child_refr_style(lv_obj_t * obj) lv_obj_t * child = lv_obj_get_child(obj, NULL); while(child != NULL) { if(child->style_p == NULL) { + lv_child_refr_style(child); /*Check children too*/ + lv_obj_refr_style(obj); /*Send a style change signal to the object*/ + } else if(child->style_p->glass) { + /*Children with 'glass' parent might be effected if their style == NULL*/ lv_child_refr_style(child); } - child = lv_obj_get_child(obj, child); + child = lv_obj_get_child(child, NULL); } - - /*Send a style change signal to the object*/ - lv_obj_refr_style(obj); } /** From 4935b885881de2cfaf0481823bf394abfc6fe37b Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Fri, 22 Sep 2017 23:55:03 +0200 Subject: [PATCH 2/5] lv_objx_templ: minor update in comments --- lv_objx/lv_objx_templ.c | 7 ++++--- lv_objx/lv_objx_templ.h | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lv_objx/lv_objx_templ.c b/lv_objx/lv_objx_templ.c index 71ad75fd1..36c2a5667 100644 --- a/lv_objx/lv_objx_templ.c +++ b/lv_objx/lv_objx_templ.c @@ -3,9 +3,10 @@ * */ -/*Search an replace: template -> object normal name with lower case (e.g. button, label etc.) - * templ -> object short name with lower case(e.g. btn, label etc) - * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) +/* TODO Remove these instructions + * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) + * templ -> object short name with lower case(e.g. btn, label etc) + * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) * */ diff --git a/lv_objx/lv_objx_templ.h b/lv_objx/lv_objx_templ.h index 63cd55447..174dc4fcb 100644 --- a/lv_objx/lv_objx_templ.h +++ b/lv_objx/lv_objx_templ.h @@ -4,9 +4,10 @@ */ -/*Search an replace: template -> object normal name with lower case (e.g. button, label etc.) - * templ -> object short name with lower case(e.g. btn, label etc) - * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) +/* TODO Remove these instructions + * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) + * templ -> object short name with lower case(e.g. btn, label etc) + * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) * */ From 280e039e1960c1fd3e1f9444f66ff00d8c58f0ca Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Fri, 22 Sep 2017 23:55:42 +0200 Subject: [PATCH 3/5] lv_ddlist: change auto_size to fix_height --- lv_objx/lv_ddlist.c | 39 +++++++++++++++++---------------------- lv_objx/lv_ddlist.h | 17 +++++++++-------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index b05d17038..a34eab7e4 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -69,7 +69,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) ext->opt_label = NULL; ext->cb = NULL; ext->opened = 0; - ext->auto_size = 0; + ext->fix_height = 0; ext->sel_opt = 0; ext->num_opt = 0; ext->anim_time = LV_DDLIST_DEF_ANIM_TIME; @@ -85,7 +85,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) if(copy == NULL) { lv_obj_t * scrl = lv_page_get_scrl(new_ddlist); lv_obj_set_drag(scrl, false); - lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL));; + lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL)); lv_cont_set_fit(scrl, true, true); ext->opt_label = lv_label_create(new_ddlist, NULL); @@ -101,7 +101,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) ext->opt_label = lv_label_create(new_ddlist, copy_ext->opt_label); lv_label_set_text(ext->opt_label, lv_label_get_text(copy_ext->opt_label)); ext->sel_opt = copy_ext->sel_opt; - ext->auto_size = copy_ext->auto_size; + ext->fix_height = copy_ext->fix_height; ext->cb = copy_ext->cb; ext->num_opt = copy_ext->num_opt; @@ -130,8 +130,6 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param) * make the object specific signal handling */ if(valid != false) { if(sign == LV_SIGNAL_STYLE_CHG) { - lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); - lv_obj_set_style(ext->opt_label, lv_obj_get_style(ddlist)); lv_ddlist_refr_size(ddlist, 0); } else if(sign == LV_SIGNAL_FOCUS) { lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); @@ -256,15 +254,16 @@ void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t cb) } /** - * Set the auto size attribute. If enabled the height will reduced to be visible on the parent. - * In this case the drop down list can be scrolled. + * Set the fix height value. + * If 0 then the opened ddlist will be auto. sized else the set height will be applied. * @param ddlist pointer to a drop down list - * @param auto_size true: enable auto size, false: disable + * @param h the height when the list is opened (0: auto size) */ -void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size) +void lv_ddlist_set_fix_height(lv_obj_t * ddlist, cord_t h) { lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); - ext->auto_size = auto_size == false ? 0 : 1; + ext->fix_height = h; + lv_ddlist_refr_size(ddlist, 0); } /** @@ -356,14 +355,14 @@ void lv_ddlist_get_selected_str(lv_obj_t * ddlist, char * buf) } /** - * Get the auto size attribute. + * Get the fix height value. * @param ddlist pointer to a drop down list object - * @return true: the auto_size is enabled, false: disabled + * @return the height if the ddlist is opened (0: auto size) */ -bool lv_ddlist_get_auto_size(lv_obj_t * ddlist, bool auto_size) +cord_t lv_ddlist_get_fix_height(lv_obj_t * ddlist) { lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); - return ext->auto_size == 0 ? false : true; + return ext->fix_height; } /** @@ -484,7 +483,7 @@ static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist, lv_dispi_t * disp } /** - * Refresh the size of drop down list according its status (open or closed) + * Refresh the size of drop down list according to its status (open or closed) * @param ddlist pointer to a drop down list object * @param anim_time animations time for open/close [ms] */ @@ -493,13 +492,9 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, uint16_t anim_time) lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); lv_style_t * style = lv_obj_get_style(ddlist); cord_t new_height; - if(ext->opened != 0) { /*Open the list*/ - new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad; - lv_obj_t * parent = lv_obj_get_parent(ddlist); - /*Reduce the height if enabled and required*/ - if(ext->auto_size != 0 && new_height + ddlist->cords.y1 > parent->cords.y2) { - new_height = parent->cords.y2 - ddlist->cords.y1; - } + if(ext->opened) { /*Open the list*/ + if(ext->fix_height == 0) new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad; + else new_height = ext->fix_height; } else { /*Close the list*/ const font_t * font = style->font; lv_style_t * label_style = lv_obj_get_style(ext->opt_label); diff --git a/lv_objx/lv_ddlist.h b/lv_objx/lv_ddlist.h index 18ec4930d..018548b3c 100644 --- a/lv_objx/lv_ddlist.h +++ b/lv_objx/lv_ddlist.h @@ -48,7 +48,7 @@ typedef struct uint16_t sel_opt; /*Index of the current option*/ uint16_t anim_time; /*Open/Close animation time [ms]*/ uint8_t opened :1; /*1: The list is opened*/ - uint8_t auto_size :1; /*1: Set height to show all options. 0: Set height maximum to the parent bottom*/ + cord_t fix_height; /*Height if the ddlist is opened. (0: auto-size)*/ }lv_ddlist_ext_t; @@ -99,12 +99,12 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt); void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t cb); /** - * Set the auto size attribute. If enabled the height will reduced to be visible on the parent. - * In this case the drop down list can be scrolled. + * Set the fix height value. + * If 0 then the opened ddlist will be auto. sized else the set height will be applied. * @param ddlist pointer to a drop down list - * @param auto_size true: enable auto size, false: disable + * @param h the height when the list is opened (0: auto size) */ -void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size); +void lv_ddlist_set_fix_height(lv_obj_t * ddlist, cord_t h); /** * Set the style of the rectangle on the selected option @@ -142,12 +142,13 @@ uint16_t lv_ddlist_get_selected(lv_obj_t * ddlist); */ void lv_ddlist_get_selected_str(lv_obj_t * ddlist, char * buf); + /** - * Get the auto size attribute. + * Get the fix height value. * @param ddlist pointer to a drop down list object - * @return true: the auto_size is enabled, false: disabled + * @return the height if the ddlist is opened (0: auto size) */ -bool lv_ddlist_get_auto_size(lv_obj_t * ddlist, bool auto_size); +cord_t lv_ddlist_get_fix_height(lv_obj_t * ddlist); /** * Get the style of the rectangle on the selected option From b557331d63bb6772c77d8e2e7f9402699a1bda9c Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Fri, 22 Sep 2017 23:55:54 +0200 Subject: [PATCH 4/5] lv_roller updates --- lv_objx/lv_roller.c | 88 +++++++++++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 23 deletions(-) diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index e25a8c3ef..fc1aaf56e 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -52,8 +52,7 @@ static lv_signal_f_t ancestor_scr_signal_f; lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor of roller*/ - /*TODO modify it to the ancestor create function */ - lv_obj_t * new_roller = lv_ddlist_create(par, copy); + lv_obj_t * new_roller = lv_ddlist_create(par, copy); dm_assert(new_roller); /*Allocate the roller type specific extended data*/ @@ -71,20 +70,16 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new roller roller*/ if(copy == NULL) { lv_obj_t * scrl = lv_page_get_scrl(new_roller); - lv_obj_set_drag(scrl, true); - lv_page_set_rel_action(new_roller, NULL); + lv_obj_set_drag(scrl, true); /*In ddlist is might be disabled*/ + lv_page_set_rel_action(new_roller, NULL); /*Handle roller specific actions*/ + lv_cont_set_fit(lv_page_get_scrl(new_roller), true, false); /*Height is specified directly*/ lv_obj_set_signal_f(scrl, roller_scrl_signal); - // lv_ddlist_open(new_roller, true, false); - lv_obj_set_style(new_roller, lv_style_get(LV_STYLE_PRETTY, NULL)); - lv_cont_set_fit(lv_page_get_scrl(new_roller), true, false); - lv_ddlist_set_options_str(new_roller, "alma\nkorte\ncitrom\nbanan\neper\ndinnye"); + lv_ddlist_open(new_roller, true, 0); lv_style_t * style_label = lv_obj_get_style(ext->ddlist.opt_label); - lv_obj_set_height(new_roller, (font_get_height(style_label->font) >> FONT_ANTIALIAS) * 3 + style_label->line_space * 4); - - lv_obj_set_height(lv_page_get_scrl(new_roller), lv_obj_get_height(ext->ddlist.opt_label) + lv_obj_get_height(new_roller)); - lv_obj_align(ext->ddlist.opt_label, NULL, LV_ALIGN_CENTER, 0, 0); - + lv_ddlist_set_fix_height(new_roller, (font_get_height(style_label->font) >> FONT_ANTIALIAS) * 3 + + style_label->line_space * 4); + lv_obj_refr_style(new_roller); /*To set scrollable size automatically*/ } /*Copy an existing roller*/ else { @@ -109,15 +104,24 @@ bool lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param) bool valid; /* Include the ancient signal function */ - /* TODO update it to the ancestor's signal function*/ valid = lv_ddlist_signal(roller, sign, param); /* The object can be deleted so check its validity and then * make the object specific signal handling */ if(valid != false) { - if(sign == LV_SIGNAL_CLEANUP) { - /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ - } + lv_roller_ext_t * ext = lv_obj_get_ext(roller); + if(sign == LV_SIGNAL_STYLE_CHG) { + lv_obj_set_height(lv_page_get_scrl(roller), + lv_obj_get_height(ext->ddlist.opt_label) + lv_obj_get_height(roller)); + lv_obj_align(ext->ddlist.opt_label, NULL, LV_ALIGN_CENTER, 0, 0); + lv_ddlist_set_selected(roller, ext->ddlist.sel_opt); + } else if(sign == LV_SIGNAL_CORD_CHG) { + lv_ddlist_set_fix_height(roller, lv_obj_get_height(roller)); + lv_obj_set_height(lv_page_get_scrl(roller), + lv_obj_get_height(ext->ddlist.opt_label) + lv_obj_get_height(roller)); + lv_obj_align(ext->ddlist.opt_label, NULL, LV_ALIGN_CENTER, 0, 0); + lv_ddlist_set_selected(roller, ext->ddlist.sel_opt); + } } return valid; @@ -188,7 +192,6 @@ static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_m cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; area_t rect_area; rect_area.y1 = roller->cords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->line_space - 2; - rect_area.y2 = rect_area.y1 + font_h + style->line_space; rect_area.x1 = ext->ddlist.opt_label->cords.x1 - style->hpad; rect_area.x2 = rect_area.x1 + lv_obj_get_width(lv_page_get_scrl(roller)); @@ -215,17 +218,56 @@ bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) * make the object specific signal handling */ if(valid != false) { if(sign == LV_SIGNAL_RELEASED) { + int32_t id; lv_obj_t * roller = lv_obj_get_parent(roller_scrl); lv_roller_ext_t * ext = lv_obj_get_ext(roller); lv_style_t * style_label = lv_obj_get_style(ext->ddlist.opt_label); + const font_t * font = style_label->font; + cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; - cord_t label_y1 = ext->ddlist.page.scrl->cords.y1 - roller->cords.y1; - cord_t label_unit = (font_get_height(style_label->font) >> FONT_ANTIALIAS) + style_label->line_space / 2; - cord_t mid = (roller->cords.y2 - roller->cords.y1) / 2; + if(lv_dispi_is_dragging(param)) { - int32_t id = (mid - label_y1) / label_unit; + cord_t label_y1 = ext->ddlist.opt_label->cords.y1 - roller->cords.y1; + cord_t label_unit = (font_get_height(style_label->font) >> FONT_ANTIALIAS) + style_label->line_space / 2; + cord_t mid = (roller->cords.y2 - roller->cords.y1) / 2; - printf("roller diff: %d , unit: %d, id: %d\n", mid-label_y1, label_unit, id); + id = (mid - label_y1) / label_unit; + + printf("roller diff: %d , unit: %d, id: %d\n", mid-label_y1, label_unit, id); + } else { + point_t p; + lv_dispi_get_point(param, &p); + p.y = p.y - ext->ddlist.opt_label->cords.y1; + printf("y: %d\n", p.y); + id = p.y / (font_h + style_label->line_space); + } + if(id < 0) id = 0; + if(id >= ext->ddlist.num_opt) id = ext->ddlist.num_opt - 1; + ext->ddlist.sel_opt = id; + + + cord_t h = lv_obj_get_height(roller); + cord_t line_y1 = id * (font_h + style_label->line_space) + ext->ddlist.opt_label->cords.y1 - roller_scrl->cords.y1; + cord_t new_y = - line_y1 + (h - font_h) / 2; + + if(ext->ddlist.anim_time == 0) { + lv_obj_set_y(roller_scrl, new_y); + } else { + anim_t a; + a.var = roller_scrl; + a.start = lv_obj_get_y(roller_scrl); + a.end = new_y; + a.fp = (anim_fp_t)lv_obj_set_y; + a.path = anim_get_path(ANIM_PATH_LIN); + a.end_cb = NULL; + a.act_time = 0; + a.time = ext->ddlist.anim_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + anim_create(&a); + } } } From af11110e0fcd426d8220a21c171cc922c06c7cd8 Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Sat, 23 Sep 2017 22:14:31 +0200 Subject: [PATCH 5/5] lv_roller: comments added --- lv_objx/lv_roller.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index fc1aaf56e..7897724fc 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -206,8 +206,14 @@ static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_m return true; } - -bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) +/** + * Signal function of the scrollable part of the roller. + * @param roller_scrl ointer to the scrollable part of roller (page) + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +static bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) { bool valid; @@ -225,27 +231,25 @@ bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) const font_t * font = style_label->font; cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; + /*If dragged then align the list to there be an element in the middle*/ if(lv_dispi_is_dragging(param)) { - cord_t label_y1 = ext->ddlist.opt_label->cords.y1 - roller->cords.y1; cord_t label_unit = (font_get_height(style_label->font) >> FONT_ANTIALIAS) + style_label->line_space / 2; cord_t mid = (roller->cords.y2 - roller->cords.y1) / 2; - id = (mid - label_y1) / label_unit; - - printf("roller diff: %d , unit: %d, id: %d\n", mid-label_y1, label_unit, id); - } else { + } + /*If pick an option by clicking then set it*/ + else { point_t p; lv_dispi_get_point(param, &p); p.y = p.y - ext->ddlist.opt_label->cords.y1; - printf("y: %d\n", p.y); id = p.y / (font_h + style_label->line_space); } if(id < 0) id = 0; if(id >= ext->ddlist.num_opt) id = ext->ddlist.num_opt - 1; ext->ddlist.sel_opt = id; - + /*Position the scrollable according to the new selected option*/ cord_t h = lv_obj_get_height(roller); cord_t line_y1 = id * (font_h + style_label->line_space) + ext->ddlist.opt_label->cords.y1 - roller_scrl->cords.y1; cord_t new_y = - line_y1 + (h - font_h) / 2;