From 2fa83eb09047e603835c462ff0d8a04eba016807 Mon Sep 17 00:00:00 2001 From: Aylur Date: Wed, 9 Oct 2024 02:52:02 +0000 Subject: gjs: refactor widgets into classes --- core/gjs/src/widgets.ts | 119 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 40 deletions(-) (limited to 'core/gjs/src/widgets.ts') diff --git a/core/gjs/src/widgets.ts b/core/gjs/src/widgets.ts index 0c30b51..50fe303 100644 --- a/core/gjs/src/widgets.ts +++ b/core/gjs/src/widgets.ts @@ -1,17 +1,22 @@ /* eslint-disable max-len */ -import { Astal, Gtk } from "./imports.js" -import astalify, { type ConstructProps, type Widget } from "./astalify.js" +import { Astal, GObject, Gtk } from "./imports.js" +import astalify, { type ConstructProps, type BindableChild } from "./astalify.js" export { astalify, ConstructProps } // Box -export type Box = Widget -export const Box = astalify(Astal.Box) +Object.defineProperty(Astal.Box.prototype, "children", { + get() { return this.get_children() }, + set(v) { this.set_children(v) }, +}) + export type BoxProps = ConstructProps +export class Box extends astalify(Astal.Box) { + static { GObject.registerClass({ GTypeName: "Box" }, this) } + constructor(props?: BoxProps, ...children: Array) { super({ children, ...props } as any) } +} // Button -export type Button = Widget -export const Button = astalify(Astal.Button) export type ButtonProps = ConstructProps +export class Button extends astalify(Astal.Button) { + static { GObject.registerClass({ GTypeName: "Button" }, this) } + constructor(props?: ButtonProps, child?: BindableChild) { super({ child, ...props } as any) } +} // CenterBox -export type CenterBox = Widget -export const CenterBox = astalify(Astal.CenterBox) export type CenterBoxProps = ConstructProps +export class CenterBox extends astalify(Astal.CenterBox) { + static { GObject.registerClass({ GTypeName: "CenterBox" }, this) } + constructor(props?: CenterBoxProps, ...children: Array) { super({ children, ...props } as any) } +} // CircularProgress -export type CircularProgress = Widget -export const CircularProgress = astalify(Astal.CircularProgress) export type CircularProgressProps = ConstructProps +export class CircularProgress extends astalify(Astal.CircularProgress) { + static { GObject.registerClass({ GTypeName: "CircularProgress" }, this) } + constructor(props?: CircularProgressProps, child?: BindableChild) { super({ child, ...props } as any) } +} // DrawingArea -export type DrawingArea = Widget -export const DrawingArea = astalify(Gtk.DrawingArea) export type DrawingAreaProps = ConstructProps +export class DrawingArea extends astalify(Gtk.DrawingArea) { + static { GObject.registerClass({ GTypeName: "DrawingArea" }, this) } + constructor(props?: DrawingAreaProps) { super(props as any) } +} // Entry -export type Entry = Widget -export const Entry = astalify(Gtk.Entry) export type EntryProps = ConstructProps +export class Entry extends astalify(Gtk.Entry) { + static { GObject.registerClass({ GTypeName: "Entry" }, this) } + constructor(props?: EntryProps) { super(props as any) } +} // EventBox -export type EventBox = Widget -export const EventBox = astalify(Astal.EventBox) export type EventBoxProps = ConstructProps - -// TODO: Fixed -// TODO: FlowBox - +export class EventBox extends astalify(Astal.EventBox) { + static { GObject.registerClass({ GTypeName: "EventBox" }, this) } + constructor(props?: EventBoxProps, child?: BindableChild) { super({ child, ...props } as any) } +} + +// // TODO: Fixed +// // TODO: FlowBox +// // Icon -export type Icon = Widget -export const Icon = astalify(Astal.Icon) export type IconProps = ConstructProps +export class Icon extends astalify(Astal.Icon) { + static { GObject.registerClass({ GTypeName: "Icon" }, this) } + constructor(props?: IconProps) { super(props as any) } +} // Label -export type Label = Widget -export const Label = astalify(Astal.Label) export type LabelProps = ConstructProps +export class Label extends astalify(Astal.Label) { + static { GObject.registerClass({ GTypeName: "Label" }, this) } + constructor(props?: LabelProps) { super(props as any) } +} // LevelBar -export type LevelBar = Widget -export const LevelBar = astalify(Astal.LevelBar) export type LevelBarProps = ConstructProps +export class LevelBar extends astalify(Astal.LevelBar) { + static { GObject.registerClass({ GTypeName: "LevelBar" }, this) } + constructor(props?: LevelBarProps) { super(props as any) } +} // TODO: ListBox // Overlay -export type Overlay = Widget -export const Overlay = astalify(Astal.Overlay) export type OverlayProps = ConstructProps +export class Overlay extends astalify(Astal.Overlay) { + static { GObject.registerClass({ GTypeName: "Overlay" }, this) } + constructor(props?: OverlayProps, ...children: Array) { super({ children, ...props } as any) } +} // Revealer -export type Revealer = Widget -export const Revealer = astalify(Gtk.Revealer) export type RevealerProps = ConstructProps +export class Revealer extends astalify(Gtk.Revealer) { + static { GObject.registerClass({ GTypeName: "Revealer" }, this) } + constructor(props?: RevealerProps, child?: BindableChild) { super({ child, ...props } as any) } +} // Scrollable -export type Scrollable = Widget -export const Scrollable = astalify(Astal.Scrollable) export type ScrollableProps = ConstructProps +export class Scrollable extends astalify(Astal.Scrollable) { + static { GObject.registerClass({ GTypeName: "Scrollable" }, this) } + constructor(props?: ScrollableProps, child?: BindableChild) { super({ child, ...props } as any) } +} // Slider -export type Slider = Widget -export const Slider = astalify(Astal.Slider) export type SliderProps = ConstructProps +export class Slider extends astalify(Astal.Slider) { + static { GObject.registerClass({ GTypeName: "Slider" }, this) } + constructor(props?: SliderProps) { super(props as any) } +} // Stack -export type Stack = Widget -export const Stack = astalify(Astal.Stack) export type StackProps = ConstructProps +export class Stack extends astalify(Astal.Stack) { + static { GObject.registerClass({ GTypeName: "Stack" }, this) } + constructor(props?: StackProps, ...children: Array) { super({ children, ...props } as any) } +} // Switch -export type Switch = Widget -export const Switch = astalify(Gtk.Switch) export type SwitchProps = ConstructProps +export class Switch extends astalify(Gtk.Switch) { + static { GObject.registerClass({ GTypeName: "Switch" }, this) } + constructor(props?: SwitchProps) { super(props as any) } +} // Window -export type Window = Widget -export const Window = astalify(Astal.Window) export type WindowProps = ConstructProps +export class Window extends astalify(Astal.Window) { + static { GObject.registerClass({ GTypeName: "Window" }, this) } + constructor(props?: WindowProps, child?: BindableChild) { super({ child, ...props } as any) } +} -- cgit v1.2.3