Skip to main content

Ui

Description​

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

Properties​

I'll create a table in the same format for the provided schema:

Properties​

PropertyTypeDefaultDescription
type (Required)stringSupported types are: 'overlay' and '3d'
fontstringFont to use
fontSizef32Size of the text
positionstringPositioning type
opacityf321Overall opacity of the object
backgroundOpacityf320Opacity of the background
backgroundSizestringSize of the background
backgroundstringBackground color
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
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’

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)