[gnome-games] ui: Add PlatformsView widget



commit b250be12cc6d46cfc745fe89f82138eed8437265
Author: 1PunMan <saurabhsingh412 gmail com>
Date:   Wed Aug 1 23:18:10 2018 +0530

    ui: Add PlatformsView widget
    
    This widget will allow the display of games grouped by the platforms
    available.

 src/meson.build            |  1 +
 src/ui/platforms-view.vala | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
---
diff --git a/src/meson.build b/src/meson.build
index 62772da6..db93de81 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -150,6 +150,7 @@ vala_sources = [
   'ui/media-menu-button.vala',
   'ui/message-dialog.vala',
   'ui/platform-list-item.vala',
+  'ui/platforms-view.vala',
   'ui/preferences-page.vala',
   'ui/preferences-page-controllers.vala',
   'ui/preferences-page-plugins.vala',
diff --git a/src/ui/platforms-view.vala b/src/ui/platforms-view.vala
new file mode 100644
index 00000000..16247560
--- /dev/null
+++ b/src/ui/platforms-view.vala
@@ -0,0 +1,32 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.PlatformsView : SidebarView {
+       private GenericSet<Platform> platforms = new GenericSet<Platform> (Platform.hash, Platform.equal);
+
+       protected override void game_added (Game game) {
+               var platform = game.get_platform();
+
+               if (!platforms.contains (platform)) {
+                       platforms.add (platform);
+                       var platform_list_item = new PlatformListItem (platform);
+                       platform_list_item.visible = true;
+                       list_box.add (platform_list_item);
+               }
+       }
+
+       protected override void invalidate (Gtk.ListBoxRow row_item) {
+               var row = row_item.get_child () as PlatformListItem;
+               var platform = row.platform;
+               collection_view.filtering_platform = platform;
+       }
+
+       protected override int sort_rows (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) {
+               var item1 = row1.get_child () as PlatformListItem;
+               var item2 = row2.get_child () as PlatformListItem;
+
+               assert (item1 != null);
+               assert (item2 != null);
+
+               return item1.label.collate (item2.label);
+       }
+}


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