Constructor
new UIObject(posopt, sizeopt)
Create a UIObject
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | <optional> | vec2() | |
size | Vector2 | <optional> | vec2() |
- Source
Members
activeColor :Color|undefined
- Color |
undefined
| Type | Description |
|---|---|
| Color | | Color of the object when active, uses hoverColor if undefined |
- Source
align :'left'|'center'|'right'
- 'left' |
'center' | 'right'
| Type | Description |
|---|---|
| 'left' | | Horizontal text alignment: left, center, or right |
- Source
anchor
Properties| Type | Description |
|---|---|
| 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. |
- Source
canBeHover
Properties| Type | Description |
|---|---|
| boolean | True if this can be a hover object |
- Source
children :Array.<UIObject>
- Array.<UIObject>
| Type | Description |
|---|---|
| Array.<UIObject> | A list of this object's children |
- Source
color
Properties| Type | Description |
|---|---|
| Color | Color of the object |
- Source
cornerRadius
Properties| Type | Description |
|---|---|
| number | Corner radius for rounded rects |
- Source
destroyed
Properties| Type | Description |
|---|---|
| boolean | Has this object been destroyed? |
- Source
disabled
Properties| Type | Description |
|---|---|
| boolean | Is this object disabled? |
- Source
disabledColor
Properties| Type | Description |
|---|---|
| Color | Color when disabled |
- Source
dragActivate
Properties| Type | Description |
|---|---|
| boolean | Activate when dragged over with mouse held down |
- Source
extraTouchSize
Properties| Type | Description |
|---|---|
| number | Added size to make small buttons easier to touch on mobile devices |
- Source
font
Properties| Type | Description |
|---|---|
| string | Font for this object |
- Source
fontStyle :string|undefined
- string |
undefined
| Type | Description |
|---|---|
| string | | Font style for this object or undefined |
- Source
gradientColor :Color|undefined
- Color |
undefined
| Type | Description |
|---|---|
| Color | | Uses a gradient fill combined with color |
- Source
hoverColor
Properties| Type | Description |
|---|---|
| Color | Color used when hovering over the object |
- Source
interactive
Properties| Type | Description |
|---|---|
| boolean | Is this element interactive |
- Source
lineColor
Properties| Type | Description |
|---|---|
| Color | Color for line drawing |
- Source
lineWidth
Properties| Type | Description |
|---|---|
| number | Width for line drawing |
- Source
localPos
Properties| Type | Description |
|---|---|
| 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. |
- Source
nativePos
Properties| Type | Description |
|---|---|
| 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. |
- Source
navigationAutoSelect
Properties| Type | Description |
|---|---|
| boolean | Should this be auto selected by navigation? Must also have valid navigation index. |
- Source
navigationIndex :number|undefined
- number |
undefined
| Type | Description |
|---|---|
| number | | Optional navigation order index, lower values are selected first |
- Source
parent :UIObject|undefined
- UIObject |
undefined
| Type | Description |
|---|---|
| UIObject | | This object's parent, position is in parent space |
- Source
shadowBlur
Properties| Type | Description |
|---|---|
| number | Size of shadow blur |
- Source
shadowColor
Properties| Type | Description |
|---|---|
| Color | Color for shadow |
- Source
shadowOffset
Properties| Type | Description |
|---|---|
| Vector2 | Offset of shadow blur |
- Source
size
Properties| Type | Description |
|---|---|
| Vector2 | Screen space size of the object |
- Source
slice :TileSlice|undefined
- TileSlice |
undefined
| Type | Description |
|---|---|
| TileSlice | | 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 |
- Source
soundClick :Sound|undefined
- Sound |
undefined
| Type | Description |
|---|---|
| Sound | | Sound when interactive element is clicked |
- Source
soundPress :Sound|undefined
- Sound |
undefined
| Type | Description |
|---|---|
| Sound | | Sound when interactive element is pressed |
- Source
soundRelease :Sound|undefined
- Sound |
undefined
| Type | Description |
|---|---|
| Sound | | Sound when interactive element is released |
- Source
text :string|undefined
- string |
undefined
| Type | Description |
|---|---|
| string | | Text for this ui object |
- Source
textColor
Properties| Type | Description |
|---|---|
| Color | Color for text |
- Source
textFitScale
Properties| Type | Description |
|---|---|
| number | Scale text to fit in the object |
- Source
textHeight :number|undefined
- number |
undefined
| Type | Description |
|---|---|
| number | | Override for text height |
- Source
textLineColor
Properties| Type | Description |
|---|---|
| Color | Color for text line drawing |
- Source
textLineWidth
Properties| Type | Description |
|---|---|
| number | Width for text line drawing |
- Source
textShadow :Vector2|undefined
- Vector2 |
undefined
| Type | Description |
|---|---|
| Vector2 | | 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 |
- Source
textWidth :number|undefined
- number |
undefined
| Type | Description |
|---|---|
| number | | Override for text width |
- Source
visible
Properties| Type | Description |
|---|---|
| boolean | Should this object be drawn |
- Source
Methods
addChild(child) → {UIObject}
Add a child UIObject to this object, returns child for chaining
| Name | Type | Description |
|---|---|---|
child | UIObject |
- Source
The child object added
- Type:
- UIObject
click(playSoundopt)
Internal function called when object is clicked
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
playSound | boolean | <optional> | true |
- Source
destroy()
Destroy this object, destroy its children, detach its parent, and mark it for removal
- Source
getTextPos(textSize) → {Vector2}
Get where the text is drawn, the center, or the edge of the text area its align puts it against
| Name | Type | Description |
|---|---|---|
textSize | Vector2 | From getTextSize |
- Source
- Type:
- Vector2
getTextSize() → {Vector2}
Get the size for text with overrides and scale
- Source
- Type:
- Vector2
isActiveObject() → {boolean}
- Source
- Is the mouse held onto this element
- Type:
- boolean
isHoverObject() → {boolean}
- Source
- Is the mouse hovering over this element
- Type:
- boolean
isInteractive() → {boolean}
- Source
- Can it be interacted with, it and every parent visible and enabled
- Type:
- boolean
isKeyInputObject() → {boolean}
- Source
- Is this object in keyboard input mode
- Type:
- boolean
isMouseOverlapping() → {boolean}
Check if the mouse is overlapping this ui object
- Source
- True if overlapping
- Type:
- boolean
isNavigationObject() → {boolean}
- Source
- Is the gamepad or keyboard navigation object
- Type:
- boolean
navigatePressed()
Called when the navigation button is pressed on this object
- Source
onChange()
Called when the state of this object changes
- Source
onClick()
Called when user clicks on this object
- Source
onEnter()
Called when the mouse enters the object
- Source
onKeyDown(e)
Called with each key while this is the keyInputObject
| Name | Type | Description |
|---|---|---|
e | KeyboardEvent |
- Source
onLeave()
Called when the mouse leaves the object
- Source
onPress()
Called when the mouse is pressed while over the object
- Source
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
- Source
onRender()
Called each frame before object renders
- Source
onUpdate()
Called each frame before object updates
- Source
removeChild(child)
Remove a child UIObject from this object
| Name | Type | Description |
|---|---|---|
child | UIObject |
- Source
render()
Render the object, called automatically by plugin once each frame
- Source
renderDebug(visibleopt)
Called if uiDebug is enabled
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
visible | boolean | <optional> | true |
- Source
toString() → {string}
Returns string containing info about this object for debugging
- Source
- Type:
- string
update() → {void}
Update the object, called automatically by plugin once each frame
- Source
- Type:
- void