diff --git a/src/lv_widgets/lv_bar.c b/src/lv_widgets/lv_bar.c index acd90fdb2..efd53af91 100644 --- a/src/lv_widgets/lv_bar.c +++ b/src/lv_widgets/lv_bar.c @@ -737,6 +737,7 @@ static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_ anim_info->anim_start = anim_info->anim_end; anim_info->anim_end = new_value; } + *value_ptr = new_value; /* Stop the previous animation if it exists */ lv_anim_del(anim_info, NULL); diff --git a/src/lv_widgets/lv_switch.c b/src/lv_widgets/lv_switch.c index 9340f1efa..396ca8eb5 100644 --- a/src/lv_widgets/lv_switch.c +++ b/src/lv_widgets/lv_switch.c @@ -126,8 +126,8 @@ void lv_switch_on(lv_obj_t * sw, lv_anim_enable_t anim) #if LV_USE_ANIMATION == 0 anim = LV_ANIM_OFF; #endif - lv_switch_ext_t * ext = lv_obj_get_ext_attr(sw); - ext->state = 1; + if(lv_bar_get_value(sw) == 1) + return; lv_bar_set_value(sw, 1, anim); lv_obj_add_state(sw, LV_STATE_CHECKED); } @@ -144,8 +144,8 @@ void lv_switch_off(lv_obj_t * sw, lv_anim_enable_t anim) #if LV_USE_ANIMATION == 0 anim = LV_ANIM_OFF; #endif - lv_switch_ext_t * ext = lv_obj_get_ext_attr(sw); - ext->state = 0; + if(lv_bar_get_value(sw) == 0) + return; lv_bar_set_value(sw, 0, anim); lv_obj_clear_state(sw, LV_STATE_CHECKED); } diff --git a/src/lv_widgets/lv_switch.h b/src/lv_widgets/lv_switch.h index 609e44fcc..868951cc7 100644 --- a/src/lv_widgets/lv_switch.h +++ b/src/lv_widgets/lv_switch.h @@ -37,7 +37,6 @@ typedef struct { lv_bar_ext_t bar; /*Ext. of ancestor*/ /*New data for this type */ lv_style_list_t style_knob; /*Style of the knob*/ - uint8_t state : 1; /*The current state*/ } lv_switch_ext_t; /** @@ -112,8 +111,7 @@ static inline void lv_switch_set_anim_time(lv_obj_t * sw, uint16_t anim_time) */ static inline bool lv_switch_get_state(const lv_obj_t * sw) { - lv_switch_ext_t * ext = (lv_switch_ext_t *)lv_obj_get_ext_attr(sw); - return ext->state ? true : false; + return lv_bar_get_value(sw) == 1 ? true : false; } /**