Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec_cb and custom_exec_cb are unexpectedly executed in the animation timeline. #7418

Open
amk3y opened this issue Dec 5, 2024 · 2 comments

Comments

@amk3y
Copy link

amk3y commented Dec 5, 2024

LVGL version

v9.2.2

Platform

Board: ESP32-C3 Super Mini (esp32-c3-devkitm-1)
Framework: esp-idf v5.3.1

IDE: Clion 2024.3 + PlatformIO
Build Machine: macOS 15.1.1 arm64

What happened?

I created a timeline with two animations that perform a fade-in and fade-out of an image.
However, I found that the first animation (the fade-in) is skipped.

So, I added a line to exec_cb to print the value of the animations.

void anim_cb_set_opa(lv_anim_t* anim, int32_t value){
    ESP_LOGI("anim", "value: %lu", value);
    lv_obj_set_style_image_opa(anim->var, value, 0);
}

Then I noticed that the exec_cb and custom_exec_cb of every animation in a timeline are executed even if the animation has not started or has already ended.
(the fade-out animation overrides the fade-in animation in this case)
image

I tried to comment out these lines in anim_timeline_set_act_time

        if(act_time < start_time && a->early_apply) {
            //...
            //if(a->exec_cb) a->exec_cb(a->var, value);
            //if(a->custom_exec_cb) a->custom_exec_cb(a, value);
            //...
        }
        else if(act_time >= start_time && act_time <= (start_time + a->duration)) {
            //...
            if(a->exec_cb) a->exec_cb(a->var, value);
            if(a->custom_exec_cb) a->custom_exec_cb(a, value);
            //...
        } 
        else if(act_time > start_time + a->duration) {
            //...
            //if(a->exec_cb) a->exec_cb(a->var, value);
            //if(a->custom_exec_cb) a->custom_exec_cb(a, value);
            //...
        }

Then this modification got my animations to work.
image

But I am not sure if it broke anything. Could you take a look at it?

How to reproduce?

Full Code: https://github.com/amk3y/lvgl_gif_lab/blob/main/src/main.c

void anim_cb_set_opa(lv_anim_t* anim, int32_t value){
    lv_obj_set_style_image_opa(anim->var, value, 0);
}

void enter_lvgl_scene(void){
    LV_IMAGE_DECLARE(image_logo);

    lv_obj_t* lv_image_logo = lv_image_create(lv_screen_active());
    lv_obj_set_style_image_opa(lv_image_logo, LV_OPA_TRANSP, 0);
    lv_image_set_src(lv_image_logo, &image_logo);
    lv_obj_align(lv_image_logo, LV_ALIGN_CENTER, 0, 0);

    lv_anim_t intro_fade_in_anim;
    lv_anim_init(&intro_fade_in_anim);
    lv_anim_set_duration(&intro_fade_in_anim, 1000);
    lv_anim_set_var(&intro_fade_in_anim, lv_image_logo);
    lv_anim_set_values(&intro_fade_in_anim,0, 255);
    lv_anim_set_path_cb(&intro_fade_in_anim, lv_anim_path_ease_in_out);
    lv_anim_set_custom_exec_cb(&intro_fade_in_anim, anim_cb_set_opa);

    lv_anim_t intro_fade_out_anim;
    lv_anim_init(&intro_fade_out_anim);
    lv_anim_set_duration(&intro_fade_out_anim, 1000);
    lv_anim_set_var(&intro_fade_out_anim, lv_image_logo);
    lv_anim_set_values(&intro_fade_out_anim,255, 0);
    lv_anim_set_path_cb(&intro_fade_out_anim, lv_anim_path_ease_in_out);
    lv_anim_set_custom_exec_cb(&intro_fade_out_anim, anim_cb_set_opa);

    lv_anim_timeline_t* timeline = lv_anim_timeline_create();
    lv_anim_timeline_add(timeline, 10, &intro_fade_in_anim);
    lv_anim_timeline_add(timeline, 2000, &intro_fade_out_anim);

    lv_anim_timeline_start(timeline);
}

void app_main() {
  // ...
  enter_lvgl_scene();
  // ...
}
@kisvegabor
Copy link
Member

Sorry for the late reply. The problem is that you need to add
lv_anim_set_early_apply(&intro_fade_out_anim, false);

By default the animations have early_apply=true to apply the start value when they start even if there is a delay. In your case both animations had early_apply=true so the first set opa=0, then it was overwritten by opa=255.

We definitely need to document it in a clean way. cc @vwheeler63

@vwheeler63
Copy link
Contributor

We definitely need to document it in a clean way.

Agreed! Added to list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants