feat(ags): make drag have accurate cursors
This commit is contained in:
parent
137a1614bf
commit
adf818fd44
1 changed files with 26 additions and 3 deletions
|
@ -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'],
|
||||
],
|
||||
}),
|
||||
|
|
Loading…
Reference in a new issue