lazy-widgets
Version:
Typescript retained mode GUI for the HTML canvas API
65 lines • 2.33 kB
JavaScript
import { SingleParent } from './SingleParent.js';
import { PropagationModel } from '../events/WidgetEvent.js';
import { SingleParentXMLInputConfig } from '../xml/SingleParentXMLInputConfig.js';
/**
* A {@link SingleParent} which contains a single child and does nothing,
* passing all events through to its child. Useful for widgets that are only
* used for logic, like {@link ThemeScope}.
*
* Can be constrained to a specific type of children.
*
* Since this does nothing on its own, it should not be used on its own.
* Instead, extend this class if you are looking for a way to do wrapper widgets
* that provide extra logic.
*
* @category Widget
*/
export class PassthroughWidget extends SingleParent {
constructor(child, properties) {
// Passthrough widgets dont need a clear background, have a child and
// propagate events
super(child, properties);
}
handleEvent(event) {
if (event.propagation !== PropagationModel.Trickling) {
return super.handleEvent(event);
}
else {
return this.child.dispatchEvent(event);
}
}
handlePreLayoutUpdate() {
// Pre-layout update child
const child = this.child;
child.preLayoutUpdate();
// If child's layout is dirty, set self's layout as dirty
if (child.layoutDirty) {
this._layoutDirty = true;
}
}
handlePostLayoutUpdate() {
// Post-layout update child
this.child.postLayoutUpdate();
}
handleResolveDimensions(minWidth, maxWidth, minHeight, maxHeight) {
// Resolve child's dimensions and set own resolved dimensions to be
// equal to the child's
const child = this.child;
child.resolveDimensions(minWidth, maxWidth, minHeight, maxHeight);
[this.idealWidth, this.idealHeight] = child.idealDimensions;
}
resolvePosition(x, y) {
super.resolvePosition(x, y);
// Resolve child's position to be the same as this widget's position
this.child.resolvePosition(x, y);
}
handlePainting(dirtyRects) {
// Paint child
this.child.paint(dirtyRects);
}
}
PassthroughWidget.autoXML = {
name: 'passthrough-widget',
inputConfig: SingleParentXMLInputConfig
};
//# sourceMappingURL=PassthroughWidget.js.map