feat(ags): make drag have accurate cursors

This commit is contained in:
matt1432 2023-09-08 23:16:46 -04:00
parent 137a1614bf
commit adf818fd44

View file

@ -1,15 +1,22 @@
const { Window, Box, EventBox } = ags.Widget;
const { Gtk, Gdk } = imports.gi;
const display = Gdk.Display.get_default();
var Gesture;
var shouldDelete = false;
const DraggableCtor = props => EventBox({
onHover: box => {
box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab'));
},
onHoverLost: box => {
box.window.set_cursor(null);
},
setup: widget => {
Gesture = Gtk.GestureDrag.new(widget);
},
child: Box({
style: 'background: black; min-width: 20px; min-height: 20px',
style: 'background: black; min-width: 40px; min-height: 20px',
}),
...props,
});
@ -27,11 +34,27 @@ export const DragTest = Window({
Box({
connections: [
[Gesture, event => {
Draggable.child.setStyle('background: black; min-width: 20px; min-height: 20px; margin-left: ' + Gesture.get_offset()[1] + 'px;')
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;
}
}, 'drag-update'],
[Gesture, event => {
Draggable.child.setStyle('transition: margin 0.5s ease; background: black; min-width: 20px; min-height: 20px')
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');
}, 'drag-end'],
],
}),