Skip to content

Commit

Permalink
remove an animation only after it has displayed its last frame (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Oct 3, 2023
1 parent 632c446 commit 0d4b45c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ static bool animation_update(struct animation* animation, double time_scale) {
return false;
}

double slider = (animation->duration > 1
&& animation->counter < animation->duration)
? animation->interp_function(animation->counter
/ animation->duration)
: 1.0;
bool final_frame = !((animation->duration > 1
&& animation->counter < animation->duration));

double slider = final_frame
? 1.0
: animation->interp_function(animation->counter
/ animation->duration);

int value;
if (animation->separate_bytes) {
Expand Down Expand Up @@ -106,6 +108,7 @@ static bool animation_update(struct animation* animation, double time_scale) {

if (!found_item && needs_update) g_bar_manager.bar_needs_update = true;

animation->finished = final_frame;
return needs_update;
}

Expand Down Expand Up @@ -268,7 +271,7 @@ bool animator_update(struct animator* animator) {
needs_refresh |= animation_update(animator->animations[i],
animator->time_scale );

if (animator->animations[i]->counter > animator->animations[i]->duration) {
if (animator->animations[i]->finished) {
remove[remove_count++] = animator->animations[i];
}
}
Expand Down
1 change: 1 addition & 0 deletions src/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct animation {
bool separate_bytes;
bool as_float;
bool locked;
bool finished;

double duration;
double counter;
Expand Down

0 comments on commit 0d4b45c

Please sign in to comment.