Skip to content
pixi-silk
GitHub repository
Entry point

pixi-silk/ui/blocks

BlockSurface, Block, ButtonBlock, CounterBlock, TextBlock, PanelBlock, stack and group. UI that paints shapes and text into a cached still layer, and a live layer for what moves.

import { Block, BlockSurface, ButtonBlock, CounterBlock } from 'pixi-silk/ui/blocks';

Classes#

ClassDescription
BlockA 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.
BlockSurfaceA 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.
ButtonBlockA button: a face that squishes on press, lights on hover, crossfades to its active colour and dims when disabled. Label and icon draw in the same call as the face.
CounterBlockA number that counts to its signal’s value with an ease-out, a frame at a time, then lets the surface sleep. Each value it shows is laid out once and cached.
PanelBlockA rounded panel: a background for a group or the whole surface ({ position: 'absolute', inset: 0 }).
TextBlockA line or paragraph of text, drawn with drawText into the painter. Without a width or height it takes the size of its text when it is made.

Interfaces#

InterfaceDescription
BlockOptionsSize of a block, in the surface’s design units.
BlockSurfaceOptionsOptions of a BlockSurface.
BlockSurfaceStatsWhat a BlockSurface has done: for a debug overlay.
ButtonBlockOptionsOptions of a ButtonBlock.
ButtonColorsColours of a ButtonBlock.
CounterBlockOptionsOptions of a CounterBlock.
PanelBlockOptionsOptions of a PanelBlock.
PressableOptionsOptions of pressable.
PressStateHover and press state of a pressable block: springs from 0 to 1.
TextBlockOptionsOptions of a TextBlock.

Type Aliases#

Type AliasDescription
BlockLayerA layer of a BlockSurface: see BlockOptions.layer.
IconPainterDraws a button’s icon centred on (cx, cy), about size across. t goes from 0 to 1 as the button turns active.
StackItemAn item of stack or group: a block (laid out with its own size), a container, or either with a style.
ValueA value a block reads: a plain value, or a signal the block follows.

Functions#

FunctionDescription
groupA FlexContainer laid out by style (a row, a column, a box with padding) holding items. Put it in a surface or in another group: blocks inside it still paint into the surface. It has no layout loop of its own, so on its own (as a root) it is laid out only by updateLayout().
readReads a Value: the signal’s current value, or the value itself.
stackAdds items to parent in order: blocks with Block.layout, other containers with the given style or none. With style, the items go into a new group first, and the group goes into parent. Returns the container the items went into.