4.7 KiB
4.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 |
| id | string | BaseElement | The unique identifier for the element |
| name | string | BaseElement | The name of the element |
| eventCallbacks | table | {} | Table containing all registered event callbacks |
Functions
| Method | Returns | Description |
|---|---|---|
| BaseElement.listenTo | - | Registers an event that this class can listen to |
| BaseElement.new | table | Creates a new BaseElement instance |
| BaseElement:destroy | - | Destroys the element and cleans up all references |
| BaseElement:dispatchEvent | boolean? | Handles all events |
| BaseElement:fireEvent | table | Triggers an event and calls all registered callbacks |
| BaseElement:getBaseFrame | table | Returns the base frame of the element |
| BaseElement:handleEvent | boolean? | The default event handler for all events |
| BaseElement:init | table | Initializes the BaseElement instance |
| BaseElement:isType | boolean | Checks if the element is a specific type |
| BaseElement:listenEvent | table | Enables or disables event listening for a specific event |
| BaseElement:postInit | table | Post initialization |
| BaseElement:registerCallback | table | Registers a callback function |
| BaseElement:updateRender | - | Requests a render update for this element |
BaseElement.listenTo(class, eventName, event?)
Registers an event that this class can listen to
Parameters
classtableThe class to add the event toeventNamestringThe name of the event to registerevent(optional)stringThe event to handle
Usage
BaseElement.listenTo(MyClass, "mouse_click")
BaseElement.new(props, basalt)
Creates a new BaseElement instance
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
Returns
tableThenewly created BaseElement instance
Usage
local element = BaseElement.new()
BaseElement:destroy()
Destroys the element and cleans up all references
Usage
element:destroy()
BaseElement:dispatchEvent(event...)
Handles all events
Parameters
eventstringThe event to handle...(vararg)anyThe arguments for the event
Returns
boolean?handledWhether the event was handled
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:getBaseFrame()
Returns the base frame of the element
Returns
tableBaseFrameThe base frame of the element
BaseElement:handleEvent(event...)
The default event handler for all events
Parameters
eventstringThe event to handle...(vararg)anyThe arguments for the event
Returns
boolean?handledWhether the event was handled
BaseElement:init(props, basalt)
Initializes the BaseElement instance
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
Returns
tableselfThe initialized instance
BaseElement:isType(type)
Checks if the element is a specific type
Parameters
typestringThe type to check for
Returns
booleanWhetherthe element is of the specified type
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:postInit()
Post initialization
Returns
tableselfThe BaseElement instance
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()