From 338bf91e2155795cc1cc52a7296dc82c3725aa54 Mon Sep 17 00:00:00 2001 From: Jamie Gravendeel Date: Sat, 27 Dec 2025 18:32:09 +0100 Subject: [PATCH] collection-details: Move from GtkFlowBox to GtkGrid --- cartridges/ui/collection-details.blp | 13 ++++---- cartridges/ui/collection_details.py | 47 ++++++++++++++++++---------- cartridges/ui/style.css | 4 --- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/cartridges/ui/collection-details.blp b/cartridges/ui/collection-details.blp index 1b3ad80..4ec74f7 100644 --- a/cartridges/ui/collection-details.blp +++ b/cartridges/ui/collection-details.blp @@ -49,12 +49,13 @@ template $CollectionDetails: Adw.Dialog { } Adw.PreferencesGroup { - FlowBox icons_box { - min-children-per-line: 7; - - styles [ - "navigation-sidebar", - ] + Grid icons_grid { + column-spacing: 6; + row-spacing: 6; + margin-top: 6; + margin-bottom: 6; + margin-start: 6; + margin-end: 6; } styles [ diff --git a/cartridges/ui/collection_details.py b/cartridges/ui/collection_details.py index 3c8b293..bf019ac 100644 --- a/cartridges/ui/collection_details.py +++ b/cartridges/ui/collection_details.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later # SPDX-FileCopyrightText: Copyright 2025 Jamie Gravendeel +from itertools import product from typing import Any, TypeVar, cast from gi.repository import Adw, Gio, GObject, Gtk @@ -43,10 +44,12 @@ class CollectionDetails(Adw.Dialog): __gtype_name__ = __qualname__ name_entry: Adw.EntryRow = Gtk.Template.Child() - icons_box: Gtk.FlowBox = Gtk.Template.Child() + icons_grid: Gtk.Grid = Gtk.Template.Child() sort_changed = GObject.Signal() + _selected_icon: str + @GObject.Property(type=Collection) def collection(self) -> Collection: """The collection that `self` represents.""" @@ -74,21 +77,33 @@ class CollectionDetails(Adw.Dialog): transform_to=lambda _, text: bool(text), ) - icons = Gtk.StringList.new(tuple(f"{icon}-symbolic" for icon in ICONS)) - self.icons_box.bind_model( - icons, - lambda string: Gtk.FlowBoxChild( - name="collection-icon-child", - child=Gtk.Image.new_from_icon_name(string.props.string), + group_button = None + for index, (row, col) in enumerate(product(range(3), range(7))): + icon = ICONS[index] + + button = Gtk.ToggleButton( + icon_name=f"{icon}-symbolic", + hexpand=True, halign=Gtk.Align.CENTER, - ), - ) - self.icons_box.select_child( - cast( - Gtk.FlowBoxChild, - self.icons_box.get_child_at_index(ICONS.index(self.collection.icon)), ) - ) + button.add_css_class("circular") + button.add_css_class("flat") + + if group_button: + button.props.group = group_button + else: + group_button = button + + button.connect( + "toggled", + lambda _, icon: setattr(self, "_selected_icon", icon), + icon, + ) + + if icon == self.collection.icon: + button.props.active = True + + self.icons_grid.attach(button, col, row, 1, 1) def _apply(self): name = self.name_entry.props.text @@ -97,9 +112,7 @@ class CollectionDetails(Adw.Dialog): if self.collection.in_model: self.emit("sort-changed") - self.collection.icon = ICONS[ - self.icons_box.get_selected_children()[0].get_index() - ] + self.collection.icon = self._selected_icon if not self.collection.in_model: collections.model.append(self.collection) diff --git a/cartridges/ui/style.css b/cartridges/ui/style.css index 8a4b28c..bf438b0 100644 --- a/cartridges/ui/style.css +++ b/cartridges/ui/style.css @@ -64,10 +64,6 @@ filter: saturate(300%) opacity(50%); } -#collection-icon-child { - border-radius: 9999px; -} - @media (prefers-color-scheme: dark) { #details list { background: rgb(from white r g b / 10%);