cover: Add placeholder icon

This commit is contained in:
kramo
2025-11-30 18:12:43 +01:00
committed by Laura Kramolis
parent 52a01f9225
commit bea060b67f
2 changed files with 36 additions and 9 deletions

View File

@@ -8,21 +8,43 @@ template $Cover: Adw.Bin {
maximum-size: bind picture.height-request;
tightening-threshold: bind picture.height-request;
Adw.Clamp {
child: Adw.Clamp {
unit: px;
maximum-size: bind picture.width-request;
tightening-threshold: bind picture.width-request;
Picture picture {
paintable: bind template.paintable;
width-request: 200;
height-request: 300;
content-fit: cover;
child: Stack {
visible-child-name: bind $_get_stack_child(template.paintable) as <string>;
overflow: hidden;
StackPage {
name: "cover";
child: Picture picture {
paintable: bind template.paintable;
width-request: 200;
height-request: 300;
content-fit: cover;
};
}
StackPage {
name: "icon";
child: Image {
icon-name: bind template.app-icon-name;
pixel-size: 80;
styles [
"dimmed",
]
};
}
styles [
"card",
]
}
}
};
};
};
}

View File

@@ -3,7 +3,7 @@
from gi.repository import Adw, Gdk, GObject, Gtk
from cartridges.config import PREFIX
from cartridges.config import APP_ID, PREFIX
@Gtk.Template.from_resource(f"{PREFIX}/cover.ui")
@@ -13,3 +13,8 @@ class Cover(Adw.Bin):
__gtype_name__ = __qualname__
paintable = GObject.Property(type=Gdk.Paintable)
app_icon_name = GObject.Property(type=str, default=f"{APP_ID}-symbolic")
@Gtk.Template.Callback()
def _get_stack_child(self, _obj, paintable: Gdk.Paintable | None) -> str:
return "cover" if paintable else "icon"