nixos-configs/modules/ags/gtk4/widget/subclasses/centerbox.ts
matt1432 adb36c2b34
All checks were successful
Discord / discord commits (push) Has been skipped
refactor(ags4): use agsV1 syntax
2025-01-13 10:51:02 -05:00

34 lines
1.1 KiB
TypeScript

import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify, { type AstalifyProps } from './astalify';
export type CenterBoxProps = ConstructProps<
CenterBoxClass,
Gtk.CenterBox.ConstructorProps & AstalifyProps
>;
@register({ GTypeName: 'CenterBox' })
export class CenterBoxClass extends astalify(Gtk.CenterBox) {
constructor({ cssName = 'centerbox', ...props }: CenterBoxProps = {}) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
super({ cssName, ...props as any });
}
getChildren(box: CenterBoxClass) {
return [box.startWidget, box.centerWidget, box.endWidget];
}
setChildren(box: CenterBoxClass, children: (Gtk.Widget | null)[]) {
if (children.length > 3) {
throw new Error('Cannot have more than 3 children in a CenterBox');
}
box.startWidget = children[0] || new Gtk.Box();
box.centerWidget = children[1] || new Gtk.Box();
box.endWidget = children[2] || new Gtk.Box();
}
}
export const CenterBox = (props?: CenterBoxProps) => new CenterBoxClass(props);