Commit 27cef3d1 authored by Abhinav Singh's avatar Abhinav Singh Committed by Adrien Plazas
Browse files

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.

https://bugzilla.gnome.org/show_bug.cgi?id=780754
parent 8690654c
......@@ -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>
......@@ -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>
......@@ -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>
......
......@@ -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]
......
......@@ -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;
......
// 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 () {}
}
......@@ -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);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment