make style transitions smoother

This commit is contained in:
Gabor Kiss-Vamosi
2020-02-15 02:56:24 +01:00
parent b6388bc5ac
commit 6c1a96ce2d
2 changed files with 9 additions and 4 deletions

View File

@@ -1434,9 +1434,11 @@ void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state)
}
else {
#if LV_USE_ANIMATION
/* If there was an animation keep the previous state and
* move to the new from there*/
bool was_anim = lv_anim_del(obj, obj_state_anim_cb);
if(obj->state_dsc.anim == 0 && was_anim) {
if(was_anim) {
obj->state_dsc.act = new_state;
} else {
obj->state_dsc.prev = obj->state_dsc.act;
@@ -1444,10 +1446,14 @@ void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state)
obj->state_dsc.anim = 0;
}
/* Create (or recreate) the animation from where it was deleted.
* Calculate the remaining time proportionally too.*/
t = ((t - obj->state_dsc.anim) * t) / 255;
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, obj, obj_state_anim_cb);
lv_anim_set_values(&a, 0, 255);
lv_anim_set_values(&a, obj->state_dsc.anim, 255);
lv_anim_set_time(&a, t, 0);
lv_anim_create(&a);
#endif

View File

@@ -728,8 +728,7 @@ static void tabview_init(void)
lv_style_init(&tabview_btns);
lv_style_set_bg_opa(&tabview_btns, LV_STATE_PRESSED, LV_OPA_COVER);
lv_style_set_bg_color(&tabview_btns, LV_STATE_PRESSED, lv_color_hex(0x444444));
lv_style_set_text_color(&tabview_btns, LV_STATE_CHECKED, COLOR_ACCENT);
lv_style_set_text_color(&tabview_btns, LV_STATE_FOCUSED, LV_COLOR_RED);
lv_style_set_text_color(&tabview_btns, LV_STATE_CHECKED, LV_COLOR_WHITE);
lv_style_set_pad_top(&tabview_btns, LV_STATE_NORMAL, LV_DPI / 5);
lv_style_set_pad_bottom(&tabview_btns, LV_STATE_NORMAL, LV_DPI / 5);