From da4115e652440151b3aa7a6bde79d46d6551bb03 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Thu, 5 Mar 2020 20:05:18 -0500 Subject: [PATCH 1/7] Do not build tests by default --- lvgl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/lvgl.h b/lvgl.h index f071833f2..07842034f 100644 --- a/lvgl.h +++ b/lvgl.h @@ -83,7 +83,6 @@ extern "C" { #define LVGL_VERSION_PATCH 0 #define LVGL_VERSION_INFO "dev" -#define LV_BUILD_TEST 1 /********************** * TYPEDEFS **********************/ From bcbcb6f31d1d7b72b8d5c4248f2619182734f95a Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Wed, 11 Mar 2020 03:30:56 -0700 Subject: [PATCH 2/7] Fixed lv_dropdown_add_option with default static options --- src/lv_widgets/lv_dropdown.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lv_widgets/lv_dropdown.c b/src/lv_widgets/lv_dropdown.c index de08fdd18..16226db41 100644 --- a/src/lv_widgets/lv_dropdown.c +++ b/src/lv_widgets/lv_dropdown.c @@ -262,8 +262,11 @@ void lv_dropdown_add_option(lv_obj_t * ddlist, const char * option, uint16_t pos lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); - /*Can not append to static options*/ - if(ext->static_txt != 0) return; + /*Clear any existing static options*/ + if(ext->static_txt != 0) { + ext->options = NULL; + ext->static_txt = 0; + } /*Allocate space for the new option*/ size_t old_len = (ext->options == NULL) ? 0 : strlen(ext->options); From d5ab09cf7f21b3dbd587c248abe4a65fe26dc927 Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Wed, 11 Mar 2020 03:36:25 -0700 Subject: [PATCH 3/7] Reset number of options when clearing static options --- src/lv_widgets/lv_dropdown.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lv_widgets/lv_dropdown.c b/src/lv_widgets/lv_dropdown.c index 16226db41..573c0f445 100644 --- a/src/lv_widgets/lv_dropdown.c +++ b/src/lv_widgets/lv_dropdown.c @@ -266,6 +266,7 @@ void lv_dropdown_add_option(lv_obj_t * ddlist, const char * option, uint16_t pos if(ext->static_txt != 0) { ext->options = NULL; ext->static_txt = 0; + ext->option_cnt = 0; } /*Allocate space for the new option*/ From e19ce6b451379d982f5b426799d68f1b5b25010d Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Wed, 11 Mar 2020 13:11:50 -0700 Subject: [PATCH 4/7] Added lv_dropdown_clear_options --- src/lv_widgets/lv_dropdown.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lv_widgets/lv_dropdown.h b/src/lv_widgets/lv_dropdown.h index 1bce0b32c..c6ada1a07 100644 --- a/src/lv_widgets/lv_dropdown.h +++ b/src/lv_widgets/lv_dropdown.h @@ -99,6 +99,12 @@ lv_obj_t * lv_dropdown_create(lv_obj_t * par, const lv_obj_t * copy); */ void lv_dropdown_set_text(lv_obj_t * ddlist, const char * txt); +/** + * Clear any options in a drop down list. Static or dynamic. + * @param ddlist pointer to drop down list object + */ +void lv_dropdown_clear_options(lv_obj_t * ddlist); + /** * Set the options in a drop down list from a string * @param ddlist pointer to drop down list object From f6b8a2f1b6788a5369b7104ad0f85a89bd9625c4 Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Wed, 11 Mar 2020 13:14:47 -0700 Subject: [PATCH 5/7] Added lv_dropdown_clear_options, convert options when adding --- src/lv_widgets/lv_dropdown.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/lv_widgets/lv_dropdown.c b/src/lv_widgets/lv_dropdown.c index 573c0f445..eb483483a 100644 --- a/src/lv_widgets/lv_dropdown.c +++ b/src/lv_widgets/lv_dropdown.c @@ -177,6 +177,26 @@ void lv_dropdown_set_text(lv_obj_t * ddlist, const char * txt) lv_obj_invalidate(ddlist); } +/** + * Clear any options in a drop down list. Static or dynamic. + * @param ddlist pointer to drop down list object + */ +void lv_dropdown_clear_options(lv_obj_t * ddlist) +{ + LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); + lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); + if(ext->options == NULL) return; + + if(ext->static_txt == 0) + lv_mem_free(ext->options); + + ext->options = NULL; + ext->static_txt = 0; + ext->option_cnt = 0; + + lv_obj_invalidate(ddlist); +} + /** * Set the options in a drop down list from a string * @param ddlist pointer to drop down list object @@ -262,11 +282,17 @@ void lv_dropdown_add_option(lv_obj_t * ddlist, const char * option, uint16_t pos lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); - /*Clear any existing static options*/ + /*Convert static options to dynmaic*/ if(ext->static_txt != 0) { - ext->options = NULL; + char * static_options = ext->options; + size_t len = strlen(static_options) + 1; + + ext->options = lv_mem_alloc(len); + LV_ASSERT_MEM(ext->options); + if(ext->options == NULL) return; + + strcpy(ext->options, static_options); ext->static_txt = 0; - ext->option_cnt = 0; } /*Allocate space for the new option*/ From d399dec0c76ffdb874ae60a073da290747d398eb Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Sat, 14 Mar 2020 15:57:35 -0400 Subject: [PATCH 6/7] Improve slider handling --- src/lv_widgets/lv_bar.c | 12 +++++++++++- src/lv_widgets/lv_slider.c | 30 +++++++++++++++++++----------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/lv_widgets/lv_bar.c b/src/lv_widgets/lv_bar.c index e5ef4d824..594e61a0a 100644 --- a/src/lv_widgets/lv_bar.c +++ b/src/lv_widgets/lv_bar.c @@ -406,6 +406,7 @@ static void draw_bg(lv_obj_t * bar, const lv_area_t * clip_area) static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) { lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + lv_bidi_dir_t base_dir = lv_obj_get_base_dir(bar); lv_coord_t objw = lv_obj_get_width(bar); lv_coord_t objh = lv_obj_get_height(bar); @@ -497,14 +498,23 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) anim_cur_value_x = (int32_t)((int32_t)anim_length * (ext->cur_value - ext->min_value)) / range; } + if(hor && base_dir == LV_BIDI_DIR_RTL) { + /* Swap axes */ + lv_coord_t * tmp; + tmp = axis1; + axis1 = axis2; + axis2 = tmp; + anim_cur_value_x = -anim_cur_value_x; + anim_start_value_x = -anim_start_value_x; + } /* Set the indicator length */ if(hor) { *axis2 = *axis1 + anim_cur_value_x; *axis1 += anim_start_value_x; } else { - *axis2 -= anim_start_value_x; *axis1 = *axis2 - anim_cur_value_x; + *axis2 -= anim_start_value_x; } if(sym) { lv_coord_t zero; diff --git a/src/lv_widgets/lv_slider.c b/src/lv_widgets/lv_slider.c index 4c4e6a603..abad580f7 100644 --- a/src/lv_widgets/lv_slider.c +++ b/src/lv_widgets/lv_slider.c @@ -23,6 +23,8 @@ *********************/ #define LV_OBJX_NAME "lv_slider" +#define LV_SLIDER_KNOB_COORD(hor, is_rtl, area) (hor ? (is_rtl ? area.x1 : area.x2) : (is_rtl ? area.y1 : area.y2)) + /********************** * TYPEDEFS **********************/ @@ -167,6 +169,7 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli ancestor_design_f(slider, clip_area, mode); lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); + lv_bidi_dir_t base_dir = lv_obj_get_base_dir(slider); lv_coord_t objw = lv_obj_get_width(slider); lv_coord_t objh = lv_obj_get_height(slider); @@ -180,14 +183,14 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli /*Horizontal*/ if(hor) { if(!sym) { - knob_area.x1 = ext->bar.indic_area.x2; + knob_area.x1 = LV_SLIDER_KNOB_COORD(hor, base_dir == LV_BIDI_DIR_RTL, ext->bar.indic_area); } else { if(ext->bar.cur_value >= 0) { - knob_area.x1 = ext->bar.indic_area.x2; + knob_area.x1 = LV_SLIDER_KNOB_COORD(hor, base_dir == LV_BIDI_DIR_RTL, ext->bar.indic_area); } else { - knob_area.x1 = ext->bar.indic_area.x1; + knob_area.x1 = LV_SLIDER_KNOB_COORD(hor, base_dir != LV_BIDI_DIR_RTL, ext->bar.indic_area); } } } @@ -213,10 +216,10 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli if(lv_slider_get_type(slider) == LV_SLIDER_TYPE_RANGE) { /* Draw a second knob for the start_value side */ if(hor) { - knob_area.x1 = ext->bar.indic_area.x1; + knob_area.x1 = LV_SLIDER_KNOB_COORD(hor, base_dir != LV_BIDI_DIR_RTL, ext->bar.indic_area); } else { - knob_area.y1 = ext->bar.indic_area.y1; + knob_area.y1 = ext->bar.indic_area.y2; } lv_slider_position_knob(slider, &knob_area, knob_size, hor); @@ -266,13 +269,14 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par else if(lv_slider_get_type(slider) == LV_SLIDER_TYPE_RANGE) { lv_indev_get_point(param, &p); bool hor = lv_obj_get_width(slider) >= lv_obj_get_height(slider); + lv_bidi_dir_t base_dir = lv_obj_get_base_dir(slider); lv_coord_t dist_left, dist_right; if(hor) { - if(p.x > ext->right_knob_area.x2) { + if((base_dir != LV_BIDI_DIR_RTL && p.x > ext->right_knob_area.x2) || (base_dir == LV_BIDI_DIR_RTL && p.x < ext->right_knob_area.x1)) { ext->value_to_set = &ext->bar.cur_value; } - else if(p.x < ext->left_knob_area.x1) { + else if((base_dir != LV_BIDI_DIR_RTL && p.x < ext->left_knob_area.x1) || (base_dir == LV_BIDI_DIR_RTL && p.x > ext->left_knob_area.x2)) { ext->value_to_set = &ext->bar.start_value; } else { @@ -306,14 +310,15 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par } else if(sign == LV_SIGNAL_PRESSING && ext->value_to_set != NULL) { lv_indev_get_point(param, &p); + lv_bidi_dir_t base_dir = lv_obj_get_base_dir(slider); lv_coord_t w = lv_obj_get_width(slider); lv_coord_t h = lv_obj_get_height(slider); lv_style_int_t bg_left = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG); - lv_style_int_t bg_right = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG); - lv_style_int_t bg_top = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG); - lv_style_int_t bg_bottom = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG); + lv_style_int_t bg_right = lv_obj_get_style_pad_right(slider, LV_SLIDER_PART_BG); + lv_style_int_t bg_top = lv_obj_get_style_pad_top(slider, LV_SLIDER_PART_BG); + lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(slider, LV_SLIDER_PART_BG); int32_t range = ext->bar.max_value - ext->bar.min_value; int16_t new_value = 0; @@ -322,7 +327,10 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par if(w >= h) { lv_coord_t indic_w = w - bg_left - bg_right; - new_value = p.x - (slider->coords.x1 + bg_left); /*Make the point relative to the indicator*/ + if(base_dir == LV_BIDI_DIR_RTL) + new_value = (slider->coords.x2 - bg_right) - p.x; /*Make the point relative to the indicator*/ + else + new_value = p.x - (slider->coords.x1 + bg_left); /*Make the point relative to the indicator*/ new_value = (new_value * range) / indic_w; new_value += ext->bar.min_value; } From 82d4c8d6ed813f63b638d8fc2ae4c299bc592c32 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Sat, 14 Mar 2020 16:16:33 -0400 Subject: [PATCH 7/7] lv_bar: fix #1406 (animation issue) --- src/lv_widgets/lv_bar.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/lv_widgets/lv_bar.c b/src/lv_widgets/lv_bar.c index 498a0973f..1816e1a93 100644 --- a/src/lv_widgets/lv_bar.c +++ b/src/lv_widgets/lv_bar.c @@ -470,8 +470,7 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) anim_start_value_x = (((anim_start_value_end_x - anim_start_value_start_x) * ext->start_value_anim.anim_state) / LV_BAR_ANIM_STATE_END); - if(anim_start_value_end_x < anim_start_value_start_x) - anim_start_value_x += anim_start_value_start_x; + anim_start_value_x += anim_start_value_start_x; } else #endif @@ -486,11 +485,8 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) lv_coord_t anim_cur_value_end_x = (int32_t)((int32_t)anim_length * (ext->cur_value_anim.anim_end - ext->min_value)) / range; - anim_cur_value_x = (((anim_cur_value_end_x - anim_cur_value_start_x) * ext->cur_value_anim.anim_state) / + anim_cur_value_x = anim_cur_value_start_x + (((anim_cur_value_end_x - anim_cur_value_start_x) * ext->cur_value_anim.anim_state) / LV_BAR_ANIM_STATE_END); - - if(anim_cur_value_end_x < anim_cur_value_start_x) - anim_cur_value_x += anim_cur_value_start_x; } else #endif @@ -507,6 +503,7 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) anim_cur_value_x = -anim_cur_value_x; anim_start_value_x = -anim_start_value_x; } + /* Set the indicator length */ if(hor) { *axis2 = *axis1 + anim_cur_value_x; @@ -729,8 +726,6 @@ static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_ lv_anim_set_ready_cb(&a, lv_bar_anim_ready); lv_anim_set_time(&a, ext->anim_time); lv_anim_start(&a); - - ext->cur_value = new_value; } }