[gnome-games/wip/abhinavsingh/gamepad-config: 21/22] ui: Allow PreferencesPage to show custom headers
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-config: 21/22] ui: Allow PreferencesPage to show custom headers
- Date: Fri, 28 Jul 2017 03:47:30 +0000 (UTC)
commit 918e952a61e0afe933853a02476f64ed62b8164d
Author: theawless <theawless gmail com>
Date: Thu Jul 27 00:41:55 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 that allows an enhanced
experience for editing controller configurations.
data/ui/preferences-page-plugins.ui | 4 ++
data/ui/preferences-page-video.ui | 4 ++
data/ui/preferences-window.ui | 20 +----------
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 | 62 ++++++++++++++++++++++++++++++----
7 files changed, 87 insertions(+), 31 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..320f4bb 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>
@@ -73,7 +55,7 @@
</object>
</child>
<child>
- <object class="GtkSeparator" id="separator1">
+ <object class="GtkSeparator" id="separator">
<property name="orientation">vertical</property>
<property name="visible">True</property>
<property name="expand">False</property>
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..68823ec 100644
--- a/src/ui/preferences-window.vala
+++ b/src/ui/preferences-window.vala
@@ -3,21 +3,69 @@
[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 separator;
[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);
+ value.show_close_button = !immersive_mode;
+ }
+ _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;
+ separator.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 () {
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]