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

35 lines
974 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-14 10:12:20 -05:00
import astalify, { type AstalifyProps } from '../astalify';
2025-01-01 13:38:44 -05:00
export type MenuButtonProps = ConstructProps<
2025-01-13 10:51:02 -05:00
MenuButtonClass,
Gtk.MenuButton.ConstructorProps & AstalifyProps
2025-01-01 13:38:44 -05:00
>;
@register({ GTypeName: 'MenuButton' })
2025-01-13 10:51:02 -05:00
export class MenuButtonClass extends astalify(Gtk.MenuButton) {
constructor({ cssName = 'menubutton', ...props }: MenuButtonProps = {}) {
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
getChildren(self: MenuButtonClass) {
2025-01-01 13:38:44 -05:00
return [self.popover, self.child];
}
2025-01-13 10:51:02 -05:00
setChildren(self: MenuButtonClass, children: Gtk.Widget[]) {
for (const child of children) {
2025-01-01 13:38:44 -05:00
if (child instanceof Gtk.Popover) {
self.set_popover(child);
}
else {
self.set_child(child);
}
}
}
}
2025-01-13 10:51:02 -05:00
export const MenuButton = (props?: MenuButtonProps) => new MenuButtonClass(props);