Skip to main content

Base component (UiBaseComponent)

This is the base internal component that all other components extend. It defines variables and methods that are widely used.

It is not meant for direct usage but this page acts as reference.

Variables

VariableDescriptionTypeDefault
parentParent componentRealglobal.ui_root_component
stepFunction called each tick to handle the component logicFunction
drawFunction called each tick to render the componentFunction
skip_layer_checksWhen this component should skip the parent layer hovering checksBoolfalse
disable_surfaceIf to disable the component surfaceBoolfalse
childrenList of the children componentsArray<Struct>[]
stateComponent stateStructSee below

State reference

VariableDescriptionTypeDefault
xComponent XReal
yComponent YReal
widthComponent widthReal
heightComponent heightReal
scroll_xCurrent X scroll positionReal0
scroll_yCurrent Y scroll positionReal0
on_clickComponent stateFunctionfunction() {}
enabledWhether the step/draw events are executedBooltrue
activeWhether the step event is executedBooltrue
visibleWhether the draw event is executedBooltrue

Methods

set(partial_state)

Updates the state and sets the component and its ancestors as updated

ParamDescriptionTypeDefault
partial_stateState variables to updateStruct

update()

Directly sets the component and its ancestors as updated. Useful when manually updating the state

click()

Executes the on_click handler defined for this component. Syntax sugar for state.on_click(self);

remove()

Removes this component from the parent's children list and destroys the component surface

x_abs()

Returns the X absolute coordinate of the component, according to the X scroll position

y_abs()

Returns the X absolute coordinate of the component, according to the Y scroll position

resize(width, height)

Resizes the component surface

ParamDescriptionTypeDefault
widthNew widthReal
heightNew heightReal

add_child(component)

Manually adds a component to the children list

ParamDescriptionTypeDefault
componentChild component to addStruct

watch(propName, callback)

Execute the specified callback when a state value has been changed. Returns the watcher ID that can be used with the unwatch method.

Note: watchers are currently only executed when using the set() method.

ParamDescriptionTypeDefault
propNameProperty to watchString
callbackCallback to executeFunction

unwatch([prop_name], [watcherid])

Remove a watcher for the specified prop name. You can also pass undefined to remove all the watchers related to that prop. Also the prop name can be undefined if you want to remove the watchers of any prop of this component.

ParamDescriptionTypeDefault
propNameSpecified propertyString
watcherIdWatcher callback to unsetReal

focus([recursive])

Bring the component above all other components in the parent's children list.

ParamDescriptionTypeDefault
recursiveIf to recursively bring on top also the parent (and its ancestors) above their parentBooltrue

is_hovered([component])

Check if the component is interecting the mouse, while being above the other parent's children

ParamDescriptionTypeDefault
componentComponent to checkStructself

Globals

Global variables defined in the script

VariableDescriptionTypeDefault
ui_mouse_xGUI Mouse X. Updated from ui_step()Realdevice_mouse_x_to_gui(0)
ui_mouse_yGUI Mouse Y. Updated from ui_step()Realdevice_mouse_y_to_gui(0)