[gnome-games/wip/aplazas/thumbnail-size: 3/3] collection-icon-view: Use small thumbs on small windows



commit 2b85241f1479be23fa1c8058e48a14e6505fc0e5
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Mon Jul 16 14:37:42 2018 +0200

    collection-icon-view: Use small thumbs on small windows
    
    If the window's width is less than half the width of a 1920×1080 screen,
    display the game thumbnails at half the size to see more of them rather
    than a few huge thumbnails, making Games more usable on small screens.

 data/ui/collection-icon-view.ui  |  1 +
 src/ui/collection-icon-view.vala | 31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
---
diff --git a/data/ui/collection-icon-view.ui b/data/ui/collection-icon-view.ui
index 0b1faf38..65326539 100644
--- a/data/ui/collection-icon-view.ui
+++ b/data/ui/collection-icon-view.ui
@@ -4,6 +4,7 @@
   <template class="GamesCollectionIconView" parent="GtkStack">
     <property name="visible">True</property>
     <property name="can-focus">False</property>
+    <signal name="size-allocate" after="no" handler="on_size_allocate"/>
     <child>
       <object class="GamesEmptyCollection" id="empty_collection">
         <property name="visible">True</property>
diff --git a/src/ui/collection-icon-view.vala b/src/ui/collection-icon-view.vala
index 59cc50f1..b02179b9 100644
--- a/src/ui/collection-icon-view.vala
+++ b/src/ui/collection-icon-view.vala
@@ -42,6 +42,9 @@ private class Games.CollectionIconView : Gtk.Stack {
        [GtkChild]
        private Gtk.FlowBox flow_box;
 
+       // Current size used by the thumbnails.
+       private int current_size;
+
        static construct {
                set_css_name ("gamescollectioniconview");
        }
@@ -133,4 +136,32 @@ private class Games.CollectionIconView : Gtk.Stack {
                        set_visible_child (scrolled_window);
        }
 
+       [GtkCallback]
+       private void on_size_allocate (Gtk.Allocation allocation) {
+               // If the window's width is less than half the width of a 1920×1080
+               // screen, display the game thumbnails at half the size to see more of
+               // them rather than a few huge thumbnails, making Games more usable on
+               // small screens.
+               if (allocation.width < 960)
+                       set_size (128);
+               else
+                       set_size (256);
+       }
+
+       private void set_size (int size) {
+               if (current_size == size)
+                       return;
+
+               flow_box.forall ((child) => {
+                       var flow_box_child = child as Gtk.FlowBoxChild;
+
+                       assert (flow_box_child != null);
+
+                       var game_view = flow_box_child.get_child () as GameIconView;
+
+                       assert (game_view != null);
+
+                       game_view.size = size;
+               });
+       }
 }


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