BlockSurface
import { BlockSurface } from 'pixi-silk/ui/blocks';
A SmartContainer that paints every Block inside it into two SilkGraphics layers.
Blocks that never change (plates, panels, captions) go into the still layer, which is painted
once and cached as a texture. A block moves to the live layer the first time it animates or
changes (see BlockOptions.layer). While something moves, only the live layer draws
shapes, in one instanced draw on top of the still texture. At rest both layers are textures.
A block drawn over a live one goes live with it, so the order on screen stays the tree order.
Lay blocks out with add(block, block.layout()) or stack.
Pass ticker: app.ticker so layout, repaint and render run in that order in one frame.
Example#
import { signal } from 'pixi-silk/signal';
import { BlockSurface, ButtonBlock, PanelBlock, stack, TextBlock } from 'pixi-silk/ui/blocks';
const coins = signal(0);
const bar = new BlockSurface({
viewport: app,
ticker: app.ticker,
layout: { direction: 'row', alignItems: 'center', gap: 24, padding: [0, 32] },
landscapeData: { valign: 'bottom', width: 1920, height: 160, extendWidth: true },
});
const panel = new PanelBlock({ radius: 32, fill: 0x14161f });
bar.add(panel, panel.layout({ position: 'absolute', inset: 0 }));
stack(bar, [
new TextBlock({ text: 'COINS', style: { fontSize: 18, fontWeight: 700 }, fill: 0x8e93a6 }),
new ButtonBlock({ width: 96, height: 96, shape: 'circle', label: '+1', onPress: () => coins.value++ }),
]);
app.stage.addChild(bar);
Extends#
Constructors#
Constructor#
new BlockSurface(options?: BlockSurfaceOptions): BlockSurface;
Parameters#
| Parameter | Type |
|---|---|
options | BlockSurfaceOptions |
Returns#
BlockSurface
Overrides#
Properties#
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
lowEnd | readonly | boolean | Whether blocks use their cheap look. See BlockSurfaceOptions.lowEnd. | - | packages/pixi-silk/src/ui/blocks.ts:340 |
maxFps | public | number | Most repaints per second while something moves, 0 for every frame. | - | packages/pixi-silk/src/ui/blocks.ts:342 |
node | readonly | LayoutNode<Container<ContainerChild>> | The layout node of this container. A nested FlexContainer’s node sits in its parent’s tree. | SmartContainer.node | packages/pixi-silk/src/ui/layout/flex-container.ts:182 |
painter | readonly | SilkGraphics | The live layer: blocks that animate or change paint here, every frame while they move. | - | packages/pixi-silk/src/ui/blocks.ts:334 |
stats | readonly | BlockSurfaceStats | Repaints and loop state. | - | packages/pixi-silk/src/ui/blocks.ts:338 |
stillPainter | readonly | SilkGraphics | The still layer: blocks that do not change paint here once, then it is a cached texture. | - | packages/pixi-silk/src/ui/blocks.ts:336 |
Accessors#
area#
Get Signature#
get area(): Size;
The root’s layout area, from the last pass when it has no fixed size.
Returns
Inherited from#
box#
Get Signature#
get box(): {
height: number;
width: number;
};
The design box of the active record, in design units, after extendWidth and extendHeight.
Returns
{
height: number;
width: number;
}
| Name | Type | Defined in |
|---|---|---|
height | number | packages/pixi-silk/src/ui/layout/smart-container.ts:269 |
width | number | packages/pixi-silk/src/ui/layout/smart-container.ts:269 |
Inherited from#
breakpoint#
Get Signature#
get breakpoint(): string;
The active record’s name: a breakpoint name, portrait or landscape.
Returns
string
Inherited from#
breakpoints#
Get Signature#
get breakpoints(): readonly Breakpoint[];
Named records, tested in order before portrait and landscape. Missing values default as landscape.
Returns
readonly Breakpoint[]
Set Signature#
set breakpoints(list: readonly Breakpoint[]): void;
Parameters
| Parameter | Type |
|---|---|
list | readonly Breakpoint[] |
Returns
void
Inherited from#
landscapeData#
Get Signature#
get landscapeData(): LayoutData;
The effective landscape record (defaults merged with yours). Setting it updates the container.
Returns
Set Signature#
set landscapeData(data: LayoutData | undefined): void;
Parameters
| Parameter | Type |
|---|---|
data | LayoutData | undefined |
Returns
void
Inherited from#
layoutStyle#
Get Signature#
get layoutStyle(): SmartLayout;
The container’s own flex style.
Returns
Inherited from#
orientation#
Get Signature#
get orientation(): "portrait" | "landscape";
The orientation of the root’s layout area. A square counts as landscape.
Returns
"portrait" | "landscape"
Inherited from#
portraitData#
Get Signature#
get portraitData(): LayoutData;
The effective portrait record (defaults merged with yours). Setting it updates the container.
Returns
Set Signature#
set portraitData(data: LayoutData | undefined): void;
Parameters
| Parameter | Type |
|---|---|
data | LayoutData | undefined |
Returns
void
Inherited from#
Methods#
add()#
add<T extends ContainerChild>(child: T, style?: SmartLayout): T;
Adds child with a layout style. Returns the child.
Type Parameters#
| Type Parameter |
|---|
T extends ContainerChild |
Parameters#
| Parameter | Type |
|---|---|
child | T |
style | SmartLayout |
Returns#
T
Inherited from#
destroy()#
destroy(options?: DestroyOptions): void;
Stops the loop and drops the caches. Pass { children: true } to destroy the blocks too.
Parameters#
| Parameter | Type |
|---|---|
options? | DestroyOptions |
Returns#
void
Overrides#
getLayout()#
getLayout(child: Container): SmartLayout;
The layout style of child, or {} when it has none.
Parameters#
| Parameter | Type |
|---|---|
child | Container |
Returns#
Inherited from#
invalidate()#
invalidate(child?: Container<ContainerChild>): this;
Lays out again on the next frame. Pass a child whose content changed (new text, a new texture) so it is measured again.
Parameters#
| Parameter | Type |
|---|---|
child? | Container<ContainerChild> |
Returns#
this
Inherited from#
paintNow()#
paintNow(dt?: number): boolean;
Steps every block, repaints both layers now, outside the loop, and caches them. Returns true while a block moves.
Parameters#
| Parameter | Type | Default value |
|---|---|---|
dt | number | 0 |
Returns#
boolean
resize()#
resize(width: number, height: number): this;
Root only: lays out in an area of this size, in local units. Without it the root sizes to its content.
Parameters#
| Parameter | Type |
|---|---|
width | number |
height | number |
Returns#
this
Inherited from#
setLayout()#
setLayout(child: Container, style: SmartLayout): this;
Gives child a layout style, replacing the old one. It need not be a child yet.
Parameters#
| Parameter | Type |
|---|---|
child | Container |
style | SmartLayout |
Returns#
this
Inherited from#
setSafeArea()#
setSafeArea(insets: Insets): this;
Keeps boxes clear of these window insets, in screen pixels.
Parameters#
| Parameter | Type |
|---|---|
insets | Insets |
Returns#
this
Inherited from#
setStyle()#
setStyle(style: SmartLayout): this;
Replaces the container’s own flex style and lays out on the next frame.
Parameters#
| Parameter | Type |
|---|---|
style | SmartLayout |
Returns#
this
Inherited from#
setViewport()#
setViewport(source: ViewportSource | null): this;
Follows a new window source and places the container at once. null stops following and leaves it where it is.
Parameters#
| Parameter | Type |
|---|---|
source | ViewportSource | null |
Returns#
this
Inherited from#
slotOf()#
slotOf(child: Container):
| {
height: number;
width: number;
x: number;
y: number;
}
| undefined;
A copy of the slot child got in the last pass, in this container’s space. Undefined for a child without a style.
Parameters#
| Parameter | Type |
|---|---|
child | Container |
Returns#
| {
height: number;
width: number;
x: number;
y: number;
}
| undefined
Inherited from#
tick()#
tick(dt: number): boolean;
Advances layout and transitions by dt seconds (only needed with ticker: null). Returns true while busy.
Parameters#
| Parameter | Type |
|---|---|
dt | number |
Returns#
boolean
Inherited from#
updateContainer()#
updateContainer(): void;
Places and scales the container for the current window. It runs on every viewport change. Call it yourself after changing a plain rectangle source.
Returns#
void
Inherited from#
SmartContainer.updateContainer
updateLayout()#
updateLayout(): this;
Lays out the whole tree now, from its root, instead of on the next frame.
Returns#
this
Inherited from#
wake()#
wake(): void;
Repaints every layer on the next frame. Blocks call Block.wake instead.
Returns#
void