feat(ags cursorbox): when release click outside box, don't run func
This commit is contained in:
parent
11f5eecbc2
commit
b255853935
2 changed files with 58 additions and 32 deletions
|
@ -3,6 +3,7 @@ import { Box, Icon, Label } from 'resource:///com/github/Aylur/ags/widget.js';
|
||||||
|
|
||||||
const DEFAULT_KB = 'at-translated-set-2-keyboard';
|
const DEFAULT_KB = 'at-translated-set-2-keyboard';
|
||||||
|
|
||||||
|
|
||||||
export default () => Box({
|
export default () => Box({
|
||||||
className: 'toggle-off',
|
className: 'toggle-off',
|
||||||
css: 'padding: 0 10px;',
|
css: 'padding: 0 10px;',
|
||||||
|
|
|
@ -1,49 +1,74 @@
|
||||||
|
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
|
||||||
import { Button, EventBox } from 'resource:///com/github/Aylur/ags/widget.js';
|
import { Button, EventBox } from 'resource:///com/github/Aylur/ags/widget.js';
|
||||||
|
|
||||||
|
import Gtk from 'gi://Gtk';
|
||||||
import Gdk from 'gi://Gdk';
|
import Gdk from 'gi://Gdk';
|
||||||
const display = Gdk.Display.get_default();
|
const display = Gdk.Display.get_default();
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: wrap in another EventBox for disabled cursor
|
||||||
export default ({
|
export default ({
|
||||||
isButton = false,
|
isButton = false,
|
||||||
reset = true,
|
reset = true,
|
||||||
onHover = () => {},
|
onHover = () => {},
|
||||||
onHoverLost = () => {},
|
onHoverLost = () => {},
|
||||||
|
onPrimaryClickRelease = () => {},
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
if (!isButton) {
|
// Make this variable to know if the function should
|
||||||
return EventBox({
|
// be executed depending on where the click is released
|
||||||
...props,
|
const CanRun = Variable(true);
|
||||||
onHover: self => {
|
|
||||||
if (!self.child.sensitive || !self.sensitive)
|
|
||||||
self.window.set_cursor(Gdk.Cursor.new_from_name(display, 'not-allowed'));
|
|
||||||
|
|
||||||
else
|
const properties = {
|
||||||
self.window.set_cursor(Gdk.Cursor.new_from_name(display, 'pointer'));
|
...props,
|
||||||
|
onPrimaryClickRelease: self => {
|
||||||
|
// Every click, do a one shot connect to
|
||||||
|
// CanRun to wait for location of click
|
||||||
|
const id = CanRun.connect('changed', () => {
|
||||||
|
if (CanRun.value)
|
||||||
|
onPrimaryClickRelease(self);
|
||||||
|
|
||||||
onHover(self);
|
CanRun.disconnect(id);
|
||||||
},
|
});
|
||||||
onHoverLost: self => {
|
},
|
||||||
if (reset)
|
onHover: self => {
|
||||||
self.window.set_cursor(null);
|
if (!self.child.sensitive || !self.sensitive)
|
||||||
|
self.window.set_cursor(Gdk.Cursor.new_from_name(display, 'not-allowed'));
|
||||||
|
|
||||||
onHoverLost(self);
|
else
|
||||||
},
|
self.window.set_cursor(Gdk.Cursor.new_from_name(display, 'pointer'));
|
||||||
});
|
|
||||||
}
|
onHover(self);
|
||||||
else {
|
},
|
||||||
return Button({
|
onHoverLost: self => {
|
||||||
...props,
|
if (reset)
|
||||||
onHover: self => {
|
self.window.set_cursor(null);
|
||||||
if (!self.child.sensitive || !self.sensitive)
|
|
||||||
self.window.set_cursor(Gdk.Cursor.new_from_name(display, 'not-allowed'));
|
onHoverLost(self);
|
||||||
else
|
},
|
||||||
self.window.set_cursor(Gdk.Cursor.new_from_name(display, 'pointer'));
|
};
|
||||||
},
|
|
||||||
onHoverLost: self => {
|
let widget;
|
||||||
if (reset)
|
if (!isButton)
|
||||||
self.window.set_cursor(null);
|
widget = EventBox(properties);
|
||||||
},
|
else
|
||||||
});
|
widget = Button(properties);
|
||||||
}
|
|
||||||
|
const gesture = Gtk.GestureLongPress.new(widget);
|
||||||
|
|
||||||
|
widget.connectTo(gesture, () => {
|
||||||
|
const pointer = gesture.get_point(null);
|
||||||
|
const x = pointer[1];
|
||||||
|
const y = pointer[2];
|
||||||
|
|
||||||
|
if ((!x || !y) || x === 0 && y === 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CanRun.value = !(
|
||||||
|
x > widget.get_allocated_width() ||
|
||||||
|
y > widget.get_allocated_height()
|
||||||
|
);
|
||||||
|
}, 'end');
|
||||||
|
|
||||||
|
return widget;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue