Skip to content
pixi-silk
GitHub repository
Class

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#

ParameterType
optionsBlockSurfaceOptions

Returns#

BlockSurface

Overrides#

SmartContainer.constructor

Properties#

PropertyModifierTypeDescriptionInherited fromDefined in
lowEndreadonlybooleanWhether blocks use their cheap look. See BlockSurfaceOptions.lowEnd.-packages/pixi-silk/src/ui/blocks.ts:340
maxFpspublicnumberMost repaints per second while something moves, 0 for every frame.-packages/pixi-silk/src/ui/blocks.ts:342
nodereadonlyLayoutNode<Container<ContainerChild>>The layout node of this container. A nested FlexContainer’s node sits in its parent’s tree.SmartContainer.nodepackages/pixi-silk/src/ui/layout/flex-container.ts:182
painterreadonlySilkGraphicsThe live layer: blocks that animate or change paint here, every frame while they move.-packages/pixi-silk/src/ui/blocks.ts:334
statsreadonlyBlockSurfaceStatsRepaints and loop state.-packages/pixi-silk/src/ui/blocks.ts:338
stillPainterreadonlySilkGraphicsThe 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

Size

Inherited from#

SmartContainer.area


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;
}
NameTypeDefined in
heightnumberpackages/pixi-silk/src/ui/layout/smart-container.ts:269
widthnumberpackages/pixi-silk/src/ui/layout/smart-container.ts:269

Inherited from#

SmartContainer.box


breakpoint#

Get Signature#

get breakpoint(): string;

The active record’s name: a breakpoint name, portrait or landscape.

Returns

string

Inherited from#

SmartContainer.breakpoint


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
ParameterType
listreadonly Breakpoint[]
Returns

void

Inherited from#

SmartContainer.breakpoints


landscapeData#

Get Signature#

get landscapeData(): LayoutData;

The effective landscape record (defaults merged with yours). Setting it updates the container.

Returns

LayoutData

Set Signature#

set landscapeData(data: LayoutData | undefined): void;
Parameters
ParameterType
dataLayoutData | undefined
Returns

void

Inherited from#

SmartContainer.landscapeData


layoutStyle#

Get Signature#

get layoutStyle(): SmartLayout;

The container’s own flex style.

Returns

SmartLayout

Inherited from#

SmartContainer.layoutStyle


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#

SmartContainer.orientation


portraitData#

Get Signature#

get portraitData(): LayoutData;

The effective portrait record (defaults merged with yours). Setting it updates the container.

Returns

LayoutData

Set Signature#

set portraitData(data: LayoutData | undefined): void;
Parameters
ParameterType
dataLayoutData | undefined
Returns

void

Inherited from#

SmartContainer.portraitData

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#

ParameterType
childT
styleSmartLayout

Returns#

T

Inherited from#

SmartContainer.add


destroy()#

destroy(options?: DestroyOptions): void;

Stops the loop and drops the caches. Pass { children: true } to destroy the blocks too.

Parameters#

ParameterType
options?DestroyOptions

Returns#

void

Overrides#

SmartContainer.destroy


getLayout()#

getLayout(child: Container): SmartLayout;

The layout style of child, or {} when it has none.

Parameters#

ParameterType
childContainer

Returns#

SmartLayout

Inherited from#

SmartContainer.getLayout


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#

ParameterType
child?Container<ContainerChild>

Returns#

this

Inherited from#

SmartContainer.invalidate


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#

ParameterTypeDefault value
dtnumber0

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#

ParameterType
widthnumber
heightnumber

Returns#

this

Inherited from#

SmartContainer.resize


setLayout()#

setLayout(child: Container, style: SmartLayout): this;

Gives child a layout style, replacing the old one. It need not be a child yet.

Parameters#

ParameterType
childContainer
styleSmartLayout

Returns#

this

Inherited from#

SmartContainer.setLayout


setSafeArea()#

setSafeArea(insets: Insets): this;

Keeps boxes clear of these window insets, in screen pixels.

Parameters#

ParameterType
insetsInsets

Returns#

this

Inherited from#

SmartContainer.setSafeArea


setStyle()#

setStyle(style: SmartLayout): this;

Replaces the container’s own flex style and lays out on the next frame.

Parameters#

ParameterType
styleSmartLayout

Returns#

this

Inherited from#

SmartContainer.setStyle


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#

ParameterType
sourceViewportSource | null

Returns#

this

Inherited from#

SmartContainer.setViewport


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#

ParameterType
childContainer

Returns#

| { height: number; width: number; x: number; y: number; } | undefined

Inherited from#

SmartContainer.slotOf


tick()#

tick(dt: number): boolean;

Advances layout and transitions by dt seconds (only needed with ticker: null). Returns true while busy.

Parameters#

ParameterType
dtnumber

Returns#

boolean

Inherited from#

SmartContainer.tick


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#

SmartContainer.updateLayout


wake()#

wake(): void;

Repaints every layer on the next frame. Blocks call Block.wake instead.

Returns#

void