Skip to content
pixi-silk
GitHub repository
Class

Block

import { Block } from 'pixi-silk/ui/blocks';

A piece of UI that paints into its surface’s painter. Subclass it and implement Block.paint: draw at (x, y), the top-left corner of the block’s slot, with the size in w and h. Animate with spring, follow state with watch, take input with pressable. Put blocks in a BlockSurface with Block.layout or stack.

Extends#

  • Container

Extended by#

Constructors#

Constructor#

new Block(options?: BlockOptions): Block;

Parameters#

ParameterType
optionsBlockOptions

Returns#

Block

Overrides#

Container.constructor

Properties#

PropertyModifierTypeDescriptionDefined in
hpublicnumberHeight of the slot, design units. The layout sets it.packages/pixi-silk/src/ui/blocks.ts:86
layerreadonlyBlockLayerThe layer it asked for. See BlockOptions.layer.packages/pixi-silk/src/ui/blocks.ts:88
wpublicnumberWidth of the slot, design units. The layout sets it.packages/pixi-silk/src/ui/blocks.ts:84

Accessors#

surface#

Get Signature#

get surface(): BlockSurface | null;

The surface the block is in, or null.

Returns

BlockSurface | null

Methods#

destroy()#

destroy(options?: DestroyOptions): void;

Stops following watched signals.

Parameters#

ParameterType
options?DestroyOptions

Returns#

void

Overrides#

Container.destroy

layout()#

layout(style?: SmartLayout): SmartLayout;

The flex style of this block’s slot: its size, no shrinking, and an onSize that keeps w and h in step with the layout. An absolute slot stretched between two edges (inset, or left and right) takes its size from them instead. Pass it to add of a FlexContainer or SmartContainer.

Parameters#

ParameterType
styleSmartLayout

Returns#

SmartLayout


paint()#

abstract paint(
   g: SilkGraphics, 
   x: number, 
   y: number
): void;

Draws the block into g with its slot’s top-left corner at (x, y), in the surface’s space.

Parameters#

ParameterType
gSilkGraphics
xnumber
ynumber

Returns#

void


step()#

step(dt: number): boolean;

Advances the block’s springs by dt seconds. Returns true while any moves. Override it to animate something else, and return true while that runs.

Parameters#

ParameterType
dtnumber

Returns#

boolean


wake()#

wake(): void;

Asks the surface to repaint this block. The surface repaints until every block settles, then sleeps. The first call moves an 'auto' block to the live layer.

Returns#

void