2.7 KiB
2.7 KiB
BaseElement : PropertySystem
The base class for all UI elements in Basalt
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| type | string | BaseElement | The type identifier of the element |
| eventCallbacks | table | {} | Table containing all registered event callbacks |
Functions
| Method | Returns | Description |
|---|---|---|
| BaseElement.listenTo | - | |
| BaseElement.new | table | |
| BaseElement:fireEvent | table | |
| BaseElement:init | table | |
| BaseElement:listenEvent | table | |
| BaseElement:registerCallback | table | |
| BaseElement:updateRender | - |
BaseElement.listenTo(class, eventName)
Registers an event that this class can listen to
Parameters
classtableThe class to add the event toeventNamestringThe name of the event to register
Usage
BaseElement.listenTo(MyClass, "mouse_click")
BaseElement.new(id, basalt)
Creates a new BaseElement instance
Parameters
idstringThe unique identifier for this elementbasalttableThe basalt instance
Returns
tableThenewly created BaseElement instance
Usage
local element = BaseElement.new("myId", basalt)
BaseElement:fireEvent(event, ...)
Triggers an event and calls all registered callbacks
Parameters
eventstringThe event to fire...anyAdditional arguments to pass to the callbacks
Returns
tableselfThe BaseElement instance
Usage
element:fireEvent("mouse_click", 1, 2)
BaseElement:init(id, basalt)
Initializes the BaseElement instance
Parameters
idstringThe unique identifier for this elementbasalttableThe basalt instance
Returns
tableselfThe initialized instance
BaseElement:listenEvent(eventName, enable?)
Enables or disables event listening for a specific event
Parameters
eventNamestringThe name of the event to listen forenable(optional)booleanWhether to enable or disable the event (default: true)
Returns
tableselfThe BaseElement instance
Usage
element:listenEvent("mouse_click", true)
BaseElement:registerCallback(event, callback)
Registers a callback function for an event
Parameters
eventstringThe event to register the callback forcallbackfunctionThe callback function to register
Returns
tableselfThe BaseElement instance
Usage
element:registerCallback("mouse_click", function(self, ...) end)
BaseElement:updateRender()
Requests a render update for this element
Usage
element:updateRender()