lazy-widgets
Version:
Typescript retained mode GUI for the HTML canvas API
54 lines • 2.06 kB
JavaScript
import { SingleParent } from './SingleParent.js';
import { PropagationModel } from '../events/WidgetEvent.js';
import { resolveContainerDimensions } from '../helpers/resolveContainerDimensions.js';
import { resolveContainerPosition } from '../helpers/resolveContainerPosition.js';
/**
* A {@link SingleParent} which contains a single child and automatically paints
* the child, adds padding, propagates events (if enabled) and handles layout.
*
* Can be constrained to a specific type of children.
*
* @category Widget
*/
export class BaseContainer extends SingleParent {
onThemeUpdated(property = null) {
super.onThemeUpdated(property);
if (property === null || property === 'containerPadding'
|| property === 'containerAlignment') {
this._layoutDirty = true;
}
}
handleEvent(event) {
if (event.propagation === PropagationModel.Trickling) {
return this.child.dispatchEvent(event);
}
else {
return super.handleEvent(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) {
[this.idealWidth, this.idealHeight] = resolveContainerDimensions(minWidth, maxWidth, minHeight, maxHeight, this.containerPadding, this.containerAlignment, this.child);
}
resolvePosition(x, y) {
super.resolvePosition(x, y);
resolveContainerPosition(x, y, this.idealWidth, this.idealHeight, this.containerPadding, this.containerAlignment, this.child);
}
handlePainting(dirtyRects) {
// Paint child
this.child.paint(dirtyRects);
}
}
//# sourceMappingURL=BaseContainer.js.map