lazy-widgets
Version:
Typescript retained mode GUI for the HTML canvas API
73 lines (72 loc) • 3.2 kB
TypeScript
import type { LayoutConstraints } from './LayoutConstraints.js';
import type { Widget } from '../widgets/Widget.js';
import type { TricklingEvent } from '../events/TricklingEvent.js';
import type { Rect } from '../helpers/Rect.js';
import type { Viewport } from './Viewport.js';
export type ClippedViewportRect = [vpX: number, vpY: number, vpW: number, vpH: number, origXDst: number, origYDst: number, xDst: number, yDst: number, wClipped: number, hClipped: number];
/**
* The base implementation of the {@link Viewport} interface. See
* {@link CanvasViewport} and {@link ClippedViewport}.
*
* @category Core
*/
export declare abstract class BaseViewport implements Viewport {
readonly relativeCoordinates: boolean;
readonly child: Widget;
abstract readonly context: CanvasRenderingContext2D;
constraints: LayoutConstraints;
rect: Rect;
abstract get effectiveScale(): [scaleX: number, scaleY: number];
parent: Viewport | null;
offset: [x: number, y: number];
/** Has the warning for dimensionless canvases been issued? */
protected static dimensionlessWarned: boolean;
/** Has the warning for non-power of 2 dimensions been issued? */
protected static powerOf2Warned: boolean;
/**
* The maximum retries allowed for
* {@link Viewport#resolveLayout | resolving the layout}. The first attempt
* is not counted. Only retries that exceed this limit are discarded; if
* maxRelayout is 4, then the 5th retry will be discarded.
*/
protected static maxRelayout: number;
/**
* Should the layout be resolved, even if the child widget doesn't have a
* dirty layout?
*/
protected forceRelayout: boolean;
protected constructor(child: Widget, relativeCoordinates: boolean);
/**
* Forces re-layout and calls {@link BaseViewport#updateChildPos}. Used as a
* callback for the {@link BaseViewport#rect} field watcher.
*/
private relayoutAndReposition;
/**
* Resolves the position of the child and finalizes its bounds. This
* effectively updates the position of the child in an out-of-order fashion
* (doesn't wait for the proper stage of the layout resolution). Used as a
* callback for the {@link BaseViewport#offset} field watcher.
*/
private updateChildPos;
/**
* Resolves the given child's layout by calling
* {@link Widget#resolveDimensions} with the current
* {@link Viewport#constraints}, {@link Widget#resolvePosition} and
* {@link Widget#finalizeBounds}.
*
* Handles both relative and absolute coordinates. The previous position is
* used.
*
* @returns Returns true if the child was resized, else, false.
*/
resolveLayout(): boolean;
abstract paint(extraDirtyRects: Array<Rect>): boolean;
dispatchTricklingEvent(event: TricklingEvent): Widget | null;
/**
* Get the rect of the child alongside more extra information,
* clipped/clamped to the bounds of the viewport. Usually only for internal,
* but can be used externally if you know what you're doing.
*/
getClippedViewport(): ClippedViewportRect;
abstract markDirtyRect(rect: Rect): void;
}