[gnome-games/wip/abhinavsingh/gamepad-config: 21/22] ui: Allow PreferencesPage to show custom headers



commit 5fb7fbb5684a2765958295d542223d1dc1260d00
Author: theawless <theawless gmail com>
Date:   Fri Jul 21 11:58:53 2017 +0530

    ui: Allow PreferencesPage to show custom headers
    
    This will allow the PreferencesPages to show widgets in the header bar.
    Add 'immersive-mode' for PreferencesPages which will help give an
    enhanced experience for configuration of inputs.

 data/ui/preferences-page-plugins.ui  |    4 ++
 data/ui/preferences-page-video.ui    |    4 ++
 data/ui/preferences-window.ui        |   18 ---------
 src/ui/preferences-page-plugins.vala |   12 +++++-
 src/ui/preferences-page-video.vala   |   12 +++++-
 src/ui/preferences-page.vala         |    4 +-
 src/ui/preferences-window.vala       |   70 ++++++++++++++++++++++++++++++---
 7 files changed, 94 insertions(+), 30 deletions(-)
---
diff --git a/data/ui/preferences-page-plugins.ui b/data/ui/preferences-page-plugins.ui
index 75a7615..4b47370 100644
--- a/data/ui/preferences-page-plugins.ui
+++ b/data/ui/preferences-page-plugins.ui
@@ -45,4 +45,8 @@
       </object>
     </child>
   </template>
+  <object class="GtkHeaderBar" id="header_bar">
+    <property name="visible">True</property>
+    <property name="title" translatable="yes">Extensions</property>
+  </object>
 </interface>
diff --git a/data/ui/preferences-page-video.ui b/data/ui/preferences-page-video.ui
index 50b473e..e900d7f 100644
--- a/data/ui/preferences-page-video.ui
+++ b/data/ui/preferences-page-video.ui
@@ -50,4 +50,8 @@
       </object>
     </child>
   </template>
+  <object class="GtkHeaderBar" id="header_bar">
+    <property name="visible">True</property>
+    <property name="title" translatable="yes">Video</property>
+  </object>
 </interface>
diff --git a/data/ui/preferences-window.ui b/data/ui/preferences-window.ui
index 36026a6..77f10e2 100644
--- a/data/ui/preferences-window.ui
+++ b/data/ui/preferences-window.ui
@@ -28,24 +28,6 @@
             <property name="visible">True</property>
           </object>
         </child>
-        <child>
-          <object class="GtkHeaderBar" id="right_header_bar">
-            <property name="name">right_header_bar</property>
-            <property name="visible">True</property>
-            <property name="expand">True</property>
-            <property name="show-close-button">True</property>
-            <property name="decoration_layout">:close</property>
-            <child>
-              <object class="GtkStack" id="controls_stack">
-                <property name="homogeneous">false</property>
-                <property name="visible">true</property>
-              </object>
-              <packing>
-                <property name="pack-type">start</property>
-              </packing>
-            </child>
-          </object>
-        </child>
       </object>
     </child>
     <child>
