[gnome-boxes/wip/less-actors2: 1/2] app: Use Gtk.Stack for below_bin



commit fca3d1f39a5e04dee8721a004424fa437b3d8352
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Feb 19 23:04:58 2014 +0000

    app: Use Gtk.Stack for below_bin
    
    This saves us yet more actor layer.
    
    This also introduces a weird issue when the EmptyBoxes widget goes
    completely blank on page switch. Switching to another application and
    back sometimes helps so its likely some gtk+ issue but need to
    investigate more to be sure.

 data/gtk-style.css       |   10 ++++
 data/ui/empty-boxes.ui   |  114 +++++++++++++++++++++++++++++----------------
 src/app.vala             |   60 +++++++++---------------
 src/collection-view.vala |   20 ++++----
 src/empty-boxes.vala     |   36 ++++++++------
 5 files changed, 135 insertions(+), 105 deletions(-)
---
diff --git a/data/gtk-style.css b/data/gtk-style.css
index 3e9718a..24ac8b8 100644
--- a/data/gtk-style.css
+++ b/data/gtk-style.css
@@ -66,11 +66,21 @@ BoxesMiniGraph {
     font-weight: bold;
 }
 
+.boxes-icon-view {
+    background-image: url("icons/boxes-dark.png");
+    border-image-repeat: stretch;
+}
+
 .wizard {
     background-image: url("icons/boxes-dark.png");
     border-image-repeat: stretch;
 }
 
+.empty-boxes {
+    background-image: url("icons/boxes-dark.png");
+    border-image-repeat: stretch;
+}
+
 .boxes-wizard-label {
     color: #d8d8d8;
 }
diff --git a/data/ui/empty-boxes.ui b/data/ui/empty-boxes.ui
index dcc4bda..27b6517 100644
--- a/data/ui/empty-boxes.ui
+++ b/data/ui/empty-boxes.ui
@@ -5,78 +5,110 @@
     <property name="visible">True</property>
     <property name="hexpand">True</property>
     <property name="vexpand">True</property>
-    <property name="halign">center</property>
-    <property name="valign">center</property>
+    <property name="halign">fill</property>
+    <property name="valign">fill</property>
     <style>
       <class name="dim-label"/>
     </style>
 
     <child>
-      <object class="GtkSpinner" id="spinner">
+      <object class="GtkBox" id="spinner-box">
         <property name="visible">True</property>
-        <property name="active">True</property>
-        <property name="width-request">32</property>
-        <property name="height-request">32</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="halign">fill</property>
+        <property name="valign">fill</property>
+        <style>
+          <class name="empty-boxes"/>
+        </style>
+
+        <child>
+          <object class="GtkSpinner" id="spinner">
+            <property name="visible">True</property>
+            <property name="active">True</property>
+            <property name="width-request">32</property>
+            <property name="height-request">32</property>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+          </packing>
+        </child>
       </object>
     </child>
 
     <child>
-      <object class="GtkGrid" id="grid">
+      <object class="GtkBox" id="grid_box">
         <property name="visible">True</property>
-        <property name="orientation">horizontal</property>
-        <property name="column-spacing">12</property>
         <property name="hexpand">True</property>
         <property name="vexpand">True</property>
-        <property name="halign">center</property>
-        <property name="valign">center</property>
-        <property name="row-homogeneous">True</property>
+        <property name="halign">fill</property>
+        <property name="valign">fill</property>
         <style>
-          <class name="dim-label"/>
+          <class name="empty-boxes"/>
         </style>
 
         <child>
-          <object class="GtkImage" id="image">
+          <object class="GtkGrid" id="grid">
             <property name="visible">True</property>
-            <property name="icon-name">application-x-appliance-symbolic</property>
-            <property name="icon-size">6</property>
-            <property name="pixel-size">96</property>
+            <property name="orientation">horizontal</property>
+            <property name="column-spacing">12</property>
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+            <property name="row-homogeneous">True</property>
             <style>
-              <class name="boxes-empty-image"/>
+              <class name="dim-label"/>
             </style>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkGrid" id="labels_grid">
-            <property name="visible">True</property>
-            <property name="orientation">vertical</property>
 
             <child>
-              <object class="GtkLabel" id="no_boxes_found_label">
+              <object class="GtkImage" id="image">
                 <property name="visible">True</property>
-                <property name="use-markup">True</property>
-                <property name="halign">start</property>
-                <property name="vexpand">True</property>
-                <property name="label" translatable="yes">&lt;b&gt;&lt;span size=&quot;large&quot;&gt;No 
boxes found&lt;/span&gt;&lt;/b&gt;</property>
+                <property name="icon-name">application-x-appliance-symbolic</property>
+                <property name="icon-size">6</property>
+                <property name="pixel-size">96</property>
+                <style>
+                  <class name="boxes-empty-image"/>
+                </style>
               </object>
             </child>
 
             <child>
-              <object class="GtkLabel" id="instructions_label">
+              <object class="GtkGrid" id="labels_grid">
                 <property name="visible">True</property>
