1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

bar and sw anim fixes

This commit is contained in:
Gabor Kiss-Vamosi 2020-01-10 07:58:39 +01:00
parent 54e11bb835
commit f38c9c8faf
3 changed files with 12 additions and 28 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;