Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(widgets): add child and overlay props #237

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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