Skip to main content

Ui

Description

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

Properties

PropertyTypeDefaultDescription
typestring'overlay'Allowed values: 'overlay' , '3d'
fontstring'Nunito'Font to use
fontSizenumber16Size of the text
positionstring'static'Allowed values: 'static', 'relative', 'absolute'
opacitynumber1Overall opacity of the object
backgroundOpacitynumber-1Opacity of the background. -1 is interpreted as 0 if there is no image, and 1 if there is an image.
backgroundSizestring'contain'Sets the size of the background image. Allowed values: 'stretch', 'contain', 'cover', 'nineSlice'.
backgroundstring'#ffffff'Background color
borderColorstring'#000000'Color of the border
colorstring'#ffffff'Foreground (text) color
textstring''Text content of the object
imagestring''Image resource
fixedSizebooleanfalseDetermines if size is fixed
widthstring'100'Width of the object
heightstring'100'Height of the object
topstring''Vertical position from top border
leftstring''Horizontal position from left border
bottomstring''Vertical position from bottom border
rightstring''Horizontal position from right border
borderRadiusnumber0Rounds all corners of the element
borderRadiusTopLeftstring''Rounds the top left corner of the element
borderRadiusTopRightstring''Rounds the top right corner of the element
borderRadiusBottomLeftstring''Rounds the bottom left corner of the element
borderRadiusBottomRightstring''Rounds the bottom right corner of the element
alignContentstring'flex-start'Distribution of space between content items. Allowed values: 'flex-start', 'center', 'flex-end', 'stretch', 'space-between', 'space-around'.
alignItemsstring'flex-start'Alignment of items on the cross axis. Allowed values: 'flex-start', 'center', 'flex-end', 'stretch', 'baseline'.
alignSelfstring''Alignment of an individual flex item. Allowed values: 'auto', 'flex-start', 'center', 'flex-end', 'stretch', 'baseline'.
borderWidthnumber0Width of the border
columnGapstring''Gap between columns
directionstring'ltr'Text direction. Allowed values: 'inherit', 'ltr', 'rtl'.
displaystring''Display type of the element. Allowed values: 'flex', 'none'.
flexnumber0Flex grow, shrink, and basis shorthand
flexBasisstring''Initial main size of a flex item
flexDirectionstring'row'Direction of flex items in the container. Allowed values: 'column', 'column-reverse', 'row', 'row-reverse'.
flexGrownumber0Defines the ability for a flex item to grow
flexShrinknumber0Defines the ability for a flex item to shrink
flexWrapstring'nowrap'Whether flex items wrap. Allowed values: 'no-wrap', 'wrap', 'wrap-reverse'.
gapstring''Gap between flex items
justifyContentstring'flex-start'Alignment of items on the main axis. Allowed values: 'flex-start', 'center', 'flex-end', 'space-between', 'space-around', 'space-evenly'.
marginstring''Margin for all sides around the element
marginBottomstring''Bottom margin
marginLeftstring''Left margin
marginRightstring''Right margin
marginTopstring''Top margin
maxHeightstring''Maximum height of the element
maxWidthstring''Maximum width of the element
minHeightstring''Minimum height of the element
minWidthstring''Minimum width of the element
overflowstring''How content that exceeds the element’s size is handled. Allowed values: 'visible', 'hidden', 'scroll'.
paddingstring''Padding for all sides inside the element
paddingBottomstring''Bottom padding
paddingLeftstring''Left padding
paddingRightstring''Right padding
paddingTopstring''Top padding
rowGapstring''Gap between rows
textAlignstring'center'Alignment of text within the element. Allowed values: 'left', 'right', 'center', 'justify'.
stackingOrdernumber0Determines the rendering order of UI elements. Elements with higher values are drawn above those with lower values. A value of 0 uses the default behavior, rendering elements according to their order in the scene hierarchy
ignoreRaycastbooleanfalseDetermines whether the UI element should respond to user interactions like clicks or taps
nineSliceBorderTopstring'0'Size of the top border used in nine-slice scaling. Defines how much of the top portion is preserved without scaling.
nineSliceBorderBottomstring'0'Size of the bottom border used in nine-slice scaling. Defines how much of the bottom portion is preserved without scaling.
nineSliceBorderLeftstring'0'Size of the left border used in nine-slice scaling. Defines how much of the left portion is preserved without scaling.
nineSliceBorderRightstring'0'Size of the right border used in nine-slice scaling. Defines how much of the right portion is preserved without scaling.
nineSliceScaleFactornumber1Multiplier applied to the scaled center area in nine-slice backgrounds. Allows finer control over the scaling of the center portion.
verticalTextAlignstring'start'Vertical alignment of the text within the element

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)