[gnome-builder/wip/gtk4-port] libide/gui: add show/hide with fade API
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] libide/gui: add show/hide with fade API
- Date: Tue, 29 Mar 2022 18:51:20 +0000 (UTC)
commit 69e8be9f3a20c7a3b5861955ec58b336a86d95ce
Author: Christian Hergert <chergert redhat com>
Date: Tue Mar 29 11:50:47 2022 -0700
libide/gui: add show/hide with fade API
This is just a straitforward port of what we were using previously.
src/libide/gtk/ide-gtk.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++
src/libide/gtk/ide-gtk.h | 4 +++
2 files changed, 85 insertions(+)
---
diff --git a/src/libide/gtk/ide-gtk.c b/src/libide/gtk/ide-gtk.c
index 423441d55..34d68c73d 100644
--- a/src/libide/gtk/ide-gtk.c
+++ b/src/libide/gtk/ide-gtk.c
@@ -24,6 +24,7 @@
#include <libide-threading.h>
+#include "ide-animation.h"
#include "ide-gtk.h"
void
@@ -146,3 +147,83 @@ ide_gtk_progress_bar_start_pulsing (GtkProgressBar *progress)
g_object_set_data (G_OBJECT (progress), "PULSE_ID", GUINT_TO_POINTER (tick_id));
ide_gtk_progress_bar_tick_cb (progress);
}
+
+static void
+show_callback (gpointer data)
+{
+ g_object_set_data (data, "IDE_FADE_ANIMATION", NULL);
+ g_object_unref (data);
+}
+
+static void
+hide_callback (gpointer data)
+{
+ GtkWidget *widget = data;
+
+ g_object_set_data (data, "IDE_FADE_ANIMATION", NULL);
+ gtk_widget_hide (widget);
+ gtk_widget_set_opacity (widget, 1.0);
+ g_object_unref (widget);
+}
+
+void
+ide_gtk_widget_show_with_fade (GtkWidget *widget)
+{
+ GdkFrameClock *frame_clock;
+ IdeAnimation *anim;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ if (!gtk_widget_get_visible (widget))
+ {
+ anim = g_object_get_data (G_OBJECT (widget), "IDE_FADE_ANIMATION");
+ if (anim != NULL)
+ ide_animation_stop (anim);
+
+ frame_clock = gtk_widget_get_frame_clock (widget);
+ gtk_widget_set_opacity (widget, 0.0);
+ gtk_widget_show (widget);
+ anim = ide_object_animate_full (widget,
+ IDE_ANIMATION_LINEAR,
+ 500,
+ frame_clock,
+ show_callback,
+ g_object_ref (widget),
+ "opacity", 1.0,
+ NULL);
+ g_object_set_data_full (G_OBJECT (widget),
+ "IDE_FADE_ANIMATION",
+ g_object_ref (anim),
+ g_object_unref);
+ }
+}
+
+void
+ide_gtk_widget_hide_with_fade (GtkWidget *widget)
+{
+ GdkFrameClock *frame_clock;
+ IdeAnimation *anim;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ if (gtk_widget_get_visible (widget))
+ {
+ anim = g_object_get_data (G_OBJECT (widget), "IDE_FADE_ANIMATION");
+ if (anim != NULL)
+ ide_animation_stop (anim);
+
+ frame_clock = gtk_widget_get_frame_clock (widget);
+ anim = ide_object_animate_full (widget,
+ IDE_ANIMATION_LINEAR,
+ 1000,
+ frame_clock,
+ hide_callback,
+ g_object_ref (widget),
+ "opacity", 0.0,
+ NULL);
+ g_object_set_data_full (G_OBJECT (widget),
+ "IDE_FADE_ANIMATION",
+ g_object_ref (anim),
+ g_object_unref);
+ }
+}
diff --git a/src/libide/gtk/ide-gtk.h b/src/libide/gtk/ide-gtk.h
index 5e8d6557e..2632d9845 100644
--- a/src/libide/gtk/ide-gtk.h
+++ b/src/libide/gtk/ide-gtk.h
@@ -41,5 +41,9 @@ IDE_AVAILABLE_IN_ALL
void ide_gtk_progress_bar_start_pulsing (GtkProgressBar *progress);
IDE_AVAILABLE_IN_ALL
void ide_gtk_progress_bar_stop_pulsing (GtkProgressBar *progress);
+IDE_AVAILABLE_IN_ALL
+void ide_gtk_widget_show_with_fade (GtkWidget *widget);
+IDE_AVAILABLE_IN_ALL
+void ide_gtk_widget_hide_with_fade (GtkWidget *widget);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]