-                <property name="use-markup">True</property>
-                <property name="halign">start</property>
-                <property name="vexpand">True</property>
-                <property name="xalign">0</property>
-                <property name="max-width-chars">24</property>
-                <property name="wrap">True</property>
-                <property name="label" translatable="yes">Create one using the button on the top 
left.</property>
-                <style>
-                  <class name="boxes-empty-details-label"/>
-                </style>
+                <property name="orientation">vertical</property>
+
+                <child>
+                  <object class="GtkLabel" id="no_boxes_found_label">
+                    <property name="visible">True</property>
+                    <property name="use-markup">True</property>
+                    <property name="halign">start</property>
+                    <property name="vexpand">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;&lt;span size=&quot;large&quot;&gt;No 
boxes found&lt;/span&gt;&lt;/b&gt;</property>
+                  </object>
+                </child>
+
+                <child>
+                  <object class="GtkLabel" id="instructions_label">
+                    <property name="visible">True</property>
+                    <property name="use-markup">True</property>
+                    <property name="halign">start</property>
+                    <property name="vexpand">True</property>
+                    <property name="xalign">0</property>
+                    <property name="max-width-chars">24</property>
+                    <property name="wrap">True</property>
+                    <property name="label" translatable="yes">Create one using the button on the top 
left.</property>
+                    <style>
+                      <class name="boxes-empty-details-label"/>
+                    </style>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+          </packing>
         </child>
       </object>
     </child>
