Layout
dill pixel includes two useful classes for laying out elements on the canvas: UICanvas
and FlexContainer
.
UICanvas
The UICanvas
class extends PIXI’s Container
and is used for
absolutely positioning elements on the canvas. It’s very handy for persistent UI elements
like menus, scores, and other HUD elements.
The align
property can be set to one of the following values:
top left
top
top right
left
center
right
bottom left
bottom
bottom right
Specifying padding
will add space around the element.
Flex Container
The FlexContainer
class extends PIXI’s Container
and is based
on the CSS Flexbox layout model. It’s useful for aligning and arranging elements in a row or column.
As new elements are added to (or removed from) the flex container, they will be automtically arranged based on the properties you’ve set.
Direction
The flexDirection
property can be set to either row
or column
.
Align Items
The alignItems
property can be set to one of the following values:
flex-start
center
flex-end
Justify Content
The justifyContent
property can be set to one of the following values:
flex-start
center
flex-end
space-between
space-around
space-evenly
Gap
The gap
property specifies the space between elements.
Wrap
The flexWrap
property can be set to either nowrap
(default) or wrap
. If set to wrap
, elements will
wrap to the next line when they reach the edge of the container (the size of the flex container must be
specified with width
and height
parameters for wrapping to occur).
Width and Height
The width
and height
properties are optional. If not specified, the container will expand to fit
its contents. If specified, the width
and height
will be used to determine when wrapping occurs and how the elements are
distributed within the container according to the justifyContent
property.