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

31 lines
948 B
TypeScript
Raw Normal View History

2025-01-01 02:55:15 -05:00
import { register } from 'astal';
import { Gtk, type ConstructProps } from 'astal/gtk4';
import astalify from './astalify';
2025-01-01 02:55:15 -05:00
export type CenterBoxProps = ConstructProps<
CenterBox,
Gtk.CenterBox.ConstructorProps & { css: string }
>;
@register({ GTypeName: 'CenterBox' })
export class CenterBox extends astalify(Gtk.CenterBox) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2025-01-01 02:55:15 -05:00
constructor(props?: CenterBoxProps) { super(props as any); }
getChildren(box: CenterBox) {
return [box.startWidget, box.centerWidget, box.endWidget];
}
setChildren(box: CenterBox, 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
}
}