diff --git a/src/app.vala b/src/app.vala
index 0873dc2..bb6fc15 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -100,8 +100,9 @@ private class Boxes.App: GLib.Object, Boxes.UI {
     public string? uri { get; set; }
     public Collection collection;
     public CollectionFilter filter;
+    public Gtk.Stack below_bin;
     private Gtk.Stack content_bin;
-    private Clutter.Actor hbox_actor;
+    private Gtk.Box below_bin_hbox;
 
     private bool is_ready;
     public signal void ready ();
@@ -576,21 +577,6 @@ private class Boxes.App: GLib.Object, Boxes.UI {
         stage.set_layout_manager (stage_bin);
         stage.name = "boxes-stage";
 
-        var background = new GtkClutter.Texture ();
-        background.name = "background";
-        try {
-            var pixbuf = load_asset ("boxes-dark.png");
-            background.set_from_pixbuf (pixbuf);
-        } catch (GLib.Error e) {
-            warning ("Failed to load asset 'boxes-dark.png': %s", e.message);
-        }
-        background.set_repeat (true, true);
-        background.x_align = Clutter.ActorAlign.FILL;
-        background.y_align = Clutter.ActorAlign.FILL;
-        background.x_expand = true;
-        background.y_expand = true;
-        stage.add_child (background);
-
         sidebar = new Sidebar ();
         view = new CollectionView ();
         topbar = new Topbar ();
@@ -600,27 +586,24 @@ private class Boxes.App: GLib.Object, Boxes.UI {
 
         window.set_titlebar (topbar);
 
-        var below_bin_actor = new Clutter.Actor ();
+        below_bin = new Gtk.Stack ();
+        below_bin.transition_type = Gtk.StackTransitionType.CROSSFADE;
+        var below_bin_actor = new GtkClutter.Actor.with_contents (below_bin);
         below_bin_actor.name = "below-bin";
-        var below_bin = new Clutter.BinLayout (Clutter.BinAlignment.START,
-                                               Clutter.BinAlignment.START);
-        below_bin_actor.set_layout_manager (below_bin);
-
         below_bin_actor.x_expand = true;
         below_bin_actor.y_expand = true;
         stage.add_child (below_bin_actor);
 
-        below_bin_actor.add_child (view.actor);
+        below_bin.add_named (empty_boxes, "empty-boxes");
+        below_bin.add_named (view, "collection-view");
 
-        var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
-        hbox_actor = new GtkClutter.Actor.with_contents (hbox);
-        hbox_actor.name = "top-hbox";
-        hbox_actor.x_align = Clutter.ActorAlign.FILL;
-        hbox_actor.y_align = Clutter.ActorAlign.FILL;
-        hbox_actor.x_expand = true;
-        hbox_actor.y_expand = true;
+        below_bin_hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
+        below_bin_hbox.halign = Gtk.Align.FILL;
+        below_bin_hbox.valign = Gtk.Align.FILL;
+        below_bin_hbox.hexpand = true;
+        below_bin_hbox.vexpand = true;
 
-        below_bin_actor.add_child (hbox_actor);
+        below_bin.add_named (below_bin_hbox, "below-bin-hbox");
 
         content_bin = new Gtk.Stack ();
         content_bin.vexpand = true;
@@ -628,12 +611,11 @@ private class Boxes.App: GLib.Object, Boxes.UI {
         content_bin.add (wizard);
         content_bin.add (properties);
 
-        hbox.add (sidebar);
-        hbox.add (content_bin);
-        hbox.show_all ();
-        hbox_actor.hide ();
+        below_bin_hbox.add (sidebar);
+        below_bin_hbox.add (content_bin);
+        below_bin_hbox.show_all ();
 
-        below_bin_actor.add_child (empty_boxes.actor);
+        below_bin.show_all ();
 
         properties.actor.hide ();
 
@@ -659,10 +641,12 @@ private class Boxes.App: GLib.Object, Boxes.UI {
         if (ui_state != UIState.COLLECTION)
             searchbar.visible = false;
 
-        hbox_actor.visible = (ui_state == UIState.WIZARD || ui_state == UIState.PROPERTIES);
-
         switch (ui_state) {
         case UIState.COLLECTION:
+            if (collection.items.length != 0)
+                below_bin.visible_child = view;
+            else
+                below_bin.visible_child = empty_boxes;
             topbar.status = null;
             status_bind = null;
             if (current_item is Machine) {
@@ -684,11 +668,13 @@ private class Boxes.App: GLib.Object, Boxes.UI {
             break;
 
         case UIState.WIZARD:
+            below_bin.visible_child = below_bin_hbox;
             content_bin.visible_child = wizard;
 
             break;
 
         case UIState.PROPERTIES:
+            below_bin.visible_child = below_bin_hbox;
             content_bin.visible_child = properties;
 
             break;
diff --git a/src/collection-view.vala b/src/collection-view.vala
index fb004dd..afde1be 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -8,11 +8,18 @@ public enum Boxes.SelectionCriteria {
 }
 
 private class Boxes.CollectionView: Gd.MainView, Boxes.UI {
-    public Clutter.Actor actor { get { return gtkactor; } }
+    // See FIXME on Topbar class
+    public Clutter.Actor actor {
+        get {
+            if (gtkactor == null)
+                gtkactor = new Clutter.Actor ();
+            return gtkactor;
+        }
+    }
     public UIState previous_ui_state { get; protected set; }
     public UIState ui_state { get; protected set; }
 
-    private GtkClutter.Actor gtkactor;
+    private Clutter.Actor gtkactor;
 
     private Category _category;
     public Category category {
@@ -284,17 +291,8 @@ private class Boxes.CollectionView: Gd.MainView, Boxes.UI {
             App.app.selection_mode = true;
         });
         show_all ();
-
-        gtkactor = new GtkClutter.Actor.with_contents (this);
-        gtkactor.get_widget ().get_style_context ().add_class ("boxes-bg");
-        gtkactor.name = "collection-view";
-        gtkactor.x_align = Clutter.ActorAlign.FILL;
-        gtkactor.y_align = Clutter.ActorAlign.FILL;
-        gtkactor.x_expand = true;
-        gtkactor.y_expand = true;
     }
 
-
     public void select (SelectionCriteria selection) {
         App.app.selection_mode = true;
 
diff --git a/src/empty-boxes.vala b/src/empty-boxes.vala
index cca28e8..0344e4c 100644
--- a/src/empty-boxes.vala
+++ b/src/empty-boxes.vala
@@ -2,24 +2,23 @@
 
 [GtkTemplate (ui = "/org/gnome/Boxes/ui/empty-boxes.ui")]
 private class Boxes.EmptyBoxes : Gtk.Stack, Boxes.UI {
-    public Clutter.Actor actor { get { return gtk_actor; } }
+    // See FIXME on Topbar class
+    public Clutter.Actor actor {
+        get {
+            if (gtk_actor == null)
+                gtk_actor = new Clutter.Actor ();
+            return gtk_actor;
+        }
+    }
     public UIState previous_ui_state { get; protected set; }
     public UIState ui_state { get; protected set; }
 
-    private GtkClutter.Actor gtk_actor;
+    private Clutter.Actor gtk_actor;
 
     [GtkChild]
-    private Gtk.Grid grid;
+    private Gtk.Box grid_box;
 
     public EmptyBoxes () {
-        gtk_actor = new GtkClutter.Actor.with_contents (this);
-        gtk_actor.get_widget ().get_style_context ().add_class ("boxes-bg");
-        gtk_actor.opacity = 255;
-        gtk_actor.x_align = Clutter.ActorAlign.FILL;
-        gtk_actor.y_align = Clutter.ActorAlign.FILL;
-        gtk_actor.x_expand = true;
-        gtk_actor.y_expand = true;
-
         App.app.call_when_ready (on_app_ready);
     }
 
@@ -31,11 +30,16 @@ private class Boxes.EmptyBoxes : Gtk.Stack, Boxes.UI {
     }
 
     private void update_visibility () {
-        var visible = ui_state == UIState.COLLECTION && App.app.collection.items.length == 0;
-        if (visible != gtk_actor.visible)
-            fade_actor (gtk_actor, visible? 255 : 0);
+        var visible = App.app.collection.items.length == 0;
+        if (visible && visible_child != grid_box)
+            visible_child = grid_box;
+
+        if (ui_state != UIState.COLLECTION)
+            return;
 
-        if (visible && visible_child != grid)
-            visible_child = grid;
+        if (visible)
+            App.app.below_bin.set_visible_child_name ("empty-boxes");
+        else
+            App.app.below_bin.set_visible_child_name ("collection-view");
     }
 }


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