[gnome-games/wip/exalm/libhandy2: 3/8] ui: Add PreferencesSidebar
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/libhandy2: 3/8] ui: Add PreferencesSidebar
- Date: Tue, 25 Sep 2018 17:12:10 +0000 (UTC)
commit 1763ad24745b5e6a2496e2b9542bd101b7fa5f44
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Wed Sep 12 15:02:49 2018 +0500
ui: Add PreferencesSidebar
Implement a GtkStackSidebar replacement that:
* Removes all unused functionality, like 'needs-attention' handling.
* Adds 'show-selection' property that allows not to select any rows in
folded mode.
* Adds row_selected() event that triggers even when switching to already
selected page, which is required in folded mode.
* Removes separators between rows.
* Allows to wrap row labels.
data/org.gnome.Games.gresource.xml | 1 +
data/ui/preferences-sidebar.ui | 24 +++++++++
src/meson.build | 1 +
src/ui/preferences-sidebar.vala | 108 +++++++++++++++++++++++++++++++++++++
4 files changed, 134 insertions(+)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index b5d366ea..114bea86 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -34,6 +34,7 @@
<file preprocess="xml-stripblanks">ui/preferences-page-plugins.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-plugins-item.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-video.ui</file>
+ <file preprocess="xml-stripblanks">ui/preferences-sidebar.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-sidebar-item.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-subpage-gamepad.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-subpage-keyboard.ui</file>
diff --git a/data/ui/preferences-sidebar.ui b/data/ui/preferences-sidebar.ui
new file mode 100644
index 00000000..8b9790a2
--- /dev/null
+++ b/data/ui/preferences-sidebar.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GamesPreferencesSidebar" parent="GtkBin">
+ <property name="visible">True</property>
+ <style>
+ <class name="preferences"/>
+ <class name="sidebar"/>
+ </style>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="visible">True</property>
+ <property name="hscrollbar-policy">never</property>
+ <child>
+ <object class="GtkListBox" id="list">
+ <property name="visible">True</property>
+ <property name="margin-top">4</property>
+ <property name="margin-bottom">4</property>
+ <signal name="row-activated" handler="row_activated"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/meson.build b/src/meson.build
index ee7952ba..76075ecd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -157,6 +157,7 @@ vala_sources = [
'ui/preferences-page-plugins.vala',
'ui/preferences-page-plugins-item.vala',
'ui/preferences-page-video.vala',
+ 'ui/preferences-sidebar.vala',
'ui/preferences-sidebar-item.vala',
'ui/preferences-subpage.vala',
'ui/preferences-subpage-gamepad.vala',
diff --git a/src/ui/preferences-sidebar.vala b/src/ui/preferences-sidebar.vala
new file mode 100644
index 00000000..6298a829
--- /dev/null
+++ b/src/ui/preferences-sidebar.vala
@@ -0,0 +1,108 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-sidebar.ui")]
+private class Games.PreferencesSidebar: Gtk.Bin {
+ private ulong child_added_id;
+
+ private Gtk.Stack _stack;
+ public Gtk.Stack stack {
+ get {
+ return _stack;
+ }
+ set {
+ if (_stack != null) {
+ clear_sidebar ();
+ stack.disconnect (child_added_id);
+ _stack = null;
+ }
+
+ _stack = value;
+
+ if (_stack != null)
+ populate_sidebar ();
+
+ child_added_id = stack.add.connect (add_child);
+
+ queue_resize ();
+ }
+ }
+
+ private bool _show_selection;
+ public bool show_selection {
+ get { return _show_selection; }
+ set {
+ _show_selection = value;
+
+ if (_show_selection)
+ list.selection_mode = Gtk.SelectionMode.SINGLE;
+ else
+ list.selection_mode = Gtk.SelectionMode.NONE;
+
+ if (stack != null)
+ select_current_row ();
+ }
+ }
+
+ public signal void row_selected ();
+
+ [GtkChild]
+ private Gtk.ListBox list;
+ private HashTable<PreferencesPage, PreferencesSidebarItem> rows;
+
+ static construct {
+ set_css_name ("stacksidebar");
+ }
+
+ construct {
+ rows = new HashTable<PreferencesPage, PreferencesSidebarItem> (null, null);
+ show_selection = true;
+ }
+
+ [GtkCallback]
+ private void row_activated (Gtk.ListBox box, Gtk.ListBoxRow? row) {
+ if (row == null)
+ return;
+
+ var item = row as PreferencesSidebarItem;
+ var page = item.preferences_page;
+ stack.visible_child = page;
+
+ row_selected ();
+ }
+
+ private void add_child (Gtk.Widget widget) {
+ var page = widget as PreferencesPage;
+
+ var row = new PreferencesSidebarItem (page);
+
+ rows[page] = row;
+ list.add (row);
+ }
+
+ private void populate_sidebar () {
+ stack.foreach (add_child);
+
+ select_current_row ();
+ }
+
+ private void clear_sidebar () {
+ foreach (var page in rows.get_keys ()) {
+ var row = rows[page];
+
+ list.remove (row);
+ rows.remove (page);
+ }
+ }
+
+ private void select_current_row () {
+ if (!show_selection)
+ return;
+
+ var page = stack.visible_child as PreferencesPage;
+
+ var row = rows[page];
+
+ if (row != null)
+ list.select_row (row);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]