import { Gtk } from "ags/gtk4"; import { Separator } from "../../../widget/Separator"; import { Accessor, createBinding, createRoot, For, Node } from "ags"; import { gtype, property, register } from "ags/gobject"; import { variableToBoolean } from "../../../modules/utils"; import Pango from "gi://Pango?version=1.0"; import GObject from "gi://GObject?version=2.0"; export type BottomButton = { title: string | Accessor; description?: string | Accessor; tooltipText?: string | Accessor; tooltipMarkup?: string | Accessor; actionClicked?: () => void; }; export type HeaderButton = { label?: string|Accessor; icon: string|Accessor; tooltipText?: string | Accessor; tooltipMarkup?: string | Accessor; actionClicked?: () => void; }; @register({ GTypeName: "Page" }) export class Page extends GObject.Object { readonly #id: string; readonly #create: () => Node; public readonly actionClosed?: () => void; public readonly actionOpen?: () => void; public get id() { return this.#id; } @property(String) title: string; @property(gtype(String)) description: string|null = null; @property(gtype(Number)) orientation: Gtk.Orientation = Gtk.Orientation.VERTICAL; @property(Number) spacing: number = 4; @property(Array) headerButtons: Array = []; @property(Array) bottomButtons: Array = []; constructor(props: { id: string; title: string; description?: string; headerButtons?: Array; bottomButtons?: Array; orientation?: Gtk.Orientation; spacing?: number; content: () => Node; actionOpen?: () => void; actionClosed?: () => void; }) { super(); this.#id = props.id; this.#create = props.content; this.title = props.title; this.actionClosed = props.actionClosed; this.actionOpen = props.actionOpen; if(props.orientation != null) this.orientation = props.orientation; if(props.description != null) this.description = props.description; if(props.spacing != null) this.spacing = props.spacing; if(props.headerButtons != null) this.headerButtons = props.headerButtons; if(props.bottomButtons != null) this.bottomButtons = props.bottomButtons; if(props.actionOpen != null) this.actionOpen = props.actionOpen; if(props.actionClosed != null) this.actionClosed = props.actionClosed; } public create(): Gtk.Box { return createRoot((dispose) => dispose()}> desc ?? "" )} xalign={0} ellipsize={Pango.EllipsizeMode.END} visible={variableToBoolean(createBinding(this, "description"))} /> {(button: HeaderButton) => button.actionClicked?.()} tooltipText={button.tooltipText} tooltipMarkup={button.tooltipMarkup} /> } {this.#create()} {(button: BottomButton) => button.actionClicked?.()} tooltipText={button.tooltipText} tooltipMarkup={button.tooltipMarkup} title={button.title} description={button.description} /> } as Gtk.Box ); } public static getContent(pageWidget: Gtk.Box) { return pageWidget.get_first_child()!.get_next_sibling()! as Gtk.Box; } } export function PageButton({ onUnmap, ...props }: { class?: string | Accessor; icon?: string | Accessor; title: string | Accessor; endWidget?: Node; description?: string | Accessor; extraButtons?: Node; maxWidthChars?: number | Accessor; onUnmap?: (self: Gtk.Box) => void; actionClicked?: (self: Gtk.Button) => void; tooltipText?: string | Accessor; tooltipMarkup?: string | Accessor; }): Gtk.Box { return onUnmap?.(self)} class={"page-button"}> {props.icon && } {props.endWidget && props.endWidget} {props.extraButtons as Node} as Gtk.Box; }