[gnome-games/wip/exalm/views2: 21/21] A hacky preferences view
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/views2: 21/21] A hacky preferences view
- Date: Sun, 7 Oct 2018 07:26:51 +0000 (UTC)
commit acccca44545ec930e0b3730aad765d132b2cca0c
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sun Oct 7 02:15:26 2018 +0500
A hacky preferences view
data/org.gnome.Games.gresource.xml | 1 +
data/ui/preferences-view.ui | 138 +++++++++++++++++++++++++++++++++++++
src/meson.build | 1 +
src/ui/application-window.vala | 13 ++++
src/ui/application.vala | 2 +
src/ui/preferences-view.vala | 129 ++++++++++++++++++++++++++++++++++
6 files changed, 284 insertions(+)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 74eb5322..b8fecd49 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -36,6 +36,7 @@
<file preprocess="xml-stripblanks">ui/preferences-page-video.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-subpage-gamepad.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-subpage-keyboard.ui</file>
+ <file preprocess="xml-stripblanks">ui/preferences-view.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-window.ui</file>
<file preprocess="xml-stripblanks">ui/quit-dialog.ui</file>
<file preprocess="xml-stripblanks">ui/remote-display.ui</file>
diff --git a/data/ui/preferences-view.ui b/data/ui/preferences-view.ui
new file mode 100644
index 00000000..610c16fe
--- /dev/null
+++ b/data/ui/preferences-view.ui
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.8 -->
+ <template class="GamesPreferencesView" parent="GtkStack">
+ <property name="visible">True</property>
+ <property name="transition-type">slide-left-right</property>
+ <property name="transition-duration">250</property>
+ <signal name="notify::transition-running" handler="subpage_transition_finished"/>
+ <child>
+ <object class="GtkBox" id="content_box">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkStackSidebar" id="sidebar">
+ <property name="margin-top">4</property>
+ <property name="stack">stack</property>
+ <property name="vexpand">True</property>
+ <property name="visible">True</property>
+ <property name="width-request">150</property>
+ <style>
+ <class name="preferences" />
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator" id="separator">
+ <property name="orientation">vertical</property>
+ <property name="visible">True</property>
+ <style>
+ <class name="sidebar"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkStack" id="stack">
+ <property name="visible">True</property>
+ <property name="expand">True</property>
+ <property name="visible-child">video_page</property>
+ <property name="transition-type">GTK_STACK_TRANSITION_TYPE_CROSSFADE</property>
+ <child>
+ <object class="GamesPreferencesPageVideo" id="video_page">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="name">video</property>
+ <property name="title" translatable="yes">Video</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GamesPreferencesPageControllers" id="controllers_page">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="name">controllers</property>
+ <property name="title" translatable="yes">Controllers</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GamesPreferencesPagePlugins" id="plugins_page">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="name">plugins</property>
+ <property name="title" translatable="yes">Extensions</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+ <object class="GtkSizeGroup">
+ <property name="mode">GTK_SIZE_GROUP_HORIZONTAL</property>
+ <widgets>
+ <widget name="left_header_bar"/>
+ <widget name="sidebar"/>
+ </widgets>
+ </object>
+ <object class="GtkStack" id="titlebar_stack">
+ <property name="visible">True</property>
+ <property name="transition-type">slide-left-right</property>
+ <property name="transition-duration">250</property>
+ <child>
+ <object class="GtkBox" id="titlebar_box">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkHeaderBar" id="left_header_bar">
+ <property name="name">left_header_bar</property>
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">Preferences</property>
+ <property name="show-close-button">True</property>
+ <property name="decoration_layout">menu</property>
+ <child>
+ <object class="GtkButton" id="back_button">
+ <property name="visible">True</property>
+ <signal name="clicked" handler="on_back_clicked"/>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child internal-child="accessible">
+ <object class="AtkObject" id="a11y-back">
+ <property name="accessible-name" translatable="yes">Back</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImage" id="back_image">
+ <property name="visible">True</property>
+ <property name="icon-name">go-previous-symbolic</property>
+ <property name="icon-size">1</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator" id="header_separator">
+ <property name="orientation">vertical</property>
+ <property name="visible">True</property>
+ <style>
+ <class name="sidebar"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkHeaderBar" id="right_header_bar">
+ <property name="name">right_header_bar</property>
+ <property name="visible">True</property>
+ <property name="hexpand">True</property>
+ <property name="show-close-button">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/src/meson.build b/src/meson.build
index baaf3cb8..e3474e2c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -161,6 +161,7 @@ vala_sources = [
'ui/preferences-subpage.vala',
'ui/preferences-subpage-gamepad.vala',
'ui/preferences-subpage-keyboard.vala',
+ 'ui/preferences-view.vala',
'ui/preferences-window.vala',
'ui/quit-dialog.vala',
'ui/remote-display.vala',
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 0debae1c..33673240 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -302,4 +302,17 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
critical (e.message);
}
}
+
+ public void show_preferences () {
+ var view = new PreferencesView ();
+ view.back.connect (() => {
+ current_view = collection_view;
+ content_box.remove (view);
+ header_bar.remove (view.titlebar);
+ });
+ view.show_back_button = true;
+ content_box.add (view);
+ header_bar.add (view.titlebar);
+ current_view = view;
+ }
}
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 7d1797fe..5070c4ac 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -343,6 +343,8 @@ public class Games.Application : Gtk.Application {
}
private void preferences () {
+ window.show_preferences ();
+ return;
if (preferences_window != null) {
preferences_window.present ();
diff --git a/src/ui/preferences-view.vala b/src/ui/preferences-view.vala
new file mode 100644
index 00000000..72d6befd
--- /dev/null
+++ b/src/ui/preferences-view.vala
@@ -0,0 +1,129 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-view.ui")]
+private class Games.PreferencesView : Gtk.Stack, ApplicationView {
+ public signal void back ();
+
+ [GtkChild]
+ private Gtk.Stack titlebar_stack;
+ [GtkChild]
+ private Gtk.Box titlebar_box;
+ [GtkChild]
+ private Gtk.HeaderBar right_header_bar;
+ [GtkChild]
+ private Gtk.Box content_box;
+ [GtkChild]
+ private Gtk.Stack stack;
+ [GtkChild]
+ private Gtk.Button back_button;
+
+ public bool selection_mode { get; set; }
+
+ public bool is_view_active { get; set; }
+
+ public bool show_back_button { get; set; }
+
+ public Gtk.Widget titlebar {
+ get {
+ return titlebar_stack;
+ }
+ }
+
+ private PreferencesSubpage _subpage;
+ public PreferencesSubpage subpage {
+ get { return _subpage; }
+ set {
+ if (subpage == value)
+ return;
+
+ if (subpage != null) {
+ previous_subpage = subpage;
+ visible_child = content_box;
+ titlebar_stack.visible_child = titlebar_box;
+ selection_mode_binding.unbind ();
+ }
+
+ if (value != null) {
+ var header_bar = value.header_bar;
+
+ add (value);
+ visible_child = value;
+
+ selection_mode_binding = value.bind_property ("request-selection-mode",
+ this, "selection-mode",
+ BindingFlags.SYNC_CREATE);
+
+ titlebar_stack.add (header_bar);
+ titlebar_stack.visible_child = header_bar;
+ }
+
+ _subpage = value;
+ }
+ }
+
+ // The previous subpage instance must be kept around during the transition
+ private PreferencesSubpage previous_subpage;
+
+ private Binding subpage_binding;
+ private Binding selection_mode_binding;
+ private Binding back_button_binding;
+
+ public PreferencesView () {
+ stack.notify["visible-child-name"].connect (visible_child_changed);
+ back_button_binding = bind_property ("show-back-button", back_button,
+ "visible", BindingFlags.SYNC_CREATE);
+ visible_child_changed ();
+ }
+
+ private void visible_child_changed () {
+ var page = stack.visible_child as PreferencesPage;
+ if (page == null) {
+ right_header_bar.title = "";
+ subpage = null;
+
+ return;
+ }
+
+ var title = "";
+ stack.child_get (page, "title", out title, null);
+ right_header_bar.title = title;
+
+ subpage_binding = page.bind_property ("subpage", this, "subpage",
+ BindingFlags.SYNC_CREATE);
+ }
+
+ [GtkCallback]
+ public void subpage_transition_finished (Object object, ParamSpec param) {
+ if (transition_running || previous_subpage == null)
+ return;
+
+ remove (previous_subpage);
+ titlebar_stack.remove (previous_subpage.header_bar);
+ previous_subpage = null;
+ }
+
+ [GtkCallback]
+ private void on_back_clicked () {
+ back ();
+ }
+
+ public bool on_button_pressed (Gdk.EventButton event) {
+ return false;
+ }
+
+ public bool on_key_pressed (Gdk.EventKey event) {
+ return false;
+ }
+
+ public bool gamepad_button_press_event (Manette.Event event) {
+ return false;
+ }
+
+ public bool gamepad_button_release_event (Manette.Event event) {
+ return false;
+ }
+
+ public bool gamepad_absolute_axis_event (Manette.Event event) {
+ return false;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]