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

31 lines
844 B
TypeScript
Raw Normal View History

2025-01-01 13:38:44 -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 13:38:44 -05:00
export type StackProps = ConstructProps<
2025-01-13 10:51:02 -05:00
StackClass,
Gtk.Stack.ConstructorProps & AstalifyProps
2025-01-01 13:38:44 -05:00
>;
@register({ GTypeName: 'Stack' })
2025-01-13 10:51:02 -05:00
export class StackClass extends astalify(Gtk.Stack) {
constructor({ cssName = 'stack', ...props }: StackProps = {}) {
super({ cssName, ...props });
2025-01-13 10:51:02 -05:00
}
2025-01-01 13:38:44 -05:00
2025-01-13 10:51:02 -05:00
setChildren(self: StackClass, children: Gtk.Widget[]) {
for (const child of children) {
2025-01-01 13:38:44 -05:00
if (child.name !== '' && child.name !== null) {
self.add_named(child, child.name);
}
else {
self.add_child(child);
}
}
}
}
2025-01-13 10:51:02 -05:00
export const Stack = (props?: StackProps) => new StackClass(props);