2023-10-02 12:06:35 -04:00
|
|
|
import { Widget } from '../../imports.js';
|
|
|
|
const { Box, Overlay, EventBox } = Widget;
|
|
|
|
|
|
|
|
import Gtk from 'gi://Gtk';
|
2023-09-26 10:43:37 -04:00
|
|
|
|
|
|
|
const MAX_OFFSET = 200;
|
|
|
|
const OFFSCREEN = 500;
|
|
|
|
const TRANSITION = 'transition: margin 0.5s ease, opacity 3s ease;';
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export default ({ properties, connections, props } = {}) => {
|
2023-09-26 10:43:37 -04:00
|
|
|
let widget = EventBox();
|
|
|
|
let gesture = Gtk.GestureDrag.new(widget)
|
|
|
|
|
|
|
|
widget.child = Overlay({
|
2023-10-17 13:47:02 -04:00
|
|
|
...props,
|
2023-09-26 10:43:37 -04:00
|
|
|
properties: [
|
|
|
|
...properties,
|
|
|
|
['dragging', false],
|
|
|
|
],
|
|
|
|
child: Box({className: 'player'}),
|
|
|
|
connections: [
|
|
|
|
...connections,
|
|
|
|
|
|
|
|
[gesture, overlay => {
|
2023-10-12 22:59:04 -04:00
|
|
|
if (overlay.list().length <= 1)
|
2023-09-26 10:43:37 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
overlay._dragging = true;
|
|
|
|
const offset = gesture.get_offset()[1];
|
|
|
|
|
2023-10-12 22:59:04 -04:00
|
|
|
let playerBox = overlay.list().at(-1);
|
|
|
|
|
2023-09-26 10:43:37 -04:00
|
|
|
if (offset >= 0) {
|
|
|
|
playerBox.setStyle(`margin-left: ${offset}px;
|
|
|
|
margin-right: -${offset}px;
|
|
|
|
${playerBox._bgStyle}`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let newOffset = Math.abs(offset);
|
|
|
|
playerBox.setStyle(`margin-left: -${newOffset}px;
|
|
|
|
margin-right: ${newOffset}px;
|
|
|
|
${playerBox._bgStyle}`);
|
|
|
|
}
|
|
|
|
overlay._selected = playerBox;
|
|
|
|
}, 'drag-update'],
|
|
|
|
|
|
|
|
[gesture, overlay => {
|
2023-10-12 22:59:04 -04:00
|
|
|
if (overlay.list().length <= 1)
|
2023-09-26 10:43:37 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
overlay._dragging = false;
|
|
|
|
const offset = gesture.get_offset()[1];
|
|
|
|
|
2023-10-12 22:59:04 -04:00
|
|
|
let playerBox = overlay.list().at(-1);
|
2023-09-26 10:43:37 -04:00
|
|
|
|
|
|
|
if (Math.abs(offset) > MAX_OFFSET) {
|
|
|
|
if (offset >= 0) {
|
|
|
|
playerBox.setStyle(`${TRANSITION}
|
|
|
|
margin-left: ${OFFSCREEN}px;
|
|
|
|
margin-right: -${OFFSCREEN}px;
|
|
|
|
opacity: 0;
|
|
|
|
${playerBox._bgStyle}`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
playerBox.setStyle(`${TRANSITION}
|
|
|
|
margin-left: -${OFFSCREEN}px;
|
|
|
|
margin-right: ${OFFSCREEN}px;
|
|
|
|
opacity: 0;
|
|
|
|
${playerBox._bgStyle}`);
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
overlay.reorder_overlay(playerBox, 0);
|
|
|
|
playerBox.setStyle(playerBox._bgStyle);
|
2023-10-12 22:59:04 -04:00
|
|
|
overlay._selected = overlay.list().at(-1);
|
2023-09-26 10:43:37 -04:00
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
playerBox.setStyle(`${TRANSITION} ${playerBox._bgStyle}`);
|
|
|
|
|
|
|
|
}, 'drag-end'],
|
|
|
|
],
|
|
|
|
});
|
2023-10-12 22:59:04 -04:00
|
|
|
widget.child.list = () => widget.child.get_children().filter(ch => ch._bgStyle !== undefined);
|
|
|
|
|
2023-09-26 10:43:37 -04:00
|
|
|
return widget;
|
|
|
|
};
|