lazy-widgets
Version:
Typescript retained mode GUI for the HTML canvas API
84 lines • 3.04 kB
JavaScript
import { BlurEvent } from '../events/BlurEvent.js';
import { FocusEvent } from '../events/FocusEvent.js';
import { LeaveEvent } from '../events/LeaveEvent.js';
import { PointerEvent } from '../events/PointerEvent.js';
import { PropagationModel } from '../events/WidgetEvent.js';
import { ClickHelper } from '../helpers/ClickHelper.js';
import { PassthroughWidget } from './PassthroughWidget.js';
export class ClickProxy extends PassthroughWidget {
constructor(child, complementaryClickHelper, properties) {
super(child, properties);
this.complementaryClickHelper = complementaryClickHelper;
this.clickHelper = new ClickHelper(this);
}
activate() {
super.activate();
this.clickHelper.reset();
this.complementaryClickHelper.ref();
}
deactivate() {
this.clickHelper.reset();
this.complementaryClickHelper.unref();
super.deactivate();
}
handleAttachment() {
this.complementaryClickHelper.addClickHelper(this.clickHelper);
super.handleAttachment();
}
handleDetachment() {
this.complementaryClickHelper.removeClickHelper(this.clickHelper);
super.handleDetachment();
}
handleEvent(event) {
// FIXME if you have a nested button or clickproxy, and they both share
// a compoundclickhelper, the hover state can't be transferred
// perfectly; there's a single event which causes the state to
// transition to a released state, instead of hover. i couldn't
// find a fix for this
if (event.propagation !== PropagationModel.Trickling) {
if (event.isa(FocusEvent)) {
return this;
}
else if (event.isa(BlurEvent)) {
return this;
}
else {
return super.handleEvent(event);
}
}
const tricklingEvent = event;
if (tricklingEvent.target !== this) {
const superCapture = super.handleEvent(event);
if (superCapture) {
if (event instanceof PointerEvent) {
// XXX simulate an unhover, since the pointer is over some
// nested button now
this.clickHelper.handleClickEvent(new LeaveEvent(this), this.root, this.bounds);
}
return superCapture;
}
if (tricklingEvent.target !== null) {
return null;
}
}
if (!(event.isa(LeaveEvent) || event instanceof PointerEvent)) {
return null;
}
this.clickHelper.handleClickEvent(tricklingEvent, this.root, this.bounds);
return this;
}
}
ClickProxy.autoXML = {
name: 'click-proxy',
inputConfig: [
{
mode: 'widget',
name: 'child',
},
{
mode: 'value',
name: 'complementary-click-helper',
},
],
};
//# sourceMappingURL=ClickProxy.js.map