From b1eef4285fa0d78969be89da140bc25466eea7de Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Sun, 11 May 2025 22:22:21 -0300 Subject: [PATCH] :sparkles: ags(widget/result-widget): add support for widgets and nerd font icons on `icon` prop --- ags/widget/runner/ResultWidget.ts | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/ags/widget/runner/ResultWidget.ts b/ags/widget/runner/ResultWidget.ts index 5c737d1..04800a6 100644 --- a/ags/widget/runner/ResultWidget.ts +++ b/ags/widget/runner/ResultWidget.ts @@ -4,7 +4,7 @@ import { Gtk, Widget } from "astal/gtk3"; export { ResultWidget, ResultWidgetProps }; type ResultWidgetProps = { - icon?: string | Binding; + icon?: string | Binding | Gtk.Widget | Binding; title: string | Binding; description?: string | Binding; closeOnClick?: boolean; @@ -14,10 +14,11 @@ type ResultWidgetProps = { @register({ GTypeName: "ResultWidget" }) class ResultWidget extends Widget.Box { + public readonly onClick: (() => void); - public readonly icon: (string | Binding | undefined); public readonly setup: ((() => void)|undefined); - public readonly closeOnClick: boolean = true; + public icon: (string | Binding | Gtk.Widget | Binding | undefined); + public closeOnClick: boolean = true; constructor(props: ResultWidgetProps) { @@ -31,11 +32,25 @@ class ResultWidget extends Widget.Box { this.closeOnClick = props.closeOnClick ?? true; this.onClick = () => props.onClick?.(); - if(this.icon != null) { - this.add(new Widget.Icon({ - visible: props.icon, - icon: props.icon || "image-missing" - } as Widget.IconProps)); + if(this.icon !== undefined) { + if(this.icon instanceof Binding) { + if(typeof this.icon.get() === "string") { + this.add(new Widget.Icon({ + icon: this.icon as Binding + } as Widget.IconProps)); + } else { + this.add(new Widget.Box({ + child: this.icon as Binding + } as Widget.BoxProps)); + } + } else { + if(typeof this.icon === "string") { + this.add(new Widget.Icon({ + icon: this.icon as string + } as Widget.IconProps)); + } else + this.add(this.icon as Gtk.Widget); + } } this.add(new Widget.Box({