diff --git a/cartridges/ui/cover.blp b/cartridges/ui/cover.blp index 1e6a225..c0e1045 100644 --- a/cartridges/ui/cover.blp +++ b/cartridges/ui/cover.blp @@ -5,27 +5,27 @@ template $Cover: Adw.Bin { child: Adw.Clamp { orientation: vertical; unit: px; - maximum-size: bind _picture.height-request; - tightening-threshold: bind _picture.height-request; + maximum-size: bind template.height; + tightening-threshold: bind template.height; child: Adw.Clamp { unit: px; - maximum-size: bind _picture.width-request; - tightening-threshold: bind _picture.width-request; + maximum-size: bind template.width; + tightening-threshold: bind template.width; child: Adw.ViewStack { name: "cover"; - visible-child-name: bind $_get_stack_child(template.paintable) as ; + visible-child-name: bind $_if_else(template.paintable, "cover", "icon") as ; overflow: hidden; enable-transitions: true; Adw.ViewStackPage { name: "cover"; - child: Picture _picture { + child: Picture { paintable: bind template.paintable; - width-request: 200; - height-request: 300; + width-request: bind template.width; + height-request: bind template.height; content-fit: cover; }; } @@ -34,7 +34,10 @@ template $Cover: Adw.Bin { name: "icon"; child: Image { - icon-name: bind template.app-icon-name; + icon-name: bind $_concat( + template.root as .application as .application-id, + "-symbolic" + ) as ; pixel-size: 80; styles [ diff --git a/cartridges/ui/cover.py b/cartridges/ui/cover.py index f70e376..0178ebc 100644 --- a/cartridges/ui/cover.py +++ b/cartridges/ui/cover.py @@ -3,7 +3,7 @@ from gi.repository import Adw, Gdk, GObject, Gtk -from cartridges.config import APP_ID, PREFIX +from cartridges.config import PREFIX @Gtk.Template.from_resource(f"{PREFIX}/cover.ui") @@ -12,12 +12,14 @@ class Cover(Adw.Bin): __gtype_name__ = __qualname__ - picture = GObject.Property(lambda self: self._picture, type=Gtk.Picture) paintable = GObject.Property(type=Gdk.Paintable) - app_icon_name = GObject.Property(type=str, default=f"{APP_ID}-symbolic") - - _picture = Gtk.Template.Child() + width = GObject.Property(type=int, default=200) + height = GObject.Property(type=int, default=300) @Gtk.Template.Callback() - def _get_stack_child(self, _obj, paintable: Gdk.Paintable | None) -> str: - return "cover" if paintable else "icon" + def _if_else[T](self, _obj, condition: object, first: T, second: T) -> T: + return first if condition else second + + @Gtk.Template.Callback() + def _concat(self, _obj, *strings: str) -> str: + return "".join(strings) diff --git a/cartridges/ui/game-item.blp b/cartridges/ui/game-item.blp index 2b66027..a88cf52 100644 --- a/cartridges/ui/game-item.blp +++ b/cartridges/ui/game-item.blp @@ -12,8 +12,8 @@ template $GameItem: Box { Adw.Clamp { unit: px; - maximum-size: bind cover.picture as .width-request; - tightening-threshold: bind cover.picture as .width-request; + maximum-size: bind cover.width; + tightening-threshold: bind cover.width; child: Overlay { child: $Cover cover {