[gnome-music/wip/jfelder/albumwidget-full-scrollarea: 723/723] albumwidget: Enlarge scroll area



commit 3cb3bd5d53fe4a337e55a5f7d6ae13816f6967e2
Author: Jean Felder <jfelder src gnome org>
Date:   Sun Mar 15 14:17:20 2020 +0100

    albumwidget: Enlarge scroll area
    
    The AlbumWidget is made of two boxes: album details on the left and
    the playlist on the right. The scrolled window is only associated with
    the playlist. This allows to have a fixed album details box when a
    scroll operations happens. However, the mouse pointer needs to be
    located inside the list to make a scroll operation.
    
    By adding a GtkEventControllerScroll to the AlbumWidget, it is
    possible to connect to the scroll events and have the whole view area
    act on scroll events.
    
    It needs Gtk 3.24.13 or above because it relies on this change:
    https://gitlab.gnome.org/GNOME/gtk/-/commit/ebd1840802a11f1f0b668064f4ba3c014c47c045
    
    Closes: #13

 data/ui/AlbumWidget.ui            | 10 +++++++++-
 gnomemusic/widgets/albumwidget.py | 24 +++++++++++++++++++++++-
 meson.build                       |  2 +-
 3 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/AlbumWidget.ui b/data/ui/AlbumWidget.ui
index 75d649ac..5de763e5 100644
--- a/data/ui/AlbumWidget.ui
+++ b/data/ui/AlbumWidget.ui
@@ -205,7 +205,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkScrolledWindow" id="scrolledWindow">
+          <object class="GtkScrolledWindow" id="_scrolled_window">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="hexpand">True</property>
@@ -240,4 +240,12 @@
       </object>
     </child>
   </template>
+  <object class="GtkEventControllerScroll" id="_scroll_ctrlr">
+    <property name="widget">AlbumWidget</property>
+    <property name="flags">vertical</property>
+    <property name="propagation-phase">capture</property>
+    <signal name="scroll-begin" handler="_on_scroll_begin" swapped="no"/>
+    <signal name="scroll-end" handler="_on_scroll_end" swapped="no"/>
+    <signal name="scroll" handler="_on_scroll" swapped="no"/>
+  </object>
 </interface>
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index d75b1fe2..a64970ef 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -24,7 +24,7 @@
 
 from gettext import ngettext
 
-from gi.repository import GObject, Grl, Gtk
+from gi.repository import Gdk, GObject, Grl, Gtk
 
 from gnomemusic.albumartcache import Art
 from gnomemusic.player import PlayerPlaylist
@@ -49,6 +49,8 @@ class AlbumWidget(Gtk.EventBox):
     _disc_list_box = Gtk.Template.Child()
     _released_info_label = Gtk.Template.Child()
     _running_info_label = Gtk.Template.Child()
+    _scroll_ctrlr = Gtk.Template.Child()
+    _scrolled_window = Gtk.Template.Child()
     _title_label = Gtk.Template.Child()
 
     selection_mode = GObject.Property(type=bool, default=False)
@@ -201,3 +203,23 @@ class AlbumWidget(Gtk.EventBox):
         :rtype: CoreAlbum
         """
         return self._corealbum
+
+    @Gtk.Template.Callback()
+    def _on_scroll_begin(self, widget):
+        gdk_window = self.get_window()
+        self._cursor = gdk_window.get_cursor()
+
+        display = gdk_window.get_display()
+        new_cursor = Gdk.Cursor.new_from_name(display, "all-scroll")
+        gdk_window.set_cursor(new_cursor)
+
+    @Gtk.Template.Callback()
+    def _on_scroll_end(self, widget):
+        gdk_window = self.get_window()
+        gdk_window.set_cursor(self._cursor)
+
+    @Gtk.Template.Callback()
+    def _on_scroll(self, controller, dx, dy):
+        vadjustment = self._scrolled_window.props.vadjustment
+        vadjustment.props.value += dy * vadjustment.props.step_increment
+        return True
diff --git a/meson.build b/meson.build
index db526527..a373324b 100644
--- a/meson.build
+++ b/meson.build
@@ -38,7 +38,7 @@ PKGLIB_DIR = join_paths(get_option('prefix'), get_option('libdir'), APPLICATION_
 # Dependencies
 dependency('goa-1.0', version: '>= 3.35.90')
 dependency('gobject-introspection-1.0', version: '>= 1.35.0')
-dependency('gtk+-3.0', version: '>= 3.24.7')
+dependency('gtk+-3.0', version: '>= 3.24.13')
 dependency('libdazzle-1.0', version: '>= 3.28.0')
 dependency('libmediaart-2.0', version: '>= 1.9.1')
 dependency('libsoup-2.4')


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