[gnome-clocks] Do a transition also on hide



commit 286cfe9e8f3bd6d1d6d7db1e1ca83e5a6774921b
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Feb 24 17:06:33 2013 +0100

    Do a transition also on hide
    
    And factor out fade in/out functions to be used also in other cases.

 src/widgets.vala |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/src/widgets.vala b/src/widgets.vala
index 6e87219..bce3789 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -409,11 +409,9 @@ public class ContentView : Gtk.Bin {
             main_toolbar.set_labels (label, null);
 
             if (n_items != 0) {
-                selection_toolbar.show ();
-                selection_toolbar.get_style_context ().add_class ("clocks-fade-in");
+                fade_in (selection_toolbar);
             } else {
-                selection_toolbar.hide ();
-                selection_toolbar.get_style_context ().remove_class ("clocks-fade-in");
+                fade_out (selection_toolbar);
             }
         });
 
@@ -486,6 +484,29 @@ public class ContentView : Gtk.Bin {
         show_all ();
     }
 
+    private void fade_in (Gtk.Widget w) {
+        uint timeout_id = w.get_data<uint> ("cloks-fade-out-timeout-id");
+        if (timeout_id != 0) {
+            Source.remove (timeout_id);
+            w.set_data<uint> ("cloks-fade-out-timeout-id", 0);
+        }
+        w.show ();
+        w.get_style_context ().add_class ("clocks-fade-in");
+    }
+
+    private void fade_out (Gtk.Widget w) {
+        uint timeout_id = w.get_data<uint> ("cloks-fade-out-timeout-id");
+        if (timeout_id == 0) {
+            w.get_style_context ().remove_class ("clocks-fade-in");
+            timeout_id = Timeout.add (300, () => {
+                w.set_data<uint> ("cloks-fade-out-timeout-id", 0);
+                w.hide ();
+                return false;
+            });
+            w.set_data<uint> ("cloks-fade-out-timeout-id", timeout_id);
+        }
+    }
+
     // Note: this is not efficient: we first walk the model to collect
     // a list then the caller has to walk this list and then it has to
     // delete the items from the view, which walks the model again...


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