From 1425b396b08f0e91d45bbd0f92b1309115c7c870 Mon Sep 17 00:00:00 2001 From: Aylur Date: Sun, 19 May 2024 02:39:53 +0200 Subject: init 0.1.0 --- js/node/widgets.ts | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 js/node/widgets.ts (limited to 'js/node/widgets.ts') diff --git a/js/node/widgets.ts b/js/node/widgets.ts new file mode 100644 index 0000000..914821d --- /dev/null +++ b/js/node/widgets.ts @@ -0,0 +1,63 @@ +/* eslint-disable max-len */ +import gi from "node-gtk" +import proxy, { type ConstructProps, type Widget } from "../src/astalify.js" +import type GtkT from "@girs/node-gtk-3.0/node-gtk-3.0" +import type AstalT from "@girs/node-astal-0.1/node-astal-0.1" + +const Astal = gi.require("Astal", "0.1") +const Gtk = gi.require("Gtk", "3.0") + +const proxify = proxy(Gtk, + prop => `set${prop.charAt(0).toUpperCase() + prop.slice(1)}`, + { + cssGetter: Astal.widgetGetCss, + cssSetter: Astal.widgetSetCss, + classGetter: Astal.widgetGetClassNames, + classSetter: Astal.widgetSetClassNames, + cursorGetter: Astal.widgetGetCursor, + cursorSetter: Astal.widgetSetCursor, + }) + +export function astalify< + C extends typeof Gtk.Widget, + P extends Record, + N extends string = "Widget", +>(klass: C) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + type Astal = Omit & { + new(props: P, ...children: GtkT.Widget[]): Widget + (props: P, ...children: GtkT.Widget[]): Widget + } + + return proxify(klass) as unknown as Astal +} + +// Label +export const Label = astalify(Gtk.Label) +export type LabelProps = ConstructProps + +// Icon +export const Icon = astalify(Astal.Icon) +export type IconProps = ConstructProps + +// Button +export const Button = astalify(Astal.Button) +export type ButtonProps = ConstructProps) => void +}> + +// Window +export const Window = astalify(Astal.Window) +export type WindowProps = ConstructProps + +// Box +export const Box = astalify(Astal.Box) +export type BoxProps = ConstructProps + +// CenterBox +export const CenterBox = astalify(Astal.CenterBox) +export type CenterBoxProps = ConstructProps + +// EventBox +export const EventBox = astalify(Astal.EventBox) +export type EventBoxProps = ConstructProps -- cgit v1.2.3