cover: Add width and height properties

This commit is contained in:
Jamie Gravendeel
2026-01-05 19:43:38 +01:00
parent 1aee234cbf
commit f9cb794394
3 changed files with 23 additions and 18 deletions

View File

@@ -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 <string>;
visible-child-name: bind $_if_else(template.paintable, "cover", "icon") as <string>;
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 <Window>.application as <Application>.application-id,
"-symbolic"
) as <string>;
pixel-size: 80;
styles [

View File

@@ -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)

View File

@@ -12,8 +12,8 @@ template $GameItem: Box {
Adw.Clamp {
unit: px;
maximum-size: bind cover.picture as <Picture>.width-request;
tightening-threshold: bind cover.picture as <Picture>.width-request;
maximum-size: bind cover.width;
tightening-threshold: bind cover.width;
child: Overlay {
child: $Cover cover {