diff options
author | Aylur <[email protected]> | 2024-06-16 02:40:29 +0200 |
---|---|---|
committer | Aylur <[email protected]> | 2024-06-16 02:40:29 +0200 |
commit | d7884d077d5985a9c653c150cb04bf33e7560415 (patch) | |
tree | 056f7ff1040758155bdb2414b041f33a80b3c9ec | |
parent | 49f0ffcd5df6f15e195ece8f3a9a33ef873638ae (diff) |
fix(gjs): css, class_name setter
-rw-r--r-- | gjs/src/astalify.ts | 28 | ||||
-rw-r--r-- | gjs/src/widgets.ts | 20 |
2 files changed, 32 insertions, 16 deletions
diff --git a/gjs/src/astalify.ts b/gjs/src/astalify.ts index d7f52fa..6e5e5b5 100644 --- a/gjs/src/astalify.ts +++ b/gjs/src/astalify.ts @@ -1,5 +1,5 @@ import Binding, { kebabify, snakeify, type Connectable, type Subscribable } from "./binding.js" -import { Astal, Gtk } from "./imports.js" +import { Astal, Gtk, Gdk } from "./imports.js" import { execAsync } from "./process.js" import Variable from "./variable.js" @@ -128,11 +128,6 @@ function ctor(self: any, config: any = {}, children: any[] = []) { }, []) Object.assign(self, props) - Object.assign(self, { - hook(obj: any, sig: any, callback: any) { - return hook(self, obj, sig, callback) - }, - }) for (const [signal, callback] of onHandlers) { if (typeof callback === "function") { @@ -174,21 +169,37 @@ function ctor(self: any, config: any = {}, children: any[] = []) { function proxify< C extends { new(...args: any[]): any }, >(klass: C) { + klass.prototype.hook = function (obj: any, sig: any, callback: any) { + return hook(this, obj, sig, callback) + } + Object.defineProperty(klass.prototype, "className", { get() { return Astal.widget_get_class_names(this).join(" ") }, set(v) { Astal.widget_set_class_names(this, v.split(/\s+/)) }, }) + klass.prototype.set_class_name = function (name: string) { + this.className = name + } + Object.defineProperty(klass.prototype, "css", { get() { return Astal.widget_get_css(this) }, set(v) { Astal.widget_set_css(this, v) }, }) + klass.prototype.set_css = function (css: string) { + this.css = css + } + Object.defineProperty(klass.prototype, "cursor", { get() { return Astal.widget_get_cursor(this) }, set(v) { Astal.widget_set_cursor(this, v) }, }) + klass.prototype.set_cursor = function (cursor: string) { + this.cursor = cursor + } + const proxy = new Proxy(klass, { construct(_, [conf, ...children]) { const self = new klass @@ -243,6 +254,11 @@ export type ConstructProps< }> & { onDestroy?: (self: Widget<Self>) => unknown onDraw?: (self: Widget<Self>) => unknown + onKeyPressEvent?: (self: Widget<Self>, event: Gdk.Event) => unknown + onKeyReleaseEvent?: (self: Widget<Self>, event: Gdk.Event) => unknown + onButtonPressEvent?: (self: Widget<Self>, event: Gdk.Event) => unknown + onButtonReleaseEvent?: (self: Widget<Self>, event: Gdk.Event) => unknown + onRealize?: (self: Widget<Self>) => unknown setup?: (self: Widget<Self>) => void } diff --git a/gjs/src/widgets.ts b/gjs/src/widgets.ts index c731b02..e363da0 100644 --- a/gjs/src/widgets.ts +++ b/gjs/src/widgets.ts @@ -12,11 +12,11 @@ export type BoxProps = ConstructProps<typeof Astal.Box, Astal.Box.ConstructorPro export const Button = astalify<typeof Astal.Button, ButtonProps, "Button">(Astal.Button) export type ButtonProps = ConstructProps<typeof Astal.Button, Astal.Button.ConstructorProperties, { onClicked: [] - onClick: [event: Astal.ClickEvent], - onClickRelease: [event: Astal.ClickEvent], - onHover: [event: Astal.HoverEvent], - onHoverLost: [event: Astal.HoverEvent], - onScroll: [event: Astal.ScrollEvent], + onClick: [event: Astal.ClickEvent] + onClickRelease: [event: Astal.ClickEvent] + onHover: [event: Astal.HoverEvent] + onHoverLost: [event: Astal.HoverEvent] + onScroll: [event: Astal.ScrollEvent] }> // CenterBox @@ -41,11 +41,11 @@ export type EntryProps = ConstructProps<typeof Gtk.Entry, Gtk.Entry.ConstructorP // EventBox export const EventBox = astalify<typeof Astal.EventBox, EventBoxProps, "EventBox">(Astal.EventBox) export type EventBoxProps = ConstructProps<typeof Astal.EventBox, Astal.EventBox.ConstructorProperties, { - onClick: [event: Astal.ClickEvent], - onClickRelease: [event: Astal.ClickEvent], - onHover: [event: Astal.HoverEvent], - onHoverLost: [event: Astal.HoverEvent], - onScroll: [event: Astal.ScrollEvent], + onClick: [event: Astal.ClickEvent] + onClickRelease: [event: Astal.ClickEvent] + onHover: [event: Astal.HoverEvent] + onHoverLost: [event: Astal.HoverEvent] + onScroll: [event: Astal.ScrollEvent] }> // TODO: Fixed |