Skip to content

Commit

Permalink
feat(widgets): add child and overlay props (Aylur#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt1432 authored and gorsbart committed Feb 28, 2024
1 parent ea3cc12 commit d57097b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/widgets/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export default class AgsBox extends AgsWidget(Gtk.Box) {
super(props as Gtk.Box.ConstructorProperties);
}

get child() { return this.children[0]; }
set child(child: Gtk.Widget) {
this.children = [child];
}

get children() { return this.get_children(); }
set children(children: Gtk.Widget[]) {
const newChildren = children || [];
Expand Down
10 changes: 9 additions & 1 deletion src/widgets/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Gtk from 'gi://Gtk?version=3.0';
export type OverlayProps = BaseProps<AgsOverlay, Gtk.Overlay.ConstructorProperties & {
pass_through?: boolean
overlays?: Gtk.Widget[]
overlay?: Gtk.Widget
}>

export default class AgsOverlay extends AgsWidget(Gtk.Overlay) {
Expand All @@ -12,6 +13,7 @@ export default class AgsOverlay extends AgsWidget(Gtk.Overlay) {
properties: {
'pass-through': ['boolean', 'rw'],
'overlays': ['jsobject', 'rw'],
'overlay': ['jsobject', 'rw'],
},
});
}
Expand All @@ -35,8 +37,14 @@ export default class AgsOverlay extends AgsWidget(Gtk.Overlay) {
this.notify('pass-through');
}

get overlay() { return this.overlays[0]; }
set overlay(overlay: Gtk.Widget) {
this.overlays = [overlay];
this.notify('overlay');
}

get overlays() {
return this.get_children().filter(ch => ch === this.child);
return this.get_children().filter(ch => ch !== this.child);
}

set overlays(overlays: Gtk.Widget[]) {
Expand Down

0 comments on commit d57097b

Please sign in to comment.