[gnome-games/wip/aplazas/gamepad-navigation: 5/7] collection-icon-view: Add game selection accessors
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/gamepad-navigation: 5/7] collection-icon-view: Add game selection accessors
- Date: Sun, 5 Aug 2018 13:08:01 +0000 (UTC)
commit 724dbc24d7b359ef4329b3abbb79942e5ad4b9f6
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun Aug 5 14:44:48 2018 +0200
collection-icon-view: Add game selection accessors
Add has_game_selected(), select_default_game() and unselect_game()
methods to allow the sidebar view to control access to its collection
icon view.
src/ui/collection-icon-view.vala | 39 +++++++++++++++++++++++++++++----------
1 file changed, 29 insertions(+), 10 deletions(-)
---
diff --git a/src/ui/collection-icon-view.vala b/src/ui/collection-icon-view.vala
index 93fd7cb0..a740c950 100644
--- a/src/ui/collection-icon-view.vala
+++ b/src/ui/collection-icon-view.vala
@@ -103,20 +103,39 @@ private class Games.CollectionIconView : Gtk.Stack {
adjustment.set_value (0);
}
- [GtkCallback]
- private bool on_gamepad_browse (Gtk.DirectionType direction) {
- if (flow_box.get_selected_children ().length () == 0) {
- var first_child = flow_box.get_child_at_index (0);
- if (first_child == null)
- return false;
+ public bool has_game_selected () {
+ foreach (var child in flow_box.get_selected_children ())
+ if (child.get_mapped ())
+ return true;
- flow_box.select_child (first_child);
- // This is needed to start moving the cursor with the gamepad only.
- first_child.focus (direction);
+ return false;
+ }
- return true;
+ public bool select_default_game (Gtk.DirectionType direction) {
+ Gtk.FlowBoxChild? child;
+ for (int i = 0; (child = flow_box.get_child_at_index (i)) != null; i++) {
+ if (child.get_mapped ()) {
+ flow_box.select_child (child);
+ // This is needed to start moving the cursor with the gamepad only.
+ child.focus (direction);
+
+ return true;
+ }
}
+ return false;
+ }
+
+ public void unselect_game () {
+ flow_box.unselect_all ();
+ }
+
+ [GtkCallback]
+ private bool on_gamepad_browse (Gtk.DirectionType direction) {
+ if (!has_game_selected ())
+ // This is needed to start moving the cursor with the gamepad only.
+ return select_default_game (direction);
+
switch (direction) {
case Gtk.DirectionType.UP:
return flow_box.move_cursor (Gtk.MovementStep.DISPLAY_LINES, -1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]