cover: Add width and height properties
This commit is contained in:
@@ -5,27 +5,27 @@ template $Cover: Adw.Bin {
|
|||||||
child: Adw.Clamp {
|
child: Adw.Clamp {
|
||||||
orientation: vertical;
|
orientation: vertical;
|
||||||
unit: px;
|
unit: px;
|
||||||
maximum-size: bind _picture.height-request;
|
maximum-size: bind template.height;
|
||||||
tightening-threshold: bind _picture.height-request;
|
tightening-threshold: bind template.height;
|
||||||
|
|
||||||
child: Adw.Clamp {
|
child: Adw.Clamp {
|
||||||
unit: px;
|
unit: px;
|
||||||
maximum-size: bind _picture.width-request;
|
maximum-size: bind template.width;
|
||||||
tightening-threshold: bind _picture.width-request;
|
tightening-threshold: bind template.width;
|
||||||
|
|
||||||
child: Adw.ViewStack {
|
child: Adw.ViewStack {
|
||||||
name: "cover";
|
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;
|
overflow: hidden;
|
||||||
enable-transitions: true;
|
enable-transitions: true;
|
||||||
|
|
||||||
Adw.ViewStackPage {
|
Adw.ViewStackPage {
|
||||||
name: "cover";
|
name: "cover";
|
||||||
|
|
||||||
child: Picture _picture {
|
child: Picture {
|
||||||
paintable: bind template.paintable;
|
paintable: bind template.paintable;
|
||||||
width-request: 200;
|
width-request: bind template.width;
|
||||||
height-request: 300;
|
height-request: bind template.height;
|
||||||
content-fit: cover;
|
content-fit: cover;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,10 @@ template $Cover: Adw.Bin {
|
|||||||
name: "icon";
|
name: "icon";
|
||||||
|
|
||||||
child: Image {
|
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;
|
pixel-size: 80;
|
||||||
|
|
||||||
styles [
|
styles [
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
from gi.repository import Adw, Gdk, GObject, Gtk
|
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")
|
@Gtk.Template.from_resource(f"{PREFIX}/cover.ui")
|
||||||
@@ -12,12 +12,14 @@ class Cover(Adw.Bin):
|
|||||||
|
|
||||||
__gtype_name__ = __qualname__
|
__gtype_name__ = __qualname__
|
||||||
|
|
||||||
picture = GObject.Property(lambda self: self._picture, type=Gtk.Picture)
|
|
||||||
paintable = GObject.Property(type=Gdk.Paintable)
|
paintable = GObject.Property(type=Gdk.Paintable)
|
||||||
app_icon_name = GObject.Property(type=str, default=f"{APP_ID}-symbolic")
|
width = GObject.Property(type=int, default=200)
|
||||||
|
height = GObject.Property(type=int, default=300)
|
||||||
_picture = Gtk.Template.Child()
|
|
||||||
|
|
||||||
@Gtk.Template.Callback()
|
@Gtk.Template.Callback()
|
||||||
def _get_stack_child(self, _obj, paintable: Gdk.Paintable | None) -> str:
|
def _if_else[T](self, _obj, condition: object, first: T, second: T) -> T:
|
||||||
return "cover" if paintable else "icon"
|
return first if condition else second
|
||||||
|
|
||||||
|
@Gtk.Template.Callback()
|
||||||
|
def _concat(self, _obj, *strings: str) -> str:
|
||||||
|
return "".join(strings)
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ template $GameItem: Box {
|
|||||||
|
|
||||||
Adw.Clamp {
|
Adw.Clamp {
|
||||||
unit: px;
|
unit: px;
|
||||||
maximum-size: bind cover.picture as <Picture>.width-request;
|
maximum-size: bind cover.width;
|
||||||
tightening-threshold: bind cover.picture as <Picture>.width-request;
|
tightening-threshold: bind cover.width;
|
||||||
|
|
||||||
child: Overlay {
|
child: Overlay {
|
||||||
child: $Cover cover {
|
child: $Cover cover {
|
||||||
|
|||||||
Reference in New Issue
Block a user