[gnome-music/wip/jfelder/searchview-new-style: 8/15] searchview: Limit artists results to one row
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/searchview-new-style: 8/15] searchview: Limit artists results to one row
- Date: Mon, 5 Aug 2019 21:38:46 +0000 (UTC)
commit 511bd3be02f20abe20dc5ed3e3d8de90e57af913
Author: Jean Felder <jfelder src gnome org>
Date: Mon Aug 5 01:33:18 2019 +0200
searchview: Limit artists results to one row
Artist results need to be displayed on only one row (a row can have up
to 6 results). But, on smaller screens, the row can be changed into
multiple rows. In that event, the latest results should be hidden to
display only one row.
Fix the issue by listening to the "size-allocate" signal of the
flowbox. If the window is too small, the latest results are hidden. If
the window becomes wider, they are displayed again.
gnomemusic/views/searchview.py | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
---
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 8335e11c..a7f5b5dd 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -102,6 +102,8 @@ class SearchView(Gtk.Stack):
"items-changed", self._on_artist_model_items_changed)
self._artist_flowbox.bind_model(
self._artist_filter, self._create_artist_widget)
+ self._artist_flowbox.connect(
+ "size-allocate", self._on_artist_flowbox_size_allocate)
self._on_artist_model_items_changed(self._artist_filter, 0, 0, 0)
self._player = self._application.props.player
@@ -263,6 +265,36 @@ class SearchView(Gtk.Stack):
child = self._album_flowbox.get_child_at_index(i)
child.props.visible = True
+ def _on_artist_flowbox_size_allocate(self, widget, allocation, data=None):
+ nb_children = self._artist_filter.get_n_items()
+ if nb_children == 0:
+ return
+
+ first_child = self._album_flowbox.get_child_at_index(0)
+ child_height = first_child.get_allocation().height
+ if allocation.height > 1.5 * child_height:
+ for i in range(nb_children - 1, -1, -1):
+ child = self._artist_flowbox.get_child_at_index(i)
+ if child.props.visible is True:
+ child.props.visible = False
+ return
+
+ children_hidden = False
+ for idx in range(nb_children):
+ child = self._artist_flowbox.get_child_at_index(idx)
+ if not child.props.visible:
+ children_hidden = True
+ break
+ if children_hidden is False:
+ return
+
+ last_child = self._artist_flowbox.get_child_at_index(idx - 1)
+ last_child_allocation = last_child.get_allocation()
+ child_width = last_child_allocation.width
+ if (last_child_allocation.x + 2 * child_width) < allocation.width:
+ child = self._artist_flowbox.get_child_at_index(idx)
+ child.props.visible = True
+
@Gtk.Template.Callback()
def _on_album_activated(self, widget, child, user_data=None):
corealbum = child.props.corealbum
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]