From f38c9c8faf4a68172eb2dc199aaf2d81eb3b986b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 10 Jan 2020 07:58:39 +0100 Subject: [PATCH] bar and sw anim fixes --- src/lv_objx/lv_bar.c | 6 ++++-- src/lv_objx/lv_sw.c | 33 ++++++++------------------------- src/lv_objx/lv_sw.h | 1 - 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/lv_objx/lv_bar.c b/src/lv_objx/lv_bar.c index 4bb678cae..aa661ff3a 100644 --- a/src/lv_objx/lv_bar.c +++ b/src/lv_objx/lv_bar.c @@ -270,7 +270,7 @@ int16_t lv_bar_get_value(const lv_obj_t * bar) LV_ASSERT_OBJ(bar, LV_OBJX_NAME); lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - + return ext->cur_value; return LV_BAR_GET_ANIM_VALUE(ext->cur_value, ext->cur_value_anim); } @@ -465,7 +465,7 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) anim_cur_value_x = (((anim_cur_value_end_x - anim_cur_value_start_x) * ext->cur_value_anim.anim_state) >> LV_BAR_ANIM_STATE_NORM); - if(anim_cur_value_x < 0) +// if(anim_cur_value_x < 0) anim_cur_value_x += anim_cur_value_start_x; } else #endif @@ -685,6 +685,8 @@ static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_ a.repeat_pause = 0; lv_anim_create(&a); + + ext->cur_value = new_value; } } diff --git a/src/lv_objx/lv_sw.c b/src/lv_objx/lv_sw.c index d30740398..a1efd4183 100644 --- a/src/lv_objx/lv_sw.c +++ b/src/lv_objx/lv_sw.c @@ -76,9 +76,6 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy) return NULL; } - /*Initialize the allocated 'ext' */ - ext->changed = 0; - /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_cb(new_sw, lv_sw_signal); @@ -204,32 +201,18 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param) lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); /* Include the ancient signal function */ - res = ancestor_signal(sw, sign, param); - if(res != LV_RES_OK) return res; + if(sign != LV_SIGNAL_PRESSED && + sign != LV_SIGNAL_PRESSING && + sign != LV_SIGNAL_RELEASED) { + res = ancestor_signal(sw, sign, param); + if(res != LV_RES_OK) return res; + } if(sign == LV_SIGNAL_CLEANUP) { /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ - } else if(sign == LV_SIGNAL_PRESSED) { - ext->changed = 0; - } else if(sign == LV_SIGNAL_PRESSING) { - if(ext->state != ext->slider.bar.cur_value) ext->changed = 1; - } else if(sign == LV_SIGNAL_PRESS_LOST) { - if(lv_sw_get_state(sw)) lv_sw_on(sw, LV_ANIM_ON); - else lv_sw_off(sw, LV_ANIM_ON); } else if(sign == LV_SIGNAL_RELEASED) { - /*If not dragged then toggle the switch*/ - if(ext->changed == 0) { - if(lv_sw_get_state(sw)) { - lv_sw_off(sw, LV_ANIM_ON); - } else { - lv_sw_on(sw, LV_ANIM_ON); - } - } - /*If the switch was dragged then calculate the new state based on the current position*/ - else { - if(ext->slider.bar.cur_value != 0) lv_sw_on(sw, LV_ANIM_ON); - else lv_sw_off(sw, LV_ANIM_ON); - } + if(lv_sw_get_state(sw)) lv_sw_off(sw, LV_ANIM_ON); + else lv_sw_on(sw, LV_ANIM_ON); res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; diff --git a/src/lv_objx/lv_sw.h b/src/lv_objx/lv_sw.h index a50184463..e3f7b735a 100644 --- a/src/lv_objx/lv_sw.h +++ b/src/lv_objx/lv_sw.h @@ -37,7 +37,6 @@ typedef struct { lv_slider_ext_t slider; /*Ext. of ancestor*/ /*New data for this type */ - uint8_t changed :1; /*Indicates the switch state explicitly changed by drag*/ uint8_t state :1; /*The current state*/ } lv_sw_ext_t;