2023-09-08 22:52:29 -04:00
|
|
|
const { Window, Box, EventBox } = ags.Widget;
|
|
|
|
const { Gtk, Gdk } = imports.gi;
|
2023-09-08 23:16:46 -04:00
|
|
|
const display = Gdk.Display.get_default();
|
2023-09-08 22:52:29 -04:00
|
|
|
|
|
|
|
var Gesture;
|
|
|
|
var shouldDelete = false;
|
|
|
|
|
|
|
|
const DraggableCtor = props => EventBox({
|
2023-09-08 23:16:46 -04:00
|
|
|
onHover: box => {
|
|
|
|
box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab'));
|
|
|
|
},
|
|
|
|
onHoverLost: box => {
|
|
|
|
box.window.set_cursor(null);
|
|
|
|
},
|
2023-09-08 22:52:29 -04:00
|
|
|
setup: widget => {
|
|
|
|
Gesture = Gtk.GestureDrag.new(widget);
|
|
|
|
},
|
|
|
|
child: Box({
|
2023-09-08 23:16:46 -04:00
|
|
|
style: 'background: black; min-width: 40px; min-height: 20px',
|
2023-09-08 22:52:29 -04:00
|
|
|
}),
|
|
|
|
...props,
|
|
|
|
});
|
|
|
|
|
|
|
|
const Draggable = DraggableCtor();
|
|
|
|
|
|
|
|
export const DragTest = Window({
|
|
|
|
name: 'drag-test',
|
|
|
|
layer: 'overlay',
|
|
|
|
anchor: 'top right',
|
|
|
|
child: Box({
|
|
|
|
style: 'background: white; min-width: 200px; min-height: 200px;',
|
|
|
|
children: [
|
|
|
|
Draggable,
|
|
|
|
Box({
|
|
|
|
connections: [
|
|
|
|
[Gesture, event => {
|
2023-09-08 23:16:46 -04:00
|
|
|
const offset = Gesture.get_offset()[1];
|
|
|
|
Draggable.child.setStyle('background: black; min-width: 40px; min-height: 20px; margin-left: ' + offset + 'px;');
|
|
|
|
Draggable.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grabbing'));
|
|
|
|
|
|
|
|
if (offset > 150) {
|
|
|
|
shouldDelete = true;
|
|
|
|
}
|
|
|
|
else if (shouldDelete) {
|
|
|
|
shouldDelete = false;
|
|
|
|
}
|
2023-09-08 22:52:29 -04:00
|
|
|
}, 'drag-update'],
|
|
|
|
|
|
|
|
[Gesture, event => {
|
2023-09-08 23:16:46 -04:00
|
|
|
if (shouldDelete) {
|
|
|
|
Draggable.destroy();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Draggable.child.setStyle('transition: margin 0.5s ease; background: black; min-width: 40px; min-height: 20px');
|
|
|
|
Draggable.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab'));
|
|
|
|
}
|
|
|
|
print('end');
|
2023-09-08 22:52:29 -04:00
|
|
|
}, 'drag-end'],
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
});
|