From 44a9ccb0ca18314016ef10b4b1b1c7c958d9eabc Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Sun, 17 Mar 2024 15:20:03 +0100 Subject: Add group grow animation --- src/animate.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/animate.c') 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; -- cgit v1.2.3