Does heaps supports double-click event for desktop application?
Not natively, as far as I’m aware. I just whipped up this quick class to handle double clicks using Interactive.
import hxd.Timer;
import hxd.Event;
/**
* Super basic double clickable version of Interactive
*/
class DoubleClickable extends h2d.Interactive {
// Max # of frames between clicks to trigger a double click.
static final DOUBLE_CLICK_THRESH = 15;
// Set this instead of using onClick.
public var realOnClick:Event->Void;
// The function to call on double click.
public var onDoubleClick:Event->Void;
// Keep track of when this instance was last clicked.
private var lastClickFrame:Int = -1;
public function new(width, height, ?parent, ?shape) {
super(width, height, parent, shape);
}
override function onClick(e:Event) {
// Within the threshold, trigger a double click.
if (Timer.frameCount - lastClickFrame <= DOUBLE_CLICK_THRESH) {
if (onDoubleClick != null) {
onDoubleClick(e);
}
} else {
// Otherwise, call `realOnClick`
if (realOnClick != null) {
realOnClick(e);
}
}
// Update the last click frame.
lastClickFrame = Timer.frameCount;
}
}
1 Like