Skip to main content
utils-layout solves the challenge of positioning PixiJS display objects across a wide range of screen sizes and orientations. Unlike HTML, PixiJS does not have automatic layout flow — every element must be placed with explicit coordinates. utils-layout provides reactive size, ratio, and device-type values derived from the browser window.

createLayout()

Factory function that returns stateLayout and stateLayoutDerived. Create it once per game.

Parameters

stateLayout

Mutable reactive state. Currently contains one field:
Set stateLayout.showLoadingScreen = false once all assets have loaded to transition the game into the playable state.

stateLayoutDerived

All values are functions (not plain values) because they are computed from innerWidth.current and innerHeight.current from Svelte’s svelte/reactivity/window — they update automatically whenever the window is resized.

canvasRatioType break points

canvasSizeType break points (shortest dimension)

layoutType derivation

How canvasSizes is driven

Because PIXI.Application is configured with resizeTo: window, the PixiJS canvas always matches the window. createLayout reads innerWidth and innerHeight from svelte/reactivity/window so all derived values stay in sync with every window resize:

Positioning PixiJS elements

For HTML, elements flow automatically. In PixiJS, coordinates must be explicit. stateLayoutDerived.canvasSizes() provides the canvas boundary:
Coordinates are relative to the parent <Container />. When a component is a direct child of <App />, canvasSizes() gives the canvas boundary. Inside a nested <Container />, positions are relative to that container’s origin.

isStacked

isStacked() returns true for portrait and tablet (almostSquare) layout types. Use it to switch between stacked (vertical) and side-by-side (horizontal) UI arrangements:

ContextLayout

Context key: '@@layout'.