textmode.js / layering / TextmodeLayerManager
Class: TextmodeLayerManager
Manages the stack of layers within a Textmodifier instance.
This interface provides methods to create, manage, and organize multiple textmode layers. Layers allow for complex compositing, independent rendering passes, and post-processing effects.
The base layer is always present at the bottom of the stack. User-created layers are added on top of the base layer.
Access this manager via textmodifier.layers.
Implements
ILayerManager
Accessors
all
Get Signature
get all(): readonly TextmodeLayer[];Get all user layers as a readonly array.
Example
const t = textmode.create();
t.layers.add();
t.layers.add();
console.log(t.layers.all.length); // 2
// Iterate over all user layers
t.layers.all.forEach(layer => {
layer.opacity(0.5);
});Returns
readonly TextmodeLayer[]
Implementation of
ILayerManager.allbase
Get Signature
get base(): TextmodeLayer;The base layer that is always rendered at the bottom of the layer stack. This layer represents the main drawing content before any user layers are composited.
The base layer cannot be removed or moved.
Returns
Implementation of
ILayerManager.basefilters
Get Signature
get filters(): TextmodeFilterManager;Returns
resultFramebuffer
Get Signature
get resultFramebuffer(): TextmodeFramebuffer;The framebuffer containing the final composited result after all layers and filters have been applied.
Returns
Implementation of
ILayerManager.resultFramebufferMethods
add()
add(options): TextmodeLayer;Create and add a new layer to the top of the layer stack.
New layers are initialized with their own grid and font settings. Layers can be offset, rotated, and blended with layers below them.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | TextmodeLayerOptions | Optional configuration for the new layer (visibility, opacity, blendMode, etc.) |
Returns
The newly created TextmodeLayer instance.
Example
const t = textmode.create();
// Add a new layer on top of the base layer
const uiLayer = t.layers.add({
blendMode: 'normal',
opacity: 1.0,
fontSize: 16
});
// Draw to the new layer
uiLayer.draw(() => {
t.clear(); // Clear THIS layer's background (transparent)
t.charColor(255, 0, 0); // Red text
t.cellColor(0, 0, 0, 0); // Transparent cell background
t.char('!');
t.rect(5, 5);
});
// Base layer content
t.draw(() => {
t.background(0, 0, 50); // Dark blue background
t.charColor(0, 0, 255); // Blue text
t.cellColor(0, 0, 0, 0); // Transparent cell background
t.char('?');
t.rect(5, 5);
});Implementation of
ILayerManager.addclear()
clear(): void;Remove all user-created layers from the manager. The base layer is not affected by this operation. This is useful for integration into live-coding environments where code is re-evaluated and layers need to be recreated from scratch.
Returns
void
Example
const t = textmode.create();
t.setup(() => {
// Ensure clean slate when re-running setup
t.layers.clear();
// Re-create layers
t.layers.add({ blendMode: 'additive' });
t.layers.add({ blendMode: 'multiply' });
});Implementation of
ILayerManager.clearmove()
move(layer, newIndex): void;Move a layer to a new index in the layer stack.
Parameters
| Parameter | Type | Description |
|---|---|---|
layer | TextmodeLayer | The layer to move. |
newIndex | number | The new index for the layer. |
Returns
void
Example
const t = textmode.create();
const bgLayer = t.layers.add(); // Index 0
const fgLayer = t.layers.add(); // Index 1
// Swap z-order by moving fgLayer to bottom (index 0)
// This pushes bgLayer to index 1
t.layers.move(fgLayer, 0);Implementation of
ILayerManager.moveremove()
remove(layer): void;Remove a layer from the manager.
Parameters
| Parameter | Type | Description |
|---|---|---|
layer | TextmodeLayer | The layer to remove. |
Returns
void
Example
const t = textmode.create();
const tempLayer = t.layers.add();
// Remove the layer after 100 frames
t.draw(() => {
if (t.frameCount > 100) {
t.layers.remove(tempLayer);
}
});Implementation of
ILayerManager.removeswap()
swap(layerA, layerB): void;Swap the order of two layers if they exist in the same collection.
Parameters
| Parameter | Type | Description |
|---|---|---|
layerA | TextmodeLayer | The first layer to swap. |
layerB | TextmodeLayer | The second layer to swap. |
Returns
void
Example
const t = textmode.create();
const layer1 = t.layers.add();
const layer2 = t.layers.add();
// Swap the layers' positions in the stack
t.layers.swap(layer1, layer2);Implementation of
ILayerManager.swap