lazy-widgets
Version:
Typescript retained mode GUI for the HTML canvas API
131 lines (130 loc) • 5.54 kB
TypeScript
import { Layer } from '../core/Layer.js';
import { WidgetEvent } from '../events/WidgetEvent.js';
import { Parent } from './Parent.js';
import type { LayerInit } from '../core/LayerInit.js';
import type { Rect } from '../helpers/Rect.js';
import type { WidgetAutoXML } from '../xml/WidgetAutoXML.js';
import type { Widget, WidgetProperties } from './Widget.js';
/**
* A tuple with a layer and the name of that layer (or null if it is an unnamed
* layer). For internal use only.
*
* @category Core
*/
export type LayerIteratorNextType<W extends Widget> = [layer: Layer<W>, layerName: string | null];
/**
* A {@link Parent} where each child is in a separate layer. Layers have an
* order, and are placed in that order; layers at the beginning of the list are
* below layers at the end of the list, painting is done in a back-to-front
* order, while event dispatching is done in a front-to-back order.
*
* A layerered container must always contain at least one layer; the default
* layer. The default layer can't be removed, and must be able to expand.
*
* Can be constrained to a specific type of children.
*
* @category Widget
*/
export declare class LayeredContainer<W extends Widget = Widget> extends Parent<W> {
static autoXML: WidgetAutoXML;
/** The default layer. Can't be removed */
readonly defaultLayer: Layer<W>;
/** The current index of the default layer */
private _defaultLayerIndex;
/** The list of layers in this container */
private readonly layers;
/**
* A map which names some layers. Each key is the layer name, and each value
* is the index of the layer in the layers list.
*/
private readonly layerNames;
/**
* @param layers - The list of layers to be added to this container
* @param defaultLayerIndex - The index of the default layer in the layers list
*/
constructor(layers: Array<LayerInit<W>>, defaultLayerIndex?: number, properties?: Readonly<WidgetProperties>);
/**
* Create a new {@link LayeredContainer} with a single default layer.
* Shortcut for using the constructor with a single-element array as the
* layers list, and a default layer index of 0.
*/
static fromDefaultLayerChild<W extends Widget>(defaultLayerChild: W, properties?: Readonly<WidgetProperties>): LayeredContainer<W>;
[Symbol.iterator](): Iterator<W>;
get childCount(): number;
/**
* Get the amount of layers currently in this container. Equivalent to
* {@link LayeredContainer#childCount};
*/
get layerCount(): number;
/**
* Get the current index of the default layer. May change if a layer is
* inserted or removed before the default layer.
*/
get defaultLayerIndex(): number;
/** Iterate all layers from back to front. */
get backToFrontLayers(): Iterable<LayerIteratorNextType<W>>;
/** Iterate all layers from front to back. */
get frontToBackLayers(): Iterable<LayerIteratorNextType<W>>;
protected handleEvent(event: WidgetEvent): Widget | null;
protected handlePreLayoutUpdate(): void;
protected handlePostLayoutUpdate(): void;
protected handleResolveDimensions(minWidth: number, maxWidth: number, minHeight: number, maxHeight: number): void;
resolvePosition(x: number, y: number): void;
protected handlePainting(dirtyRects: Array<Rect>): void;
/** Add a new layer to the container at the end of the layers list. */
pushLayer(layer: Layer<W>, name?: string | null): number;
/** Add a new layer to the container at a given index of the layers list. */
insertLayerBefore(layer: Layer<W>, index: number, name?: string | null): number;
/**
* Add a new layer to the container after a given index of the layers list.
*/
insertLayerAfter(layer: Layer<W>, index: number, name?: string | null): number;
/**
* Remove a layer from the container at a given index of the layers list.
*/
removeLayer(index: number): void;
/**
* Get the current index of a named layer by its name.
*
* @returns Returns the index of the named layer, or null if no layer has been added with this name.
*/
getNamedLayerIndex(name: string): number | null;
/**
* Get a named layer by its name.
*
* @returns Returns the named layer, or null if no layer has been added with this name.
*/
getNamedLayer(name: string): Layer<W> | null;
/**
* Get the current index of a layer by its value.
*
* @returns Returns the index of the layer, or null if the layer is not present in the container.
*/
getLayerIndex(layer: Layer<W>): number | null;
/**
* Change the indices of the named layers and default layer if they exceed
* indexMin, by a given delta. For internal use only.
*
* @param indexMin - Indices with this value or greater will be updated
* @param delta - The amount of change the indices by
*/
private updateIndices;
/**
* Attach a given layer to the UI root. For internal use only.
*
* @param layer - The layer to attach to the UI root.
*/
private attachLayer;
/**
* Detach a given layer from the UI root. For internal use only.
*
* @param layer - The layer to deatach from the UI root.
*/
private detachLayer;
/**
* Assert that a layer name is available. If no name is provided, this
* method will always succeed. If the name is already taken, an error is
* thrown.
*/
private assertNameAvailable;
}