feat(ags popup): make more modular

This commit is contained in:
matt1432 2023-10-30 19:53:50 -04:00
parent d55c4ce09e
commit 0907b2cbe7

View file

@ -1,32 +1,51 @@
import { App, Widget } from '../../imports.js'; import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import App from 'resource:///com/github/Aylur/ags/app.js';
const { Revealer, Box, Window } = Widget; const { Revealer, Box, Window } = Widget;
export default ({ export default ({
// Revealer props
transition = 'slide_down',
transitionDuration = 500,
// Optional: execute a function whenever the window pops up
onOpen = () => {},
// Window props
name, name,
child, child,
closeOnUnfocus = 'released', closeOnUnfocus = 'released',
transition = 'slide_down', visible = false,
onOpen = () => {}, layer = 'overlay',
...props ...props
}) => { }) => {
const window = Window({ const window = Window({
name, name,
layer,
popup: true, popup: true,
visible: false, visible: false,
layer: 'overlay',
...props, ...props,
// Add way to make window open on startup
setup: () => {
const id = App.connect('config-parsed', () => {
if (visible)
App.openWindow(name);
App.disconnect(id);
});
},
// Wrapping the revealer inside a box is needed
// to allocate some space for it even when not revealed
child: Box({ child: Box({
style: `min-height:1px; style: `min-height:1px;
min-width:1px; min-width:1px;
padding: 1px;`, padding: 1px;`,
child: Revealer({ child: Revealer({
transition, transition,
transitionDuration: 500, transitionDuration,
connections: [[App, (rev, currentName, visible) => { connections: [[App, (rev, currentName, visible) => {
if (currentName === name) { if (currentName === name) {
rev.reveal_child = visible; rev.revealChild = visible;
onOpen(child); onOpen(child);
} }
}]], }]],
@ -34,7 +53,14 @@ export default ({
}), }),
}), }),
}); });
// Make getting the original child passed in
// this function easier when making more code
// for the widget
window.getChild = () => child; window.getChild = () => child;
// This is for my custom pointers.js
window.closeOnUnfocus = closeOnUnfocus; window.closeOnUnfocus = closeOnUnfocus;
return window; return window;
}; };