feat(ags4): add rest of subclasses
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2025-01-01 13:38:44 -05:00
parent 362bc7314d
commit 8871cc8f01
16 changed files with 332 additions and 10 deletions

View file

@ -1,7 +1,7 @@
import { App, Astal, Gtk } from 'astal/gtk4';
import { Variable } from 'astal';
import { Box, Button, CenterBox } from './subclasses';
import { Box, Button, Calendar, CenterBox, Label, MenuButton, Popover, Window } from './subclasses';
const { EXCLUSIVE } = Astal.Exclusivity;
const { TOP, LEFT, RIGHT } = Astal.WindowAnchor;
@ -21,7 +21,7 @@ export default () => {
) as Box;
return (
<window
<Window
visible
cssClasses={['Bar']}
exclusivity={EXCLUSIVE}
@ -33,16 +33,16 @@ export default () => {
{styledBox}
<menubutton
<MenuButton
hexpand
halign={CENTER}
>
<label label={time().as(String)} />
<popover>
<Gtk.Calendar />
</popover>
</menubutton>
<Label label={time().as(String)} />
<Popover>
<Calendar />
</Popover>
</MenuButton>
</CenterBox>
</window>
</Window>
);
};

View file

@ -20,8 +20,8 @@ export const filter = (children: any[]) => {
new Gtk.Label({ visible: true, label: String(ch) }));
};
export const type = Symbol('child type');
const dummyBuilder = new Gtk.Builder();
const type = Symbol('child type');
interface EventController<Self extends Gtk.Widget> {
onFocusEnter?: (self: Self) => void

View file

@ -0,0 +1,26 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
type CalendarSignals = Record<`on${string}`, unknown[]> & {
onDaySelected: []
onNextMonth: []
onNextYear: []
onPrevMonth: []
onPrevYear: []
};
export type CalendarProps = ConstructProps<
Calendar,
Gtk.Calendar.ConstructorProps & { css: string },
CalendarSignals
>;
@register({ GTypeName: 'Calendar' })
export class Calendar extends astalify(Gtk.Calendar) {
constructor(props?: CalendarProps) { super(props as any); }
}

View file

@ -0,0 +1,24 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
type EntrySignals = Record<`on${string}`, unknown[]> & {
onActivate: []
onNotifyText: []
};
export type EntryProps = ConstructProps<
Entry,
Gtk.Entry.ConstructorProps & { css: string },
EntrySignals
>;
@register({ GTypeName: 'Entry' })
export class Entry extends astalify(Gtk.Entry) {
constructor(props?: EntryProps) { super(props as any); }
getChildren() { return []; }
}

View file

@ -0,0 +1,19 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
export type ImageProps = ConstructProps<
Image,
Gtk.Image.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'Image' })
export class Image extends astalify(Gtk.Image) {
constructor(props?: ImageProps) { super(props as any); }
getChildren() { return []; }
}

View file

@ -1,3 +1,16 @@
export * from './box';
export * from './button';
export * from './calendar';
export * from './centerbox';
export * from './entry';
export * from './image';
export * from './label';
export * from './levelbar';
export * from './menubutton';
export * from './overlay';
export * from './popover';
export * from './revealer';
export * from './slider';
export * from './stack';
export * from './switch';
export * from './window';

View file

@ -0,0 +1,21 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
export type LabelProps = ConstructProps<
Label,
Gtk.Label.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'Label' })
export class Label extends astalify(Gtk.Label) {
constructor(props?: LabelProps) { super(props as any); }
getChildren() { return []; }
setChildren(self: Label, children: any[]) { self.label = String(children); }
}

View file

@ -0,0 +1,19 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
export type LevelBarProps = ConstructProps<
LevelBar,
Gtk.LevelBar.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'LevelBar' })
export class LevelBar extends astalify(Gtk.LevelBar) {
constructor(props?: LevelBarProps) { super(props as any); }
getChildren() { return []; }
}

View file

@ -0,0 +1,32 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify, { filter } from './astalify';
export type MenuButtonProps = ConstructProps<
MenuButton,
Gtk.MenuButton.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'MenuButton' })
export class MenuButton extends astalify(Gtk.MenuButton) {
constructor(props?: MenuButtonProps) { super(props as any); }
getChildren(self: MenuButton) {
return [self.popover, self.child];
}
setChildren(self: MenuButton, children: any[]) {
for (const child of filter(children)) {
if (child instanceof Gtk.Popover) {
self.set_popover(child);
}
else {
self.set_child(child);
}
}
}
}

View file

@ -0,0 +1,47 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify, { filter, type } from './astalify';
export type OverlayProps = ConstructProps<
Overlay,
Gtk.Overlay.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'Overlay' })
export class Overlay extends astalify(Gtk.Overlay) {
constructor(props?: OverlayProps) { super(props as any); }
getChildren(self: Overlay) {
const children: Gtk.Widget[] = [];
let ch = self.get_first_child();
while (ch !== null) {
children.push(ch);
ch = ch.get_next_sibling();
}
return children.filter((child) => child !== self.child);
}
setChildren(self: Overlay, children: any[]) {
for (const child of filter(children)) {
const types = type in child ?
(child[type] as string).split(/\s+/) :
[];
if (types.includes('overlay')) {
self.add_overlay(child);
}
else {
self.set_child(child);
}
self.set_measure_overlay(child, types.includes('measure'));
self.set_clip_overlay(child, types.includes('clip'));
}
}
}

View file

@ -0,0 +1,17 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
export type PopoverProps = ConstructProps<
Popover,
Gtk.Popover.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'Popover' })
export class Popover extends astalify(Gtk.Popover) {
constructor(props?: PopoverProps) { super(props as any); }
}

View file

@ -0,0 +1,17 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
export type RevealerProps = ConstructProps<
Revealer,
Gtk.Revealer.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'Revealer' })
export class Revealer extends astalify(Gtk.Revealer) {
constructor(props?: RevealerProps) { super(props as any); }
}

View file

@ -0,0 +1,23 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Astal, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
type SliderSignals = Record<`on${string}`, unknown[]> & {
onClicked: []
};
export type SliderProps = ConstructProps<
Slider,
Astal.Slider.ConstructorProps & { css: string },
SliderSignals
>;
@register({ GTypeName: 'Slider' })
export class Slider extends astalify(Astal.Slider) {
constructor(props?: SliderProps) { super(props as any); }
getChildren() { return []; }
}

View file

@ -0,0 +1,28 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify, { filter } from './astalify';
export type StackProps = ConstructProps<
Stack,
Gtk.Stack.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'Stack' })
export class Stack extends astalify(Gtk.Stack) {
constructor(props?: StackProps) { super(props as any); }
setChildren(self: Stack, children: any[]) {
for (const child of filter(children)) {
if (child.name !== '' && child.name !== null) {
self.add_named(child, child.name);
}
else {
self.add_child(child);
}
}
}
}

View file

@ -0,0 +1,19 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
export type SwitchProps = ConstructProps<
Switch,
Gtk.Switch.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'Switch' })
export class Switch extends astalify(Gtk.Switch) {
constructor(props?: SwitchProps) { super(props as any); }
getChildren() { return []; }
}

View file

@ -0,0 +1,17 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { register } from 'astal';
import { Astal, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
export type WindowProps = ConstructProps<
Window,
Astal.Window.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'Window' })
export class Window extends astalify(Astal.Window) {
constructor(props?: WindowProps) { super(props as any); }
}