[gnome-games] ui: Introduce CollectionsPage
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ui: Introduce CollectionsPage
- Date: Thu, 16 Jul 2020 14:50:33 +0000 (UTC)
commit 8e037186ba6414a67bb21abaa5400b455d46165f
Author: Neville <nevilleantony98 gmail com>
Date: Thu Jun 18 20:49:04 2020 +0530
ui: Introduce CollectionsPage
This will be used to display collections and games which belongs to a
collection. The ui structure is as follows:
GamesCollectionsPage
Hdy.Deck
CollectionsMainPage
Stack (subpage_stack)
GamesPage
EmptyPage
data/org.gnome.Games.gresource.xml | 1 +
data/ui/collections-page.ui | 43 +++++++++++
src/meson.build | 1 +
src/ui/collections-page.vala | 146 +++++++++++++++++++++++++++++++++++++
4 files changed, 191 insertions(+)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 0487f908..e8030e51 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -16,6 +16,7 @@
<file preprocess="xml-stripblanks">ui/collection-icon-view.ui</file>
<file preprocess="xml-stripblanks">ui/collection-view.ui</file>
<file preprocess="xml-stripblanks">ui/collections-main-page.ui</file>
+ <file preprocess="xml-stripblanks">ui/collections-page.ui</file>
<file preprocess="xml-stripblanks">ui/display-view.ui</file>
<file preprocess="xml-stripblanks">ui/empty-collection.ui</file>
<file preprocess="xml-stripblanks">ui/empty-search.ui</file>
diff --git a/data/ui/collections-page.ui b/data/ui/collections-page.ui
new file mode 100644
index 00000000..08b3ff67
--- /dev/null
+++ b/data/ui/collections-page.ui
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.24"/>
+ <template class="GamesCollectionsPage" parent="GtkBin">
+ <property name="visible">True</property>
+ <signal name="notify::is-search-mode" handler="update_can_swipe_back"/>
+ <signal name="notify::is-selection-mode" handler="update_can_swipe_back"/>
+ <child>
+ <object class="HdyDeck" id="collections_deck">
+ <property name="visible">True</property>
+ <property name="visible-child">collections_main_page</property>
+ <property name="can-swipe-back" bind-source="GamesCollectionsPage" bind-property="can-swipe-back"/>
+ <signal name="notify::visible-child" handler="on_visible_child_changed"/>
+ <child>
+ <object class="GamesCollectionsMainPage" id="collections_main_page">
+ <property name="visible">True</property>
+ <signal name="collection-activated" handler="on_collection_activated"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkStack" id="collections_subpage_stack">
+ <property name="visible">True</property>
+ <property name="visible-child">collections_subpage</property>
+ <child>
+ <object class="GamesGamesPage" id="collections_subpage">
+ <property name="visible">True</property>
+ <property name="is-selection-mode" bind-source="GamesCollectionsPage"
bind-property="is-selection-mode"/>
+ <signal name="game-activated" handler="on_game_activated"/>
+ <signal name="gamepad-cancel-clicked" handler="on_subpage_back_clicked"/>
+ <style>
+ <class name="gamesgamespage"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GamesCollectionEmpty" id="collection_empty_subpage"/>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
\ No newline at end of file
diff --git a/src/meson.build b/src/meson.build
index 60bd5971..71610442 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -113,6 +113,7 @@ vala_sources = [
'ui/collection-icon-view.vala',
'ui/collection-view.vala',
'ui/collections-main-page.vala',
+ 'ui/collections-page.vala',
'ui/display-bin.vala',
'ui/display-view.vala',
'ui/empty-collection.vala',
diff --git a/src/ui/collections-page.vala b/src/ui/collections-page.vala
new file mode 100644
index 00000000..d3e1a53f
--- /dev/null
+++ b/src/ui/collections-page.vala
@@ -0,0 +1,146 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/collections-page.ui")]
+private class Games.CollectionsPage : Gtk.Bin {
+ public signal void game_activated (Game game);
+ public signal void selected_items_changed ();
+
+ [GtkChild]
+ private Hdy.Deck collections_deck;
+ [GtkChild]
+ private CollectionsMainPage collections_main_page;
+ [GtkChild]
+ private Gtk.Stack collections_subpage_stack;
+ [GtkChild]
+ private GamesPage collections_subpage;
+ [GtkChild]
+ private CollectionEmpty collection_empty_subpage;
+
+ private bool _is_empty_collection;
+ public bool is_empty_collection {
+ get { return _is_empty_collection; }
+ set {
+ _is_empty_collection = value;
+
+ if (is_empty_collection)
+ collections_subpage_stack.visible_child = collection_empty_subpage;
+ else
+ collections_subpage_stack.visible_child = collections_subpage;
+ }
+ }
+
+ public CollectionModel collection_model {
+ get { return collections_main_page.collection_model; }
+ set {
+ collections_main_page.collection_model = value;
+ }
+ }
+
+ public bool is_search_mode { get; set; }
+ public bool is_subpage_open { get; set; }
+ public bool is_selection_mode { get; set; }
+ public bool can_swipe_back { get; set; }
+ public string collection_title { get; set; }
+
+ construct {
+ collections_main_page.gamepad_accepted.connect (() => {
+ collections_subpage.select_default_game (Gtk.DirectionType.RIGHT);
+ });
+ collections_subpage.selected_items_changed.connect (() => {
+ selected_items_changed ();
+ });
+ update_can_swipe_back ();
+ }
+
+ public void select_all () {
+ if (is_subpage_open)
+ collections_subpage.select_all ();
+ }
+
+ public void select_none () {
+ if (is_subpage_open)
+ collections_subpage.select_none ();
+ }
+
+ public Game[] get_selected_games () {
+ return collections_subpage.get_selected_games ();
+ }
+
+ public bool gamepad_button_press_event (Manette.Event event) {
+ return is_subpage_open ? collections_subpage.gamepad_button_press_event (event) :
+ collections_main_page.gamepad_button_press_event (event);
+ }
+
+ public bool gamepad_button_release_event (Manette.Event event) {
+ return is_subpage_open ? collections_subpage.gamepad_button_release_event (event) :
+ collections_main_page.gamepad_button_release_event (event);
+ }
+
+ public bool gamepad_absolute_axis_event (Manette.Event event) {
+ return is_subpage_open ? collections_subpage.gamepad_absolute_axis_event (event) :
+ collections_main_page.gamepad_absolute_axis_event (event);
+ }
+
+ public void reset_scroll_position () {
+ if (is_subpage_open)
+ collections_subpage.reset_scroll_position ();
+ else
+ collections_main_page.reset_scroll_position ();
+ }
+
+ public void update_is_empty_collection () {
+ is_empty_collection = collections_subpage.game_model.get_n_items () == 0;
+ }
+
+ public void set_filter (string[] filtering_terms) {
+ if (is_subpage_open)
+ collections_subpage.set_filter (filtering_terms);
+ }
+
+ public Hdy.Deck get_collections_deck () {
+ return collections_deck;
+ }
+
+ public bool exit_subpage () {
+ return on_subpage_back_clicked ();
+ }
+
+ [GtkCallback]
+ private bool on_subpage_back_clicked () {
+ if (!is_subpage_open)
+ return false;
+
+ is_search_mode = false;
+ collections_deck.visible_child = collections_main_page;
+ return true;
+ }
+
+ [GtkCallback]
+ private void on_collection_activated (Collection collection) {
+ collection_title = collection.get_title ();
+ collections_deck.visible_child = collections_subpage_stack;
+
+ is_empty_collection = collection.get_game_model ().get_n_items () == 0;
+ if (is_empty_collection)
+ return;
+
+ collections_subpage.hide_stars = collection.get_hide_stars ();
+ collections_subpage.game_model = collection.get_game_model ();
+ collections_subpage.reset_scroll_position ();
+ }
+
+ [GtkCallback]
+ private void on_game_activated (Game game) {
+ game_activated (game);
+ }
+
+ [GtkCallback]
+ private void on_visible_child_changed () {
+ is_subpage_open = collections_deck.visible_child == collections_subpage_stack;
+ }
+
+ [GtkCallback]
+ private void update_can_swipe_back () {
+ can_swipe_back = !is_search_mode && !is_selection_mode;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]