nixos-configs/modules/ags/gtk4/widget/subclasses/centerbox.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-01-01 02:55:15 -05:00
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
2025-01-13 10:51:02 -05:00
import astalify, { type AstalifyProps } from './astalify';
2025-01-01 02:55:15 -05:00
export type CenterBoxProps = ConstructProps<
2025-01-13 10:51:02 -05:00
CenterBoxClass,
Gtk.CenterBox.ConstructorProps & AstalifyProps
2025-01-01 02:55:15 -05:00
>;
@register({ GTypeName: 'CenterBox' })
2025-01-13 10:51:02 -05:00
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 });
}
2025-01-01 02:55:15 -05:00
2025-01-13 10:51:02 -05:00
getChildren(box: CenterBoxClass) {
2025-01-01 02:55:15 -05:00
return [box.startWidget, box.centerWidget, box.endWidget];
}
2025-01-13 10:51:02 -05:00
setChildren(box: CenterBoxClass, children: (Gtk.Widget | null)[]) {
if (children.length > 3) {
throw new Error('Cannot have more than 3 children in a CenterBox');
}
2025-01-01 02:55:15 -05:00
box.startWidget = children[0] || new Gtk.Box();
box.centerWidget = children[1] || new Gtk.Box();
box.endWidget = children[2] || new Gtk.Box();
2025-01-01 02:55:15 -05:00
}
}
2025-01-13 10:51:02 -05:00
export const CenterBox = (props?: CenterBoxProps) => new CenterBoxClass(props);