diff --git a/src/ui/preferences-page-plugins.vala b/src/ui/preferences-page-plugins.vala
index 16500b8..37d4702 100644
--- a/src/ui/preferences-page-plugins.vala
+++ b/src/ui/preferences-page-plugins.vala
@@ -2,8 +2,16 @@
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-plugins.ui")]
 private class Games.PreferencesPagePlugins: Gtk.Bin, PreferencesPage {
-       public string title {
-               get { return _("Extensions"); }
+       [GtkChild (name = "header_bar")]
+       private Gtk.HeaderBar _header_bar;
+       public Gtk.HeaderBar header_bar {
+               protected set {}
+               get { return _header_bar; }
+       }
+       
+       public bool immersive_mode {
+               protected set {}
+               get { return false; }
        }
 
        [GtkChild]
diff --git a/src/ui/preferences-page-video.vala b/src/ui/preferences-page-video.vala
index 7754e59..b1dca80 100644
--- a/src/ui/preferences-page-video.vala
+++ b/src/ui/preferences-page-video.vala
@@ -2,8 +2,16 @@
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-video.ui")]
 private class Games.PreferencesPageVideo: Gtk.Bin, PreferencesPage {
-       public string title {
-               get { return _("Video"); }
+       [GtkChild (name = "header_bar")]
+       private Gtk.HeaderBar _header_bar;
+       public Gtk.HeaderBar header_bar {
+               protected set {}
+               get { return _header_bar; }
+       }
+       
+       public bool immersive_mode {
+               protected set {}
+               get { return false; }
        }
 
        private string _filter_active;
diff --git a/src/ui/preferences-page.vala b/src/ui/preferences-page.vala
index 14b2170..bd8576f 100644
--- a/src/ui/preferences-page.vala
+++ b/src/ui/preferences-page.vala
@@ -1,5 +1,7 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 private interface Games.PreferencesPage: Gtk.Widget {
-       public abstract string title { get; }
+       public abstract Gtk.HeaderBar header_bar { protected set; get; }
+       public abstract bool immersive_mode { protected set; get; }
+       public virtual void visible_page_changed () {}
 }
diff --git a/src/ui/preferences-window.vala b/src/ui/preferences-window.vala
index 3d1bc0b..612c2dd 100644
--- a/src/ui/preferences-window.vala
+++ b/src/ui/preferences-window.vala
@@ -3,21 +3,77 @@
 [GtkTemplate (ui = "/org/gnome/Games/ui/preferences-window.ui")]
 private class Games.PreferencesWindow : Gtk.Window {
        [GtkChild]
-       private Gtk.HeaderBar right_header_bar;
+       private Gtk.Box titlebar_box;
+       [GtkChild]
+       private Gtk.HeaderBar left_header_bar;
+       [GtkChild]
+       private Gtk.Separator header_separator;
+       [GtkChild]
+       private Gtk.Box sidebar_vbox;
+       [GtkChild]
+       private Gtk.Separator separator1;
        [GtkChild]
        private Gtk.Stack stack;
 
+       private Gtk.HeaderBar _right_header_bar;
+       public Gtk.HeaderBar right_header_bar {
+               set {
+                       if (_right_header_bar != null)
+                               titlebar_box.remove (_right_header_bar);
+                       if (value != null)
+                               titlebar_box.pack_end (value);
+
+                       _right_header_bar = value;
+               }
+               get { return _right_header_bar; }
+       }
+
+       private bool _immersive_mode;
+       public bool immersive_mode {
+               set {
+                       header_separator.visible = !value;
+                       left_header_bar.visible = !value;
+                       separator1.visible = !value;
+                       sidebar_vbox.visible = !value;
+                       if (right_header_bar != null)
+                               right_header_bar.show_close_button = !value;
+
+                       _immersive_mode = value;
+               }
+               get { return _immersive_mode; }
+       }
+
+       private Binding right_header_bar_binding;
+       private Binding immersive_mode_binding;
+
        public PreferencesWindow () {
                stack.foreach ((child) => {
-                       var page = child as PreferencesPage;
-                       page.notify["title"].connect (update_title);
+                       var page = (PreferencesPage) child;
+                       stack.notify["visible-child-name"].connect (page.visible_page_changed);
                });
-               stack.notify["visible-child-name"].connect (update_title);
-               update_title ();
+               stack.notify["visible-child-name"].connect (visible_child_changed);
+               visible_child_changed ();
        }
 
-       private void update_title () {
+       private void visible_child_changed () {
+               if (right_header_bar_binding != null) {
+                       right_header_bar_binding.unbind ();
+                       right_header_bar_binding = null;
+               }
+               if (immersive_mode_binding != null) {
+                       immersive_mode_binding.unbind ();
+                       immersive_mode_binding = null;
+               }
+
                var page = (PreferencesPage) stack.get_visible_child ();
-               right_header_bar.title = (page == null) ? "" : page.title;
+               if (page == null) {
+                       right_header_bar = null;
+
+                       return;
+               }
+               right_header_bar_binding = page.bind_property ("header-bar", this, "right_header_bar",
+                                                              BindingFlags.SYNC_CREATE);
+               immersive_mode_binding = page.bind_property ("immersive-mode", this, "immersive-mode",
+                                                              BindingFlags.SYNC_CREATE);
        }
 }


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