2025-01-01 13:38:44 -05:00
|
|
|
import { register } from 'astal';
|
2025-01-15 18:17:27 -05:00
|
|
|
import { Gtk } from 'astal/gtk4';
|
2025-01-01 13:38:44 -05:00
|
|
|
|
2025-01-15 18:17:27 -05:00
|
|
|
import astalify, { childType, type AstalifyProps, type ConstructProps } from '../astalify';
|
2025-01-01 13:38:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
export type OverlayProps = ConstructProps<
|
2025-01-13 10:51:02 -05:00
|
|
|
OverlayClass,
|
|
|
|
Gtk.Overlay.ConstructorProps & AstalifyProps
|
2025-01-01 13:38:44 -05:00
|
|
|
>;
|
|
|
|
|
|
|
|
@register({ GTypeName: 'Overlay' })
|
2025-01-13 10:51:02 -05:00
|
|
|
export class OverlayClass extends astalify(Gtk.Overlay) {
|
|
|
|
constructor({ cssName = 'overlay', ...props }: OverlayProps = {}) {
|
2025-01-14 00:09:11 -05:00
|
|
|
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: OverlayClass) {
|
2025-01-01 13:38:44 -05:00
|
|
|
const children: Gtk.Widget[] = [];
|
|
|
|
let ch = self.get_first_child();
|
|
|
|
|
|
|
|
while (ch !== null) {
|
|
|
|
children.push(ch);
|
|
|
|
ch = ch.get_next_sibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
return children.filter((child) => child !== self.child);
|
|
|
|
}
|
|
|
|
|
2025-01-13 10:51:02 -05:00
|
|
|
setChildren(self: OverlayClass, children: Gtk.Widget[]) {
|
2025-01-12 20:12:46 -05:00
|
|
|
for (const child of children) {
|
2025-01-14 10:12:20 -05:00
|
|
|
const types = childType in child ?
|
|
|
|
(child[childType] as string).split(/\s+/) :
|
2025-01-01 13:38:44 -05:00
|
|
|
[];
|
|
|
|
|
|
|
|
if (types.includes('overlay')) {
|
|
|
|
self.add_overlay(child);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.set_child(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.set_measure_overlay(child, types.includes('measure'));
|
|
|
|
self.set_clip_overlay(child, types.includes('clip'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-01-13 10:51:02 -05:00
|
|
|
|
|
|
|
export const Overlay = (props?: OverlayProps) => new OverlayClass(props);
|