[gnome-games] ui: Add SidebarView widget



commit 8404ac445f3978261d39baa0131dbb44a9b30a5d
Author: 1PunMan <saurabhsingh412 gmail com>
Date:   Thu Aug 2 23:36:48 2018 +0530

    ui: Add SidebarView widget
    
    This widget will be later used to implement developers view &
    platforms view.

 data/org.gnome.Games.gresource.xml |  1 +
 data/ui/sidebar-view.ui            | 34 ++++++++++++++++++++
 src/meson.build                    |  1 +
 src/ui/sidebar-view.vala           | 65 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 101 insertions(+)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index c2cdf35c..e77d0db2 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -41,5 +41,6 @@
     <file preprocess="xml-stripblanks">ui/resume-failed-dialog.ui</file>
     <file preprocess="xml-stripblanks">ui/search-bar.ui</file>
     <file preprocess="xml-stripblanks">ui/shortcuts-window.ui</file>
+    <file preprocess="xml-stripblanks">ui/sidebar-view.ui</file>
   </gresource>
 </gresources>
diff --git a/data/ui/sidebar-view.ui b/data/ui/sidebar-view.ui
new file mode 100644
index 00000000..df5d65ac
--- /dev/null
+++ b/data/ui/sidebar-view.ui
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GamesSidebarView" parent="GtkBox">
+    <property name="visible">True</property>
+    <property name="can-focus">False</property>
+    <property name="expand">True</property>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="vexpand">True</property>
+        <property name="width_request">250</property>
+        <child>
+          <object class="GtkListBox" id="list_box">
+            <property name="visible">True</property>
+            <property name="can-focus">False</property>
+            <signal name="row-activated" handler="on_list_box_row_selected"/>
+            <style>
+              <class name="sidebar"/>
+            </style>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GamesCollectionIconView" id="collection_view">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="expand">True</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/meson.build b/src/meson.build
index d6349d8a..a13573e9 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -160,6 +160,7 @@ vala_sources = [
   'ui/resume-failed-dialog.vala',
   'ui/search-bar.vala',
   'ui/shortcuts-window.vala',
+  'ui/sidebar-view.vala',
   'ui/ui-state.vala',
 
   'utils/composite-cover.vala',
diff --git a/src/ui/sidebar-view.vala b/src/ui/sidebar-view.vala
new file mode 100644
index 00000000..e97afa5b
--- /dev/null
+++ b/src/ui/sidebar-view.vala
@@ -0,0 +1,65 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/sidebar-view.ui")]
+private abstract class Games.SidebarView : Gtk.Box {
+       public signal void game_activated (Game game);
+
+       public string filtering_text {
+               set { collection_view.filtering_text = value; }
+       }
+
+       private ListModel _model;
+       public ListModel model {
+               set {
+                       _model = value;
+                       collection_view.model = _model;
+                       model.items_changed.connect (on_model_changed);
+               }
+               get { return _model; }
+       }
+
+
+       [GtkChild]
+       protected CollectionIconView collection_view;
+
+       [GtkChild]
+       protected Gtk.ListBox list_box;
+
+       construct {
+               list_box.set_sort_func (sort_rows);
+
+               collection_view.game_activated.connect ((game) => {
+                       game_activated (game);
+                });
+       }
+
+       protected abstract void game_added (Game game);
+       protected abstract void invalidate (Gtk.ListBoxRow row_item);
+       protected abstract int sort_rows (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2);
+
+       [GtkCallback]
+       private void on_list_box_row_selected (Gtk.ListBoxRow row_item) {
+               list_box.select_row (row_item);
+               invalidate (row_item);
+       }
+
+       private void on_model_changed (uint position, uint removed, uint added) {
+               // FIXME: currently games are never removed, update this function if
+               // necessary.
+               assert (removed == 0);
+
+               for (uint i = position ; i < position + added ; i++) {
+                       var game = model.get_item (i) as Game;
+                       game_added (game);
+               }
+       }
+
+       public void select_default_row () {
+               var row = list_box.get_row_at_index (0) as Gtk.ListBoxRow;
+
+               if (row == null)
+                       return;
+
+               on_list_box_row_selected (row);
+       }
+}


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