diff options
| author | Federico Angelilli <code@fedang.net> | 2024-03-17 15:20:03 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-03-17 15:20:03 +0100 |
| commit | 44a9ccb0ca18314016ef10b4b1b1c7c958d9eabc (patch) | |
| tree | 459cb397c045685a0fca59b1edf849965888f52f /src/animate.c | |
| parent | 6e6992ec09edf79ef2cdcaf249e31809cf7d3145 (diff) | |
Add group grow animation
Diffstat (limited to 'src/animate.c')
| -rw-r--r-- | src/animate.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/animate.c b/src/animate.c index 313cfa7..387c9b8 100644 --- a/src/animate.c +++ b/src/animate.c @@ -179,6 +179,41 @@ Animation *animation_group_shrink_create(gint64 duration) return shrink; } +static bool grow_func(Animation *grow, Layout *layout) +{ + g_assert_false(layout->btn->simple); + ButtonGroup *group = (gpointer)layout->btn; + + gint64 end = grow->start + grow->duration; + gint64 now = g_get_monotonic_time(); + if (now > end) return false; + + double t = (double)(now - grow->start) / (end - grow->start); + double pos = smoothstep(t, 0, 1); + + int start_w = CAST(layout->children->data, Layout)->width; + int width = start_w + pos * (layout->width - start_w); + layout->width = width; + + for (GList *it = layout->children, *next = it->next; it; it = next, next = it ? it->next : NULL) { + Layout *child = it->data; + if (child->x + child->width > layout->x + width) + layout->children = g_list_delete_link(layout->children, it); + } + + return true; +} + +Animation *animation_group_grow_create(gint64 duration) +{ + // Note the 0 initialization + Animation *grow = g_malloc0(sizeof(Animation)); + grow->type = ANIM_GROUP_GROW; + grow->layout_func = (LayoutFunc)grow_func; + grow->duration = duration; + return grow; +} + void animation_destroy(Animation *anim) { if (anim == NULL) return; |
