Skip to content
pixi-silk
GitHub repository
Entry point

pixi-silk/ui/layout

SmartContainer and FlexContainer: place and scale a design box in the window, flex children inside it.

import { FlexContainer, SimulatedViewport, SmartContainer, DEVICES } from 'pixi-silk/ui/layout';

Classes#

ClassDescription
FlexContainerA container that lays out its children with flexbox. Give a child a style with FlexContainer.setLayout (or add it with FlexContainer.add). The container places it in its slot once per frame, and only after something changed: a child added, removed or restyled, a new size, or FlexContainer.invalidate.
SimulatedViewportPreviews a window size inside a desktop page: a device of that size, scaled down to fit an area (letterboxed), with a bezel and a mask. Add SmartContainers to SimulatedViewport.content and pass the simulator itself as their viewport: it is a signal of the device’s window, so they lay out as they would on that device.
SmartContainerA responsive container for portrait and landscape screens. It places and scales itself in the window from layout records against a reference resolution. A record has a design box, a reference resolution it fits or covers, an alignment, and optional stretch and corrections. It picks portraitData when the window is taller than wide, landscapeData otherwise, or the first matching named breakpoint.

Interfaces#

InterfaceDescription
BreakpointA named layout record that applies when when returns true for the window size.
FlexContainerOptionsOptions of FlexContainer.
InsetsDistances from the window edges, in screen pixels: notches, rounded corners, home bars.
LayoutDataWhere a SmartContainer sits on screen and how it scales, for one breakpoint. The box is in design units, and the reference resolution sets how design units map to the window.
LayoutDebugThe handle layoutDebug returns.
LayoutDebugOptionsOptions of layoutDebug.
MediaRuleA style that applies when the root’s layout area, or the root SmartContainer’s breakpoint, matches.
PlacementWhere placeBox put a design box: position and scale in the window’s space, and the box size.
SimulatedViewportOptionsOptions of SimulatedViewport.
SmartContainerOptionsOptions of SmartContainer.
SmartLayoutA responsive style: base values, then portrait or landscape, then each matching media rule in order. Rules test the root container’s layout area.
SmartStyleA flex style plus how a child sits in its slot.
ViewportRectA window rectangle in screen pixels.

Type Aliases#

Type AliasDescription
FitModeHow a child scales into its slot, as CSS object-fit. none keeps its size, contain fits inside, cover fills and overflows, scale-down is contain that never enlarges, fill stretches both axes.
ViewportSourceWhat a SmartContainer follows: an Application or a renderer (it updates on their resize), a signal of a rectangle (it updates on change), or a plain rectangle (call updateContainer()).

Variables#

VariableDescription
DEVICESWindow sizes to preview, in CSS pixels.

Functions#

FunctionDescription
fitScaleThe [x, y] scale of a child of natural size w by h in a slot, for a fit mode. [1, 1] for none or an empty child.
layoutDebugA debug overlay for SmartContainers and FlexContainers, off by default. It draws over the whole stage, in screen pixels:
placeBoxWhere a record puts its box in a window: the fit scale of the window to the reference resolution, then stretch per axis, then the corrections, then the alignment. Pure, so you can check a layout record without a renderer. Writes into out when given, else returns a new object.
simulateViewportCreates a SimulatedViewport. Same as new SimulatedViewport(options).
wrapTextA measure that wraps a text child to the width offered: Pixi Text (through its style) or SilkText. Long copy then breaks into lines instead of overflowing its slot. It turns on the child’s wordWrap and sets wordWrapWidth. Other children are measured by their bounds.