[libdazzle] progress-menu-button: suppress theatrics until ack



commit 6e1dcbd0c67344b53aefa2a6331d93026f06baa6
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 9 21:22:57 2017 -0700

    progress-menu-button: suppress theatrics until ack
    
    Do not animate multiple times unless the caller as ack'd the previous
    animation. This is helpful to avoid suprious animations if the binding
    for progress activates 1.0 too often.

 src/widgets/dzl-progress-menu-button.c |   26 +++++++++++++++++++++++++-
 src/widgets/dzl-progress-menu-button.h |    1 +
 2 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/src/widgets/dzl-progress-menu-button.c b/src/widgets/dzl-progress-menu-button.c
index e37f4c0..4a37913 100644
--- a/src/widgets/dzl-progress-menu-button.c
+++ b/src/widgets/dzl-progress-menu-button.c
@@ -31,6 +31,7 @@ typedef struct
   gdouble          progress;
   guint            transition_duration;
   guint            show_theatric : 1;
+  guint            suppress_theatric : 1;
 } DzlProgressMenuButtonPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (DzlProgressMenuButton, dzl_progress_menu_button, GTK_TYPE_MENU_BUTTON)
@@ -133,7 +134,7 @@ dzl_progress_menu_button_begin_theatrics (DzlProgressMenuButton *self)
 
   g_assert (DZL_IS_PROGRESS_MENU_BUTTON (self));
 
-  if (!priv->show_theatric || priv->transition_duration == 0)
+  if (!priv->show_theatric || priv->transition_duration == 0 || priv->suppress_theatric)
     return;
 
   gtk_widget_get_allocation (GTK_WIDGET (self), &rect);
@@ -174,6 +175,8 @@ dzl_progress_menu_button_begin_theatrics (DzlProgressMenuButton *self)
                            "height", rect.height + 120,
                            "alpha", 0.0,
                            NULL);
+
+  priv->suppress_theatric = TRUE;
 }
 
 static void
@@ -299,3 +302,24 @@ dzl_progress_menu_button_init (DzlProgressMenuButton *self)
                     &priv->icon);
   gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (priv->icon));
 }
+
+/**
+ * dzl_progress_menu_button_reset_theatrics:
+ * @self: a #DzlProgressMenuButton
+ *
+ * To avoid suprious animations from the button, you must call this function any
+ * time you want to allow animations to continue. This is because animations are
+ * automatically started upon reaching a progress of 1.0.
+ *
+ * If you are performing operations in the background, calling this function
+ * every time you add an operation is a good strategry.
+ */
+void
+dzl_progress_menu_button_reset_theatrics (DzlProgressMenuButton *self)
+{
+  DzlProgressMenuButtonPrivate *priv = dzl_progress_menu_button_get_instance_private (self);
+
+  g_return_if_fail (DZL_IS_PROGRESS_MENU_BUTTON (self));
+
+  priv->suppress_theatric = FALSE;
+}
diff --git a/src/widgets/dzl-progress-menu-button.h b/src/widgets/dzl-progress-menu-button.h
index 4c915bf..7419417 100644
--- a/src/widgets/dzl-progress-menu-button.h
+++ b/src/widgets/dzl-progress-menu-button.h
@@ -44,6 +44,7 @@ void       dzl_progress_menu_button_set_progress      (DzlProgressMenuButton *bu
 gboolean   dzl_progress_menu_button_get_show_theatric (DzlProgressMenuButton *self);
 void       dzl_progress_menu_button_set_show_theatric (DzlProgressMenuButton *self,
                                                        gboolean               show_theatic);
+void       dzl_progress_menu_button_reset_theatrics   (DzlProgressMenuButton *self);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]