[gnome-music/wip/jfelder/searchview-new-style: 7/15] searchview: Limit album results to two rows
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/searchview-new-style: 7/15] searchview: Limit album results to two rows
- Date: Mon, 5 Aug 2019 21:38:41 +0000 (UTC)
commit 597bd7bdb56ea9f6e61a24ca3d260a8cfacd8cd9
Author: Jean Felder <jfelder src gnome org>
Date: Sun Aug 4 21:01:32 2019 +0200
searchview: Limit album results to two rows
Album results need to be displayed on only two rows at most (each row
can have up to 6 results). But, on smaller screens, the rows can be
changed into multiple rows. In that event, the latest results should
be hidden to display only two rows.
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 | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
---
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 45082d52..8335e11c 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -94,6 +94,8 @@ class SearchView(Gtk.Stack):
"items-changed", self._on_album_model_items_changed)
self._album_flowbox.bind_model(
self._album_filter, self._create_album_widget)
+ self._album_flowbox.connect(
+ "size-allocate", self._on_album_flowbox_size_allocate)
self._on_album_model_items_changed(self._album_filter, 0, 0, 0)
self._artist_filter.connect_after(
@@ -227,6 +229,40 @@ class SearchView(Gtk.Stack):
return True
+ def _on_album_flowbox_size_allocate(self, widget, allocation, data=None):
+ nb_children = self._album_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 > 2.5 * child_height:
+ for i in range(nb_children - 1, -1, -1):
+ child = self._album_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._album_flowbox.get_child_at_index(idx)
+ if not child.props.visible:
+ children_hidden = True
+ break
+ if children_hidden is False:
+ return
+
+ last_visible_child = self._album_flowbox.get_child_at_index(idx - 1)
+ first_row_last = self._album_flowbox.get_child_at_index((idx - 1) // 2)
+ second_row_pos = last_visible_child.get_allocation().x
+ first_row_pos = first_row_last.get_allocation().x
+ child_width = last_visible_child.get_allocation().width
+ nb_children_to_add = (first_row_pos - second_row_pos) // child_width
+ nb_children_to_add = min(nb_children_to_add + idx, nb_children)
+ for i in range(idx, nb_children_to_add):
+ child = self._album_flowbox.get_child_at_index(i)
+ 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]