Sprites.Media.Sprite.Layers
The layers panel: the stack of layers of the current frame, and the controls to add, clone, reorder, delete and hide them. Window is a resizable floating window, shown while its own visible flag is true. It holds a scrolling list of layer cards over a row of buttons. A card is a selectable option, so the selected layer darkens like a button group, and it carries the layer's thumbnail and a visible checkbox. The selected layer is the one the editor draws into; the view shows the visible layers flattened. The Tools window's Windows buttons open it; the selector and that window live in Sprites.Media.Sprite.Tool.
- Sprites.Media.Sprite.Layers.Preview
- Sprites.Media.Sprite.Layers.Card
- Sprites.Media.Sprite.Layers.List
- Sprites.Media.Sprite.Layers.Buttons
- Sprites.Media.Sprite.Layers.Window
Sprites.Media.Sprite.Layers.Preview Void
Sprites.Media.Sprite.Layers.Preview(thumb)
One layer's thumbnail preview: a small fixed square on a white ground, the layer drawn to fit, so a transparent layer reads as empty. The image scales to contain and renders pixelated, so the pixels stay crisp.
| Input | Type | Description |
|---|---|---|
thumb | Sprites.Reactive.Value | The reactive PNG data URL of the layer. |
Returns nothing.
const layer = Sprites.Media.Sprite.NewLayer(8, 8);
const pixels = Sprites.Object.Field(layer, 'pixels');
const painted = Sprites.Object.With(pixels, 27, 1);
const filled = Sprites.Object.With(layer, 'pixels', painted);
const thumb = Sprites.Media.Sprite.LayerThumbnail(filled, 8, 8, undefined, 1);
Sprites.Media.Sprite.Layers.Preview(thumb);
Sprites.Media.Sprite.Layers.Card Void
Sprites.Media.Sprite.Layers.Card(layer, index, layers, frames, frameIndex, width, height, optionalSlots, aspect)
One layer card: a row of a selectable thumbnail and a visible checkbox. The thumbnail is an Option, so a click selects the layer and the selected card darkens; the checkbox is a two way flag written back into the layer through the frames list, so hiding a layer drops it from the flattened view.
| Input | Type | Description |
|---|---|---|
layer | Sprites.Reactive.Value | The layer value. |
index | Number | The layer's position in layers. |
layers | Sprites.Reactive.Value | The frame's layers list. |
frames | Sprites.Reactive.Value | The two way frames list. |
frameIndex | Number or Sprites.Reactive.Value | The current frame. |
width | Number or Sprites.Reactive.Value | The document width for the thumbnail. |
height | Number or Sprites.Reactive.Value | The document height for the thumbnail. |
optionalSlots | Sprites.Reactive.Value | The palette slot colours for the thumbnail. |
aspect | Number or Sprites.Reactive.Value | The pixel aspect for the thumbnail. |
Returns nothing.
const layer = Sprites.Media.Sprite.NewLayer(8, 8);
const frame = Sprites.Reactive.ReadOnly({ layers: [layer] });
const frames = Sprites.Reactive.Value([frame]);
const selected = Sprites.Reactive.Value(0);
Sprites.Ui.Button.Select(selected, () => {
Sprites.Media.Sprite.Layers.Card(layer, 0, [layer], frames, 0, 8, 8, undefined, 1);
});
Sprites.Media.Sprite.Layers.List Void
Sprites.Media.Sprite.Layers.List(frames, frameIndex, layers, selectedLayer, width, height, optionalSlots, aspect)
The scrolling list of layer cards: a Select over the selected layer so exactly one card darkens, an Each over the layers, and column-reverse so the top layer, the one drawn last, sits at the top of the list. It scrolls up and down inside the resizable window.
| Input | Type | Description |
|---|---|---|
frames | Sprites.Reactive.Value | The two way frames list. |
frameIndex | Number or Sprites.Reactive.Value | The current frame. |
layers | Sprites.Reactive.Value | That frame's layers. |
selectedLayer | Sprites.Reactive.Value | The two way pick of the selected layer. |
width | Number or Sprites.Reactive.Value | The document width for the thumbnails. |
height | Number or Sprites.Reactive.Value | The document height for the thumbnails. |
optionalSlots | Sprites.Reactive.Value | The palette slot colours for the thumbnails. |
aspect | Number or Sprites.Reactive.Value | The pixel aspect for the thumbnails. |
Returns nothing.
const back = Sprites.Media.Sprite.NewLayer(8, 8);
const front = Sprites.Media.Sprite.NewLayer(8, 8);
const layers = [back, front];
const frame = Sprites.Reactive.ReadOnly({ layers: layers });
const frames = Sprites.Reactive.Value([frame]);
const selected = Sprites.Reactive.Value(1);
Sprites.Media.Sprite.Layers.List(frames, 0, layers, selected, 8, 8, undefined, 1);
Sprites.Media.Sprite.Layers.Window Void
Sprites.Media.Sprite.Layers.Window(visible, frames, frameIndex, layers, selectedLayer, layerIndex, width, height, optionalSlots, aspect)
The Layers panel window: a resizable floating panel, shown while visible is true, with a close button. It fills as a column: a scrolling list of layer cards over a fixed row of buttons, so the list grows a scrollbar while the buttons stay put as the window resizes. The window owns its live rect, so it keeps its dragged corner and size across a close and reopen.
| Input | Type | Description |
|---|---|---|
visible | Sprites.Reactive.Value | Shows the window while true. |
Returns nothing.
const document = Sprites.Media.Sprite.NewDocument(8, 8);
const data = Sprites.Reactive.Value(document);
const frames = Sprites.Object.Field(data, 'frames');
const current = Sprites.Array.At(frames, 0);
const layers = Sprites.Object.Field(current, 'layers');
const selected = Sprites.Reactive.Value(0);
const count = Sprites.Array.Length(layers);
const last = Sprites.Maths.Subtract(count, 1);
const layerIndex = Sprites.Maths.Clamp(selected, 0, last);
const visible = Sprites.Reactive.Value(false);
Sprites.Ui.Button.SetValue(visible, true, 'Open Layers window');
Sprites.Media.Sprite.Layers.Window(visible, frames, 0, layers, selected, layerIndex, 8, 8, undefined, 1);