Skip to main content

Ui

Description

This component establishes a User Interface in relation to the entity.

Properties

PropertyTypeDefaultDescription
type (Required)stringSupported types are: 'overlay' and '3d'
fontstringFont to use
fontSizef32Size of the text
positionstring'relative'Choice of: 'relative' or 'absolute'
opacityf321Overall opacity of the object
backgroundOpacityf320Opacity of the background
backgroundSizestringBackground sizing behavior. Choose between ‘stretch’, 'contain’, 'cover’, 'nineSlice’
backgroundstringBackground color. Supports color and image.
colorstringForeground (text) color
textstring""Text content of the object
imagestringnullImage resource
fixedSizebooleanDetermines if size is fixed
widthstring100Width of the object
heightstring100Height of the object
topstringVertical position from top border
leftstringHorizontal position from left border
bottomstringVertical position from bottom border
rightstringHorizontal position from right border
borderColorstringColor of the border
borderRadiusf320Rounds the corners of the element
borderRadiusTopLeftf320Rounds the top left corner of the element
borderRadiusTopRightf320Rounds the top right corner of the element
borderRadiusBottomLeftf320Rounds the bottom left corner of the element
borderRadiusBottomRightf320Rounds the bottom right corner of the element
alignContentstringDistribution of space between content items; allowed values: 'flex-start’, 'center’, 'flex-end’, 'stretch’, 'space-between’, 'space-around’
alignItemsstringAlignment of items on the cross axis; allowed values: 'flex-start’, 'center’, 'flex-end’, 'stretch’, 'baseline’
alignSelfstringAlignment of an individual flex item; allowed values: 'auto’, 'flex-start’, 'center’, 'flex-end’, 'stretch’, 'baseline’
borderWidthf320Width of the border
columnGapstringGap between columns
directionstringText direction; allowed values: 'inherit’, 'LTR’, 'RTL’
displaystringDisplay type of the element; allowed values: 'flex’, 'none’
flexf32Flex grow, shrink, and basis shorthand
flexBasisstringInitial main size of a flex item
flexDirectionstringDirection of flex items in the container; allowed values: 'column’, 'column-reverse’, 'row’, 'row-reverse’
flexGrowf32Defines the ability for a flex item to grow
flexShrinkf32Defines the ability for a flex item to shrink
flexWrapstringWhether flex items wrap; allowed values: 'no-wrap’, 'wrap’, 'wrap-reverse’
gapstringGap between flex items
justifyContentstringAlignment of items on the main axis; allowed values: 'flex-start’, 'center’, 'flex-end’, 'space-between’, 'space-around’, 'space-evenly’
marginstringMargin around the element
marginBottomstringBottom margin
marginLeftstringLeft margin
marginRightstringRight margin
marginTopstringTop margin
maxHeightstringMaximum height of the element
maxWidthstringMaximum width of the element
minHeightstringMinimum height of the element
minWidthstringMinimum width of the element
overflowstringHow content that exceeds the element’s size is handled; allowed values: 'visible’, 'hidden’, 'scroll’
paddingstringPadding inside the element
paddingBottomstringBottom padding
paddingLeftstringLeft padding
paddingRightstringRight padding
paddingTopstringTop padding
rowGapstringGap between rows
textAlignstringAlignment of text within the element; allowed values: 'left’, 'right’, 'center’, 'justify’
ignoreRaycastbooleanfalseDetermines whether the UI element should respond to user interactions like clicks or taps
stackingOrderf320Determines the rendering order of UI elements. Elements with higher values are drawn above those with lower values. By default elements are rendered according to their order in the scene hierarchy
nineSliceBorderTopstringSize of the top border used in nine-slice scaling. Defines how much of the top portion is preserved without scaling.
nineSliceBorderBottomstringSize of the bottom border used in nine-slice scaling. Defines how much of the bottom portion is preserved without scaling.
nineSliceBorderLeftstringSize of the left border used in nine-slice scaling. Defines how much of the left portion is preserved without scaling.
nineSliceBorderRightstringSize of the right border used in nine-slice scaling. Defines how much of the right portion is preserved without scaling.
nineSliceScaleFactorf32Multiplier applied to the scaled center area in nine-slice backgrounds. Allows finer control over the scaling of the center portion.

Functions

Get

Returns a read-only reference.

Example

ecs.Ui.get(world, component.eid)

Set

Ensures the component exists on the entity, then assigns the (optional) data to the component.

Example

ecs.Ui.set(world, component.eid, {
type: 'overlay',
background: '#FFFFFF'
})

Mutate

Perform an update to the component within a callback function. Return true to indicate no changes made.

Example

ecs.Ui.mutate(world, component.eid, (cursor) => {
cursor.opacity = 0.5;
cursor.text = 'Hello World!';
cursor.width = 150;
return false;
})

Remove

Removes the component from the entity.

Example

ecs.Ui.remove(world, component.eid)

Has

Returns true if the component is present on the entity.

Example

ecs.Ui.has(world, component.eid)

Reset

Adds, or resets the component to its default state.

Example

ecs.Ui.reset(world, component.eid)

Advanced Functions

Cursor

Returns a mutable reference. Cursors are reused so only one cursor for each component can exist at a time.

Example
ecs.Ui.cursor(world, component.eid)

Acquire

Same behavior as cursor, but commit must be called after the cursor is done being used.

Example
ecs.Ui.acquire(world, component.eid)

Commit

Called after acquire. An optional third argument determines whether the cursor was mutated or not.

Example
ecs.Ui.commit(world, component.eid)
ecs.Ui.commit(world, component.eid, false)

Dirty

Mark the entity as having been mutated. Only needed in a specific case where systems are mutating data.

Example
ecs.Ui.dirty(world, component.eid)