Files
Basalt2/docs/content/BaseElement.md
2025-02-10 06:45:18 +00:00

2.7 KiB

BaseElement

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

  • class table The class to add the event to
  • eventName string The name of the event to register

Usage

BaseElement.listenTo(MyClass, "mouse_click")

BaseElement.new(id, basalt)

Creates a new BaseElement instance

Parameters

  • id string The unique identifier for this element
  • basalt table The basalt instance

Returns

  • table The newly created BaseElement instance

Usage

local element = BaseElement.new("myId", basalt)

BaseElement:fireEvent(event, ...)

Triggers an event and calls all registered callbacks

Parameters

  • event string The event to fire
  • ... any Additional arguments to pass to the callbacks

Returns

  • table self The BaseElement instance

Usage

element:fireEvent("mouse_click", 1, 2)

BaseElement:init(id, basalt)

Initializes the BaseElement instance

Parameters

  • id string The unique identifier for this element
  • basalt table The basalt instance

Returns

  • table self The initialized instance

BaseElement:listenEvent(eventName, enable?)

Enables or disables event listening for a specific event

Parameters

  • eventName string The name of the event to listen for
  • enable (optional) boolean Whether to enable or disable the event (default: true)

Returns

  • table self The BaseElement instance

Usage

element:listenEvent("mouse_click", true)

BaseElement:registerCallback(event, callback)

Registers a callback function for an event

Parameters

  • event string The event to register the callback for
  • callback function The callback function to register

Returns

  • table self The BaseElement instance

Usage

element:registerCallback("mouse_click", function(self, ...) end)

BaseElement:updateRender()

Requests a render update for this element

Usage

element:updateRender()