UISystem. UIObject

UI Object - Base level object for all UI elements

Constructor

new UIObject(posopt, sizeopt)

Create a UIObject

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>
vec2()
sizeVector2<optional>
vec2()

Members

activeColor :Color|undefined

Type:
  • Color | undefined
Properties
TypeDescription
Color | undefined

Color of the object when active, uses hoverColor if undefined

align :'left'|'center'|'right'

Type:
  • 'left' | 'center' | 'right'
Properties
TypeDescription
'left' | 'center' | 'right'

Horizontal text alignment: left, center, or right

anchor

Properties
TypeDescription
Vector2

Where on parent (or canvas if no parent) this object is anchored. Components in [-1, 1]: (0,0)=center, (-1,-1)=top-left, (1,1)=bottom-right. Also acts as self-pivot — e.g. (1,-1) puts your top-right corner at the anchor point.

canBeHover

Properties
TypeDescription
boolean

True if this can be a hover object

children :Array.<UIObject>

Type:
  • Array.<UIObject>
Properties
TypeDescription
Array.<UIObject>

A list of this object's children

color

Properties
TypeDescription
Color

Color of the object

cornerRadius

Properties
TypeDescription
number

Corner radius for rounded rects

destroyed

Properties
TypeDescription
boolean

Has this object been destroyed?

disabled

Properties
TypeDescription
boolean

Is this object disabled?

disabledColor

Properties
TypeDescription
Color

Color when disabled

dragActivate

Properties
TypeDescription
boolean

Activate when dragged over with mouse held down

extraTouchSize

Properties
TypeDescription
number

Added size to make small buttons easier to touch on mobile devices

font

Properties
TypeDescription
string

Font for this object

fontStyle :string|undefined

Type:
  • string | undefined
Properties
TypeDescription
string | undefined

Font style for this object or undefined

gradientColor :Color|undefined

Type:
  • Color | undefined
Properties
TypeDescription
Color | undefined

Uses a gradient fill combined with color

hoverColor

Properties
TypeDescription
Color

Color used when hovering over the object

interactive

Properties
TypeDescription
boolean

Is this element interactive

lineColor

Properties
TypeDescription
Color

Color for line drawing

lineWidth

Properties
TypeDescription
number

Width for line drawing

localPos

Properties
TypeDescription
Vector2

Position you set: an offset from this object's anchor point (the parent box, or the canvas for roots). This is the input that controls placement — set this, not nativePos.

nativePos

Properties
TypeDescription
Vector2

Resolved position in native UI space, recomputed every frame from localPos + anchor (and nativeHeight, if set). This is a derived output used for drawing and hit-testing; assigning to it has no effect since it is overwritten each frame. Set localPos instead.

Properties
TypeDescription
boolean

Should this be auto selected by navigation? Must also have valid navigation index.

Type:
  • number | undefined
Properties
TypeDescription
number | undefined

Optional navigation order index, lower values are selected first

parent :UIObject|undefined

Type:
  • UIObject | undefined
Properties
TypeDescription
UIObject | undefined

This object's parent, position is in parent space

shadowBlur

Properties
TypeDescription
number

Size of shadow blur

shadowColor

Properties
TypeDescription
Color

Color for shadow

shadowOffset

Properties
TypeDescription
Vector2

Offset of shadow blur

size

Properties
TypeDescription
Vector2

Screen space size of the object

slice :TileSlice|undefined

Type:
  • TileSlice | undefined
Properties
TypeDescription
TileSlice | undefined

Style to draw with in place of the rectangle, tinted by the color for its state; its art has the frame, so the outline, corner radius and shadow are not drawn

soundClick :Sound|undefined

Type:
  • Sound | undefined
Properties
TypeDescription
Sound | undefined

Sound when interactive element is clicked

soundPress :Sound|undefined

Type:
  • Sound | undefined
Properties
TypeDescription
Sound | undefined

Sound when interactive element is pressed

soundRelease :Sound|undefined

Type:
  • Sound | undefined
Properties
TypeDescription
Sound | undefined

Sound when interactive element is released

text :string|undefined

Type:
  • string | undefined
Properties
TypeDescription
string | undefined

Text for this ui object

textColor

Properties
TypeDescription
Color

Color for text

textFitScale

Properties
TypeDescription
number

Scale text to fit in the object

textHeight :number|undefined

Type:
  • number | undefined
Properties
TypeDescription
number | undefined

Override for text height

textLineColor

Properties
TypeDescription
Color

Color for text line drawing

textLineWidth

Properties
TypeDescription
number

Width for text line drawing

textShadow :Vector2|undefined

Type:
  • Vector2 | undefined
Properties
TypeDescription
Vector2 | undefined

How much to offset the text shadow or undefined. UIText draws it in its shadowColor, which is clear by default, so set that too; the blurred shadow then shows as well unless shadowBlur and shadowOffset are zero. The other widgets draw it in black

textWidth :number|undefined

Type:
  • number | undefined
Properties
TypeDescription
number | undefined

Override for text width

visible

Properties
TypeDescription
boolean

Should this object be drawn

Methods

addChild(child) → {UIObject}

Add a child UIObject to this object, returns child for chaining

Parameters:
NameTypeDescription
childUIObject
Returns:

The child object added

Type: 
UIObject

click(playSoundopt)

Internal function called when object is clicked

Parameters:
NameTypeAttributesDefaultDescription
playSoundboolean<optional>
true

destroy()

Destroy this object, destroy its children, detach its parent, and mark it for removal

getTextPos(textSize) → {Vector2}

Get where the text is drawn, the center, or the edge of the text area its align puts it against

Parameters:
NameTypeDescription
textSizeVector2

From getTextSize

Returns:
Type: 
Vector2

getTextSize() → {Vector2}

Get the size for text with overrides and scale

Returns:
Type: 
Vector2

isActiveObject() → {boolean}

Returns:
  • Is the mouse held onto this element
Type: 
boolean

isHoverObject() → {boolean}

Returns:
  • Is the mouse hovering over this element
Type: 
boolean

isInteractive() → {boolean}

Returns:
  • Can it be interacted with, it and every parent visible and enabled
Type: 
boolean

isKeyInputObject() → {boolean}

Returns:
  • Is this object in keyboard input mode
Type: 
boolean

isMouseOverlapping() → {boolean}

Check if the mouse is overlapping this ui object

Returns:
  • True if overlapping
Type: 
boolean

isNavigationObject() → {boolean}

Returns:
  • Is the gamepad or keyboard navigation object
Type: 
boolean

Called when the navigation button is pressed on this object

onChange()

Called when the state of this object changes

onClick()

Called when user clicks on this object

onEnter()

Called when the mouse enters the object

onKeyDown(e)

Called with each key while this is the keyInputObject

Parameters:
NameTypeDescription
eKeyboardEvent

onLeave()

Called when the mouse leaves the object

onPress()

Called when the mouse is pressed while over the object

onRelease()

Called when a press on it ends, wherever the mouse is let go, or when it is disabled or hidden while held, or an edit takes the press; onClick is the one for a press let go over it

onRender()

Called each frame before object renders

onUpdate()

Called each frame before object updates

removeChild(child)

Remove a child UIObject from this object

Parameters:
NameTypeDescription
childUIObject

render()

Render the object, called automatically by plugin once each frame

renderDebug(visibleopt)

Called if uiDebug is enabled

Parameters:
NameTypeAttributesDefaultDescription
visibleboolean<optional>
true

toString() → {string}

Returns string containing info about this object for debugging

Returns:
Type: 
string

update() → {void}

Update the object, called automatically by plugin once each frame

Returns:
Type: 
void