From ebac219ba3c77c77d3cc8e8ee9358a36026f7ca3 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 9 Jun 2018 08:49:27 +0200 Subject: [PATCH 1/8] lv_txt_get_width: trim letter space of trailing non-printoble characters --- lv_misc/lv_txt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lv_misc/lv_txt.c b/lv_misc/lv_txt.c index d19c6365d..7e2c567a2 100644 --- a/lv_misc/lv_txt.c +++ b/lv_misc/lv_txt.c @@ -199,9 +199,12 @@ lv_coord_t lv_txt_get_width(const char * txt, uint16_t length, width += letter_space; } + + width -= letter_space; /*Trim the last letter space. Important if the text is center aligned */ + /*Trim closing spaces. Important when the text is aligned to the middle */ for(i = length - 1; i > 0; i--) { - if(txt[i] == ' ') { + if(txt[i] == ' ' || txt[i] == '\n' || txt[i] == '\r') { width -= lv_font_get_width(font, txt[i]); width -= letter_space; } else { From f6e054ba738681943e8960b8646ab768c6395bc1 Mon Sep 17 00:00:00 2001 From: Josh McAtee Date: Mon, 11 Jun 2018 16:00:30 -0700 Subject: [PATCH 2/8] Fix page focus not focusing objects the same way when moving up or down the page --- lv_objx/lv_page.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 2f0c0fcc9..518f64a53 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -303,9 +303,9 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, uint16_t anim_time) else if((obj_h <= page_h && bot_err > 0) || (obj_h > page_h && top_err >= bot_err)) { /*Calculate a new position and let some space below*/ - scrlable_y = -obj_y; - scrlable_y += page_h - obj_h; + scrlable_y = -(obj_y + style_scrl->body.padding.ver + style->body.padding.ver); scrlable_y -= style_scrl->body.padding.ver; + scrlable_y += page_h - obj_h; } else { /*Already in focus*/ return; From a30b117c607d24094acd50657cf2a4cd4fe7fe3b Mon Sep 17 00:00:00 2001 From: Josh McAtee Date: Mon, 11 Jun 2018 16:53:45 -0700 Subject: [PATCH 3/8] Small fix for bar/slider to make the fill more symmetric when near the min/max --- lv_objx/lv_bar.c | 8 ++++---- lv_objx/lv_slider.c | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lv_objx/lv_bar.c b/lv_objx/lv_bar.c index 1e938995c..1479ed1a4 100644 --- a/lv_objx/lv_bar.c +++ b/lv_objx/lv_bar.c @@ -291,11 +291,11 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode lv_coord_t h = lv_area_get_height(&indic_area); if(w >= h) { - indic_area.x2 = (int32_t) ((int32_t)w * (ext->cur_value - ext->min_value)) / (ext->max_value - ext->min_value); - indic_area.x2 = indic_area.x1 + indic_area.x2 - 1; + indic_area.x2 = (int32_t) ((int32_t)w * (ext->cur_value - ext->min_value - 1)) / (ext->max_value - ext->min_value); + indic_area.x2 = indic_area.x1 + indic_area.x2; } else { - indic_area.y1 = (int32_t) ((int32_t)h * (ext->cur_value - ext->min_value)) / (ext->max_value - ext->min_value); - indic_area.y1 = indic_area.y2 - indic_area.y1 + 1; + indic_area.y1 = (int32_t) ((int32_t)h * (ext->cur_value - ext->min_value - 1)) / (ext->max_value - ext->min_value); + indic_area.y1 = indic_area.y2 - indic_area.y1; } /*Draw the indicator*/ diff --git a/lv_objx/lv_slider.c b/lv_objx/lv_slider.c index ed188be25..9a9e93ad4 100644 --- a/lv_objx/lv_slider.c +++ b/lv_objx/lv_slider.c @@ -320,12 +320,12 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig if(ext->drag_value != LV_SLIDER_NOT_PRESSED) cur_value = ext->drag_value; if(slider_w >= slider_h) { - area_indic.x2 = (int32_t) ((int32_t)lv_area_get_width(&area_indic) * (cur_value - min_value)) / (max_value - min_value); - area_indic.x2 = area_indic.x1 + area_indic.x2 - 1; + area_indic.x2 = (int32_t) ((int32_t)(lv_area_get_width(&area_indic) - 1) * (cur_value - min_value)) / (max_value - min_value); + area_indic.x2 += area_indic.x1 + area_indic.x2; } else { - area_indic.y1 = (int32_t) ((int32_t)lv_area_get_height(&area_indic) * (cur_value - min_value)) / (max_value - min_value); - area_indic.y1 = area_indic.y2 - area_indic.y1 + 1; + area_indic.y1 = (int32_t) ((int32_t)(lv_area_get_height(&area_indic) - 1) * (cur_value - min_value)) / (max_value - min_value); + area_indic.y1 = area_indic.y2 - area_indic.y1; } if(cur_value != min_value) lv_draw_rect(&area_indic, mask, style_indic); @@ -339,7 +339,7 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig knob_area.x1 = area_indic.x2 - slider_h / 2; knob_area.x2 = knob_area.x1 + slider_h; } else { - knob_area.x1 = (int32_t) ((int32_t)(slider_w - slider_h) * (cur_value - min_value)) / (max_value - min_value); + knob_area.x1 = (int32_t) ((int32_t)(slider_w - slider_h - 1) * (cur_value - min_value)) / (max_value - min_value); knob_area.x1 += slider->coords.x1; knob_area.x2 = knob_area.x1 + slider_h; } @@ -351,7 +351,7 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig knob_area.y1 = area_indic.y1 - slider_w / 2; knob_area.y2 = knob_area.y1 + slider_w; } else { - knob_area.y2 = (int32_t) ((int32_t)(slider_h - slider_w) * (cur_value - min_value)) / (max_value - min_value); + knob_area.y2 = (int32_t) ((int32_t)(slider_h - slider_w - 1) * (cur_value - min_value)) / (max_value - min_value); knob_area.y2 = slider->coords.y2 - knob_area.y2; knob_area.y1 = knob_area.y2 - slider_w; } From 2a15cffbb9857a3127403b25138f16fec8664820 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 14 Jun 2018 11:17:49 +0200 Subject: [PATCH 4/8] lv_obj_del: remove from the group before delete the children (DEFOCUS might need children) --- lv_core/lv_obj.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lv_core/lv_obj.c b/lv_core/lv_obj.c index 806fb3003..e28679de9 100644 --- a/lv_core/lv_obj.c +++ b/lv_core/lv_obj.c @@ -265,6 +265,16 @@ lv_res_t lv_obj_del(lv_obj_t * obj) { lv_obj_invalidate(obj); + /*Delete from the group*/ + #if USE_LV_GROUP + if(obj->group_p != NULL) lv_group_remove_obj(obj); + #endif + + /*Remove the animations from this object*/ +#if USE_LV_ANIMATION + lv_anim_del(obj, NULL); +#endif + /*Recursively delete the children*/ lv_obj_t * i; lv_obj_t * i_next; @@ -272,32 +282,13 @@ lv_res_t lv_obj_del(lv_obj_t * obj) while(i != NULL) { /*Get the next object before delete this*/ i_next = lv_ll_get_next(&(obj->child_ll), i); - + /*Call the recursive del to the child too*/ delete_children(i); /*Set i to the next node*/ i = i_next; } -#if USE_LV_ANIMATION - /*Remove the animations from this object*/ - lv_anim_del(obj, NULL); -#endif - - /*Delete from the group*/ - #if USE_LV_GROUP - if(obj->group_p != NULL) lv_group_remove_obj(obj); - #endif - - /* Reset all input devices if - * the currently pressed object is deleted*/ - lv_indev_t * indev = lv_indev_next(NULL); - while(indev) { - if(indev->proc.act_obj == obj || indev->proc.last_obj == obj) { - lv_indev_reset(indev); - } - indev = lv_indev_next(indev); - } /*Remove the object from parent's children list*/ lv_obj_t * par = lv_obj_get_parent(obj); @@ -307,6 +298,16 @@ lv_res_t lv_obj_del(lv_obj_t * obj) lv_ll_rem(&(par->child_ll), obj); } + /* Reset all input devices if + * the currently pressed object is deleted*/ + lv_indev_t * indev = lv_indev_next(NULL); + while(indev) { + if(indev->proc.act_obj == obj || indev->proc.last_obj == obj) { + lv_indev_reset(indev); + } + indev = lv_indev_next(indev); + } + /* All children deleted. * Now clean up the object specific data*/ obj->signal_func(obj, LV_SIGNAL_CLEANUP, NULL); From 73c83cbd25b6d644c93f5dfb9cedbb36566c540f Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 14 Jun 2018 20:05:15 +0200 Subject: [PATCH 5/8] lv_ddlist: fix incorrect hegiht on style change --- lv_objx/lv_ddlist.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index fa48c3815..26e0a5578 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -681,6 +681,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); + 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 { #if USE_LV_ANIMATION lv_anim_t a; From 1cf5d5db9efd5feb6d525ec634696e86068cb786 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 14 Jun 2018 20:54:47 +0200 Subject: [PATCH 6/8] lv_theme_mono: add more line space to ddlist and roller --- lv_themes/lv_theme_mono.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lv_themes/lv_theme_mono.c b/lv_themes/lv_theme_mono.c index 4fc020381..b40e0bcb5 100644 --- a/lv_themes/lv_theme_mono.c +++ b/lv_themes/lv_theme_mono.c @@ -39,6 +39,7 @@ static lv_style_t dark_frame; static uint16_t _hue; static lv_font_t * _font; + /********************** * MACROS **********************/ @@ -345,9 +346,11 @@ static void list_init(void) static void ddlist_init(void) { #if USE_LV_DDLIST != 0 + static lv_style_t bg; + lv_style_copy(&bg, &light_frame); + bg.text.line_space = LV_DPI / 12; - - theme.ddlist.bg = &light_frame; + theme.ddlist.bg = &bg; theme.ddlist.sel = &dark_plain; theme.ddlist.sb = &dark_frame; #endif @@ -356,9 +359,11 @@ static void ddlist_init(void) static void roller_init(void) { #if USE_LV_ROLLER != 0 + static lv_style_t bg; + lv_style_copy(&bg, &light_frame); + bg.text.line_space = LV_DPI / 12; - - theme.roller.bg = &light_frame; + theme.roller.bg = &bg; theme.roller.sel = &dark_frame; #endif } From 31b3a2a3502bd55bd07173d6313535c3f8589405 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 16 Jun 2018 13:03:32 +0200 Subject: [PATCH 7/8] tabview: fix unwanted sending of tab change action on page click --- lv_objx/lv_tabview.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lv_objx/lv_tabview.c b/lv_objx/lv_tabview.c index 9841676a6..2591e5549 100644 --- a/lv_objx/lv_tabview.c +++ b/lv_objx/lv_tabview.c @@ -691,7 +691,7 @@ static void tabpage_press_lost_handler(lv_obj_t * tabview, lv_obj_t * tabpage) if(tab_cur < ext->tab_cnt - 1) tab_cur++; } - lv_tabview_set_tab_act(tabview, tab_cur, true); + if(tab_cur != ext->tab_cur) lv_tabview_set_tab_act(tabview, tab_cur, true); } /** From 4ac1c29ca917d14f1d8711f698949361f04956eb Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sun, 17 Jun 2018 16:43:28 +0200 Subject: [PATCH 8/8] lv_group_remove_obj: fix when delete the last object from the group --- lv_core/lv_group.c | 13 +++++++++++-- lv_core/lv_group.h | 2 +- lv_core/lv_indev.c | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index 16f365e71..53464e6cf 100644 --- a/lv_core/lv_group.c +++ b/lv_core/lv_group.c @@ -58,7 +58,7 @@ lv_group_t * lv_group_create(void) */ void lv_group_del(lv_group_t * group) { - /*Defocus the the currently focussed object*/ + /*Defocus the the currently focused object*/ if(group->obj_focus != NULL) { (*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL); lv_obj_invalidate(*group->obj_focus); @@ -81,6 +81,8 @@ void lv_group_del(lv_group_t * group) */ void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj) { + if(group == NULL) return; + obj->group_p = group; lv_obj_t ** next = lv_ll_ins_tail(&group->obj_ll); *next = obj; @@ -100,10 +102,17 @@ void lv_group_remove_obj(lv_obj_t * obj) { lv_group_t * g = obj->group_p; if(g == NULL) return; + if(g->obj_focus == NULL) return; /*Just to be sure (Not possible if there is at least one object in the group)*/ if(*g->obj_focus == obj) { lv_group_focus_next(g); - } + } + + /* If the focuses object is still the same then it was the only object in the group but it will be deleted. + * Set the `obj_focus` to NULL to get back to the initial state of the group with zero objects*/ + if(*g->obj_focus == obj) { + g->obj_focus = NULL; + } /*Search the object and remove it from its group */ lv_obj_t ** i; diff --git a/lv_core/lv_group.h b/lv_core/lv_group.h index f8ff0dc4e..c027bb9d0 100644 --- a/lv_core/lv_group.h +++ b/lv_core/lv_group.h @@ -45,7 +45,7 @@ typedef struct _lv_group_t { lv_ll_t obj_ll; /*Linked list to store the objects in the group */ lv_obj_t ** obj_focus; /*The object in focus*/ - lv_group_style_mod_func_t style_mod; /*A function which modifies the style of the focused object*/ + lv_group_style_mod_func_t style_mod; /*A function which modifies the style of the focused object*/ lv_group_focus_cb_t focus_cb; /*A function to call when a new object is focused (optional)*/ lv_style_t style_tmp; /*Stores the modified style of the focused object */ uint8_t frozen:1; /*1: can't focus to new object*/ diff --git a/lv_core/lv_indev.c b/lv_core/lv_indev.c index 6650b85f4..1cc9cdfe5 100644 --- a/lv_core/lv_indev.c +++ b/lv_core/lv_indev.c @@ -367,6 +367,8 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) lv_group_send_data(i->group, data->key); } + if(i->proc.reset_query) return; /*The object might be deleted in `focus_cb` or due to any other user event*/ + i->proc.pr_timestamp = 0; i->proc.long_pr_sent = 0; }