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/gjs/widgets.ts | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 js/gjs/widgets.ts (limited to 'js/gjs/widgets.ts') diff --git a/js/gjs/widgets.ts b/js/gjs/widgets.ts new file mode 100644 index 0000000..29af9a2 --- /dev/null +++ b/js/gjs/widgets.ts @@ -0,0 +1,60 @@ +/* eslint-disable max-len */ +import Gtk from "gi://Gtk" +import Astal from "gi://Astal" +import { kebabify } from "../src/binding.js" +import proxy, { type ConstructProps, type Widget } from "../src/astalify.js" + +const proxify = proxy(Gtk, + prop => `set_${kebabify(prop).replaceAll("-", "_")}`, + { + cssGetter: Astal.widget_get_css, + cssSetter: Astal.widget_set_css, + classGetter: Astal.widget_get_class_names, + classSetter: Astal.widget_set_class_names, + cursorGetter: Astal.widget_get_cursor, + cursorSetter: Astal.widget_set_cursor, + }) + +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: Gtk.Widget[]): Widget + (props?: P, ...children: Gtk.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