This commit is contained in:
NoryiE
2025-09-13 20:28:52 +00:00
parent 9e1112f3bd
commit 4ccefcac9f
48 changed files with 3036 additions and 1565 deletions

View File

@@ -1,27 +1,30 @@
# ElementManager # ElementManager
This class manages elements and plugins. It loads elements and plugins from the elements and plugins directories _This class manages elements and plugins. It loads elements and plugins from the elements and plugins directories
and then applies the plugins to the elements. It also provides a way to get elements and APIs. and then applies the plugins to the elements. It also provides a way to get elements and APIs._
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[ElementManager.getAPI](#elementmanager-getapi)|table| |[ElementManager.loadElement](#elementmanager-loadelement-name)|-|Loads an element by name. This will load the element and apply any plugins to it.|
|[ElementManager.getElement](#elementmanager-getelement)|table| |[ElementManager.getElement](#elementmanager-getelement-name)|table|Gets an element by name. If the element is not loaded, it will try to load it first.|
|[ElementManager.getElementList](#elementmanager-getelementlist)|table| |[ElementManager.getElementList](#elementmanager-getelementlist)|table|Gets a list of all elements|
|[ElementManager.loadElement](#elementmanager-loadelement)|-| |[ElementManager.getAPI](#elementmanager-getapi-name)|table|Gets an Plugin API by name|
## ElementManager.loadElement(name)
## ElementManager.getAPI(name) Loads an element by name. This will load the element and apply any plugins to it.
Gets an Plugin API by name
### Parameters ### Parameters
* `name` `string` The name of the API to get * `name` `string` The name of the element to load
### Returns ### Usage
* `table` `API` The API ```lua
ElementManager.loadElement("Button")
```
## ElementManager.getElement(name) ## ElementManager.getElement(name)
Gets an element by name. If the element is not loaded, it will try to load it first. Gets an element by name. If the element is not loaded, it will try to load it first.
### Parameters ### Parameters
@@ -31,20 +34,18 @@ Gets an element by name. If the element is not loaded, it will try to load it fi
* `table` `Element` The element class * `table` `Element` The element class
## ElementManager.getElementList() ## ElementManager.getElementList()
Gets a list of all elements Gets a list of all elements
### Returns ### Returns
* `table` `ElementList` A list of all elements * `table` `ElementList` A list of all elements
## ElementManager.loadElement(name) ## ElementManager.getAPI(name)
Loads an element by name. This will load the element and apply any plugins to it.
Gets an Plugin API by name
### Parameters ### Parameters
* `name` `string` The name of the element to load * `name` `string` The name of the API to get
### Usage
```lua
ElementManager.loadElement("Button")
```
### Returns
* `table` `API` The API

View File

@@ -1,28 +1,29 @@
# BarChart : Graph # BarChart
The Bar Chart element is designed for visualizing data series as vertical bars. It displays multiple values as side-by-side bars where each bar's height represents its value. _The Bar Chart element is designed for visualizing data series as vertical bars. It displays multiple values as side-by-side bars where each bar's height represents its value._
### Usage Extends: `Graph`
```lua
local chart = main:addBarChart()
:addSeries("input", " ", colors.green, colors.green, 5)
:addSeries("output", " ", colors.red, colors.red, 5)
basalt.schedule(function() ## Functions
while true do
chart:addPoint("input", math.random(1,100))
chart:addPoint("output", math.random(1,100))
sleep(2)
end
end)
```
## Protected Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|BarChart:init|BarChart|Initializes the BarChart instance |[BarChart.new](#barchart-new)|BarChart|Creates a new BarChart instance|
|BarChart:render|-|Renders the BarChart |[BarChart:init](#barchart-init-props-basalt)|BarChart|Initializes the BarChart instance|
|[BarChart:render](#barchart-render)|-|Renders the BarChart|
## BarChart.new()
Creates a new BarChart instance
### Returns
* `BarChart` `self` The newly created BarChart instance
## BarChart:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `BarChart` `self` The initialized instance
## BarChart:render()

View File

@@ -1,41 +1,40 @@
# BaseElement : PropertySystem # BaseElement
The base class for all UI elements in Basalt. This class provides basic properties and event handling functionality. _The base class for all UI elements in Basalt. This class provides basic properties and event handling functionality._
Extends: `PropertySystem`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|type|string|BaseElement|The type identifier of the element |type|string|BaseElement|The type identifier of the element|
|id|string|BaseElement|The unique identifier for the element |id|string|BaseElement|The unique identifier for the element|
|name|string|BaseElement|The name of the element |name|string|BaseElement|The name of the element|
|eventCallbacks|table|BaseElement|The event callbacks for the element |eventCallbacks|table|BaseElement|The event callbacks for the element|
|enabled|boolean|BaseElement|Whether the element is enabled or not|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[BaseElement.defineEvent](#baseelement-defineevent)|-|Registers a new event listener for the element (on class level) |[BaseElement.defineEvent](#baseelement-defineevent-class-eventname-requiredevent)|-|Registers a new event listener for the element (on class level)|
|[BaseElement.registerEventCallback](#baseelement-registereventcallback)|-|Registers a new event callback for the element (on class level) |[BaseElement.registerEventCallback](#baseelement-registereventcallback-class-callbackname-string)|-|Registers a new event callback for the element (on class level)|
|[BaseElement:destroy](#baseelement-destroy)|-|Destroys the element and cleans up all references |[BaseElement.new](#baseelement-new)|table|Creates a new BaseElement instance|
|[BaseElement:fireEvent](#baseelement-fireevent)|table|Triggers an event and calls all registered callbacks |[BaseElement:init](#baseelement-init-props-basalt)|table|Initializes the BaseElement instance|
|[BaseElement:getBaseFrame](#baseelement-getbaseframe)|BaseFrame|Returns the base frame of the element |[BaseElement:postInit](#baseelement-postinit)|table|Post initialization|
|[BaseElement:isType](#baseelement-istype)|boolean|Checks if the element is a specific type |[BaseElement:isType](#baseelement-istype-type)|boolean|Checks if the element is a specific type|
|[BaseElement:listenEvent](#baseelement-listenevent)|table|Enables or disables event listening for a specific event |[BaseElement:listenEvent](#baseelement-listenevent-eventname-enable)|table|Enables or disables event listening for a specific event|
|[BaseElement:onChange](#baseelement-onchange)|table|Observes a property and calls a callback when it changes |[BaseElement:registerCallback](#baseelement-registercallback-event-callback)|table|Registers a callback function|
|[BaseElement:registerCallback](#baseelement-registercallback)|table|Registers a callback function |[BaseElement:fireEvent](#baseelement-fireevent-event-any)|table|Triggers an event and calls all registered callbacks|
|[BaseElement:updateRender](#baseelement-updaterender)|table|Requests a render update for this element |[BaseElement:dispatchEvent](#baseelement-dispatchevent-event)|handled|Handles all events|
|[BaseElement:handleEvent](#baseelement-handleevent-event)|handled|The default event handler for all events|
|[BaseElement:onChange](#baseelement-onchange-property-callback)|table|Observes a property and calls a callback when it changes|
## Protected Functions |[BaseElement:getBaseFrame](#baseelement-getbaseframe)|BaseFrame|Returns the base frame of the element|
|[BaseElement:destroy](#baseelement-destroy)|-|Destroys the element and cleans up all references|
|Method|Returns|Description| |[BaseElement:updateRender](#baseelement-updaterender)|table|Requests a render update for this element|
|---|---|---|
|BaseElement:dispatchEvent|boolean?|Handles all events
|BaseElement:handleEvent|boolean?|The default event handler for all events
|BaseElement:init|table|Initializes the BaseElement instance
|BaseElement:postInit|table|Post initialization
## BaseElement.defineEvent(class, eventName, requiredEvent?) ## BaseElement.defineEvent(class, eventName, requiredEvent?)
Registers a new event listener for the element (on class level) Registers a new event listener for the element (on class level)
### Parameters ### Parameters
@@ -43,34 +42,33 @@ Registers a new event listener for the element (on class level)
* `eventName` `string` The name of the event to register * `eventName` `string` The name of the event to register
* `requiredEvent` *(optional)* `string` The name of the required event (optional) * `requiredEvent` *(optional)* `string` The name of the required event (optional)
## BaseElement.registerEventCallback(class, callbackName, ...) ## BaseElement.registerEventCallback(class, callbackName, string)
Registers a new event callback for the element (on class level) Registers a new event callback for the element (on class level)
### Parameters ### Parameters
* `class` `table` The class to register * `class` `table` The class to register
* `callbackName` `string` The name of the callback to register * `callbackName` `string` The name of the callback to register
* `...` `string` The names of the events to register the callback for * `string` `The` names of the events to register the callback for
## BaseElement:destroy() ## BaseElement.new()
Destroys the element and cleans up all references ### Returns
* `table` `The` newly created BaseElement instance
## BaseElement:fireEvent(event, ...)
Triggers an event and calls all registered callbacks
## BaseElement:init(props, basalt)
### Parameters ### Parameters
* `event` `string` The event to fire * `props` `table` The properties to initialize the element with
* `...` `any` Additional arguments to pass to the callbacks * `basalt` `table` The basalt instance
### Returns
* `table` `self` The initialized instance
## BaseElement:postInit()
### Returns ### Returns
* `table` `self` The BaseElement instance * `table` `self` The BaseElement instance
## BaseElement:getBaseFrame()
Returns the base frame of the element
### Returns
* `BaseFrame` `BaseFrame` The base frame of the element
## BaseElement:isType(type) ## BaseElement:isType(type)
Checks if the element is a specific type Checks if the element is a specific type
### Parameters ### Parameters
@@ -80,6 +78,7 @@ Checks if the element is a specific type
* `boolean` `isType` Whether the element is of the specified type * `boolean` `isType` Whether the element is of the specified type
## BaseElement:listenEvent(eventName, enable?) ## BaseElement:listenEvent(eventName, enable?)
Enables or disables event listening for a specific event Enables or disables event listening for a specific event
### Parameters ### Parameters
@@ -89,17 +88,8 @@ Enables or disables event listening for a specific event
### Returns ### Returns
* `table` `self` The BaseElement instance * `table` `self` The BaseElement instance
## BaseElement:onChange(property, callback)
Observes a property and calls a callback when it changes
### Parameters
* `property` `string` The property to observe
* `callback` `function` The callback to call when the property changes
### Returns
* `table` `self` The BaseElement instance
## BaseElement:registerCallback(event, callback) ## BaseElement:registerCallback(event, callback)
Registers a callback function for an event Registers a callback function for an event
### Parameters ### Parameters
@@ -109,10 +99,56 @@ Registers a callback function for an event
### Returns ### Returns
* `table` `self` The BaseElement instance * `table` `self` The BaseElement instance
## BaseElement:updateRender() ## BaseElement:fireEvent(event, any)
Requests a render update for this element
Triggers an event and calls all registered callbacks
### Parameters
* `event` `string` The event to fire
* `any` `Additional` arguments to pass to the callbacks
### Returns ### Returns
* `table` `self` The BaseElement instance * `table` `self` The BaseElement instance
## BaseElement:dispatchEvent(event)
### Parameters
* `event` `string` The event to handle
### Returns
* `handled` `Whether` the event was handled
## BaseElement:handleEvent(event)
### Parameters
* `event` `string` The event to handle
### Returns
* `handled` `Whether` the event was handled
## BaseElement:onChange(property, callback)
Observes a property and calls a callback when it changes
### Parameters
* `property` `string` The property to observe
* `callback` `function` The callback to call when the property changes
### Returns
* `table` `self` The BaseElement instance
## BaseElement:getBaseFrame()
Returns the base frame of the element
### Returns
* `BaseFrame` `BaseFrame` The base frame of the element
## BaseElement:destroy()
Destroys the element and cleans up all references
## BaseElement:updateRender()
Requests a render update for this element
### Returns
* `table` `self` The BaseElement instance

View File

@@ -1,56 +1,96 @@
# BaseFrame : Container # BaseFrame
This is the base frame class. It is the root element of all elements and the only element without a parent. _This is the base frame class. It is the root element of all elements and the only element without a parent._
## Fields Extends: `Container`
|Field|Type|Description|
|---|---|---|
|_render|`Render`|The render object|
|_renderUpdate|`boolean`|Whether the render object needs to be updated|
|_peripheralName|`string`|The name of a peripheral|
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|term|term|peripheral|term.current()|The terminal or (monitor) peripheral object to render to |term|term|peripheral|term.current()|The terminal or (monitor) peripheral object to render to|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[BaseFrame:dispatchEvent](#baseframe-dispatchevent)|-| |[BaseFrame.new](#baseframe-new)|BaseFrame|Creates a new Frame instance|
|[BaseFrame:drawBg](#baseframe-drawbg)|-| |[BaseFrame:init](#baseframe-init-props-basalt)|table|Initializes the Frame instance|
|[BaseFrame:drawFg](#baseframe-drawfg)|-| |[BaseFrame:multiBlit](#baseframe-multiblit-x-y-width-height-text-fg-bg)|-|Renders a multiBlit to the render Object|
|[BaseFrame:setCursor](#baseframe-setcursor)|-|Sets the cursor position |[BaseFrame:textFg](#baseframe-textfg-x-y-text-fg)|-|Renders a text with a foreground color to the render Object|
|[BaseFrame:textBg](#baseframe-textbg-x-y-text-bg)|-|Renders a text with a background color to the render Object|
|[BaseFrame:drawText](#baseframe-drawtext-x-y-text-bg)|-|Renders a text with a background color to the render Object|
|[BaseFrame:blit](#baseframe-blit-x-y-text-fg-bg)|-|Renders a text with a foreground and background color to the render Object|
|[BaseFrame:setCursor](#baseframe-setcursor-x-y-blink)|-|Sets the cursor position|
|[BaseFrame:monitor_touch](#baseframe-monitor-touch-name-x-y)|-|Handles monitor touch events|
|[BaseFrame:mouse_click](#baseframe-mouse-click-button-x-y)|-|Handles mouse click events|
|[BaseFrame:mouse_up](#baseframe-mouse-up-button-x-y)|-|Handles mouse up events|
|[BaseFrame:term_resize](#baseframe-term-resize)|-|Resizes the Frame|
|[BaseFrame:key](#baseframe-key-key)|-|Handles key events|
|[BaseFrame:key_up](#baseframe-key-up-key)|-|Handles key up events|
|[BaseFrame:char](#baseframe-char-char)|-|Handles character events|
|[BaseFrame:render](#baseframe-render)|-|Renders the Frame|
## BaseFrame.new()
## Protected Functions Creates a new Frame instance
|Method|Returns|Description| ### Returns
|---|---|---| * `BaseFrame` `object` The newly created Frame instance
|BaseFrame:blit|-|Renders a text with a foreground and background color to the render Object
|BaseFrame:char|-|Handles character events
|BaseFrame:drawText|-|Renders a text with a background color to the render Object
|BaseFrame:init|table|Initializes the Frame instance
|BaseFrame:key|-|Handles key events
|BaseFrame:key_up|-|Handles key up events
|BaseFrame:monitor_touch|-|Handles monitor touch events
|BaseFrame:mouse_click|-|Handles mouse click events
|BaseFrame:mouse_up|-|Handles mouse up events
|BaseFrame:multiBlit|-|Renders a multiBlit to the render Object
|BaseFrame:render|-|Renders the Frame
|BaseFrame:term_resize|-|Resizes the Frame
|BaseFrame:textBg|-|Renders a text with a background color to the render Object
|BaseFrame:textFg|-|Renders a text with a foreground color to the render Object
## BaseFrame:dispatchEvent() ### Usage
```lua
local element = BaseFrame.new()
```
## BaseFrame:drawBg() ## BaseFrame:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
## BaseFrame:drawFg() ### Returns
* `table` `self` The initialized instance
## BaseFrame:multiBlit(x, y, width, height, text, fg, bg)
### Parameters
* `x` `number` The x position to render to
* `y` `number` The y position to render to
* `width` `number` The width of the text
* `height` `number` The height of the text
* `text` `string` The text to render
* `fg` `string` The foreground color
* `bg` `string` The background color
## BaseFrame:textFg(x, y, text, fg)
### Parameters
* `x` `number` The x position to render to
* `y` `number` The y position to render to
* `text` `string` The text to render
* `fg` `colors` The foreground color
## BaseFrame:textBg(x, y, text, bg)
### Parameters
* `x` `number` The x position to render to
* `y` `number` The y position to render to
* `text` `string` The text to render
* `bg` `colors` The background color
## BaseFrame:drawText(x, y, text, bg)
### Parameters
* `x` `number` The x position to render to
* `y` `number` The y position to render to
* `text` `string` The text to render
* `bg` `colors` The background color
## BaseFrame:blit(x, y, text, fg, bg)
### Parameters
* `x` `number` The x position to render to
* `y` `number` The y position to render to
* `text` `string` The text to render
* `fg` `string` The foreground color
* `bg` `string` The background color
## BaseFrame:setCursor(x, y, blink) ## BaseFrame:setCursor(x, y, blink)
Sets the cursor position Sets the cursor position
### Parameters ### Parameters
@@ -58,4 +98,35 @@ Sets the cursor position
* `y` `number` The y position to set the cursor to * `y` `number` The y position to set the cursor to
* `blink` `boolean` Whether the cursor should blink * `blink` `boolean` Whether the cursor should blink
## BaseFrame:monitor_touch(name, x, y)
### Parameters
* `name` `string` The name of the monitor that was touched
* `x` `number` The x position of the mouse
* `y` `number` The y position of the mouse
## BaseFrame:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the mouse
* `y` `number` The y position of the mouse
## BaseFrame:mouse_up(button, x, y)
### Parameters
* `button` `number` The button that was released
* `x` `number` The x position of the mouse
* `y` `number` The y position of the mouse
## BaseFrame:term_resize()
## BaseFrame:key(key)
### Parameters
* `key` `number` The key that was pressed
## BaseFrame:key_up(key)
### Parameters
* `key` `number` The key that was released
## BaseFrame:char(char)
### Parameters
* `char` `string` The character that was pressed
## BaseFrame:render()

View File

@@ -1,26 +1,34 @@
# BigFont : VisualElement # BigFontText
The BigFont element is a text element that displays larger text. It uses Wojbie's BigFont API to render the text in a larger font size. Credits to Wojbie for the original API. _Basalt - Nyorie: Please don't copy paste this code to your projects, this code is slightly changed (to fit the way basalt draws elements), if you want the original code, checkout this:
http://www.computercraft.info/forums2/index.php?/topic/25367-bigfont-api-write-bigger-letters-v10/_
### Usage # BigFont
```lua _The BigFont element is a text element that displays larger text. It uses Wojbie's BigFont API to render the text in a larger font size. Credits to Wojbie for the original API._
local font = main:addBigFont()
font:setText("Hello World!")
```
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|text|string|BigFont|BigFont text |text|string|BigFont|BigFont text|
|fontSize|number|1|The font size of the BigFont |fontSize|number|1|The font size of the BigFont|
## Functions
## Protected Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|BigFont:init|-|Initializes the BigFont instance |[BigFont.new](#bigfont-new)|table|Creates a new BigFont instance|
|BigFont:render|-|Renders the BigFont |[BigFont:init](#bigfont-init-props-basalt)|-|Initializes the BigFont instance|
|[BigFont:render](#bigfont-render)|-|Renders the BigFont|
## BigFont.new()
### Returns
* `table` `self` The created instance
## BigFont:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
## BigFont:render()

View File

@@ -1,18 +1,29 @@
# Button : VisualElement # Button
The Button is a standard button element with click handling and state management. _The Button is a standard button element with click handling and state management._
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|text|string|Button|Button text |text|string|Button|Button text|
## Functions
## Protected Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|Button:init|-|Initializes the Button instance |[Button.new](#button-new)|table|Creates a new Button instance|
|Button:render|-|Renders the Button |[Button:init](#button-init-props-basalt)|-|Initializes the Button instance|
|[Button:render](#button-render)|-|Renders the Button|
## Button.new()
### Returns
* `table` `self` The created instance
## Button:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
## Button:render()

View File

@@ -1,23 +1,42 @@
# Checkbox : VisualElement # Checkbox
The Checkbox is a visual element that can be checked. _The Checkbox is a visual element that can be checked._
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|checked|boolean|Whether|checkbox is checked |checked|boolean|Whether|checkbox is checked|
|text|string|empty|Text to display |text|string|empty|Text to display|
|checkedText|string|Text|when checked |checkedText|string|Text|when checked|
|autoSize|boolean|true|Whether to automatically size the checkbox |autoSize|boolean|true|Whether to automatically size the checkbox|
## Functions
## Protected Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|Checkbox.new|Checkbox|Creates a new Checkbox instance |[Checkbox.new](#checkbox-new)|Checkbox|Creates a new Checkbox instance|
|Checkbox:init|-|Initializes the Checkbox instance |[Checkbox:init](#checkbox-init-props-basalt)|-|Initializes the Checkbox instance|
|Checkbox:mouse_click|boolean|Handles mouse click events |[Checkbox:mouse_click](#checkbox-mouse-click-button-x-y)|boolean|Handles mouse click events|
|Checkbox:render|-|Renders the Checkbox |[Checkbox:render](#checkbox-render)|-|Renders the Checkbox|
## Checkbox.new()
### Returns
* `Checkbox` `self` The created instance
## Checkbox:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
## Checkbox:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `Clicked` Whether the event was handled
## Checkbox:render()

View File

@@ -0,0 +1,129 @@
# ComboBox
_This is the ComboBox class. It extends the dropdown functionality with editable text input,
allowing users to either select from a list or type their own custom text._
Extends: `Dropdown`
## Properties
|Property|Type|Default|Description|
|---|---|---|---|
|editable|boolean|true|Whether the ComboBox allows text input|
|text|string|""|The current text content of the ComboBox|
|cursorPos|number|1|The current cursor position in the text|
|viewOffset|number|0|The horizontal scroll offset for viewing long text|
|placeholder|string|"..."|Text to display when input is empty|
|placeholderColor|color|gray|Color of the placeholder text|
|focusedBackground|color|blue|Background color when ComboBox is focused|
|focusedForeground|color|white|Foreground color when ComboBox is focused |
|autoComplete|boolean|false|Whether to enable auto-complete filtering when typing|
|manuallyOpened|boolean|false|Whether the dropdown was manually opened (not by auto-complete)|
## Functions
|Method|Returns|Description|
|---|---|---|
|[ComboBox.new](#combobox-new)|ComboBox|Creates a new ComboBox instance|
|[ComboBox:init](#combobox-init-props-basalt)|ComboBox|Initializes the ComboBox instance|
|[ComboBox:setText](#combobox-settext-text)|ComboBox|Sets the text content|
|[ComboBox:getText](#combobox-gettext)|string|Gets the text content|
|[ComboBox:setEditable](#combobox-seteditable-editable)|ComboBox|Sets editable state|
|[ComboBox:getFilteredItems](#combobox-getfiltereditems)|-|Filters items for auto-complete|
|[ComboBox:updateFilteredDropdown](#combobox-updatefiltereddropdown)|-|Updates dropdown with filtered items|
|[ComboBox:updateViewport](#combobox-updateviewport)|-|Updates the viewport|
|[ComboBox:char](#combobox-char-char)|-|Handles character input|
|[ComboBox:key](#combobox-key-key-held)|-|Handles key input|
|[ComboBox:mouse_click](#combobox-mouse-click-button-x-y)|boolean|Handles mouse clicks|
|[ComboBox:render](#combobox-render)|-|Renders the ComboBox|
|[ComboBox:focus](#combobox-focus)|-|Called when gaining focus|
|[ComboBox:blur](#combobox-blur)|-|Called when losing focus|
## ComboBox.new()
Creates a new ComboBox instance
### Returns
* `ComboBox` `self` The newly created ComboBox instance
## ComboBox:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `ComboBox` `self` The initialized instance
## ComboBox:setText(text)
Sets the text content of the ComboBox
### Parameters
* `text` `string` The text to set
### Returns
* `ComboBox` self
## ComboBox:getText()
Gets the current text content
### Returns
* `string` `text` The current text
## ComboBox:setEditable(editable)
Sets whether the ComboBox is editable
### Parameters
* `editable` `boolean` Whether the ComboBox should be editable
### Returns
* `ComboBox` self
## ComboBox:getFilteredItems()
Filters items based on current text for auto-complete
## ComboBox:updateFilteredDropdown()
Updates the dropdown with filtered items
## ComboBox:updateViewport()
## ComboBox:char(char)
Handles character input when editable
### Parameters
* `char` `string` The character that was typed
## ComboBox:key(key, held)
Handles key input when editable
### Parameters
* `key` `number` The key code that was pressed
* `held` `boolean` Whether the key is being held
## ComboBox:mouse_click(button, x, y)
Handles mouse clicks
### Parameters
* `button` `number` The mouse button (1 = left, 2 = right, 3 = middle)
* `x` `number` The x coordinate of the click
* `y` `number` The y coordinate of the click
### Returns
* `boolean` `handled` Whether the event was handled
## ComboBox:render()
Renders the ComboBox
## ComboBox:focus()
Called when the ComboBox gains focus
## ComboBox:blur()
Called when the ComboBox loses focus

View File

@@ -1,119 +1,72 @@
# Container : VisualElement # Container
The Container class serves as a fundamental building block for organizing UI elements. It acts as a parent element that can hold and manage child elements. _The Container class serves as a fundamental building block for organizing UI elements. It acts as a parent element that can hold and manage child elements._
### Usage
```lua
local container = basalt.getMainFrame()
container:addButton() -- Add a child element
```
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|children|table|{}|The children of the container |children|table|{}|The children of the container|
|childrenSorted|boolean|true|Whether the children are sorted |childrenSorted|boolean|true|Whether the children are sorted|
|childrenEventsSorted|boolean|true|Whether the children events are sorted |childrenEventsSorted|boolean|true|Whether the children events are sorted|
|childrenEvents|table|{}|The children events of the container |childrenEvents|table|{}|The children events of the container|
|eventListenerCount|table|{}|The event listener count of the container |eventListenerCount|table|{}|The event listener count of the container|
|focusedChild|table|nil|The focused child of the container |focusedChild|table|nil|The focused child of the container|
|visibleChildren|table|{}|The visible children of the container |visibleChildren|table|{}|The visible children of the container|
|visibleChildrenEvents|table|{}|The visible children events of the container |visibleChildrenEvents|table|{}|The visible children events of the container|
|offsetX|number|0|Horizontal content offset |offsetX|number|0|Horizontal content offset|
|offsetY|number|0|Vertical content offset |offsetY|number|0|Vertical content offset|
## Combined Properties
|Name|Properties|Description|
|---|---|---|
|offset|`offsetX number, offsetY number`|Combined property for offsetX and offsetY|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Container:addChild](#container-addchild)|Container|Adds a child to the container |[Container.new](#container-new)|Container|Creates a new Container instance|
|[Container:callChildrenEvent](#container-callchildrenevent)|boolean|Calls a event on all children |[Container:init](#container-init-props-basalt)|-|Initializes the Container instance|
|[Container:clear](#container-clear)|Container|Clears the container |[Container:isChildVisible](#container-ischildvisible-child)|boolean|Returns whether a child is visible|
|[Container:drawBg](#container-drawbg)|-| |[Container:addChild](#container-addchild-child)|Container|Adds a child to the container|
|[Container:drawFg](#container-drawfg)|-| |[Container:clear](#container-clear)|Container|Clears the container|
|[Container:drawText](#container-drawtext)|-| |[Container:sortChildren](#container-sortchildren)|Container|Sorts the children of the container|
|[Container:getChild](#container-getchild)|Container?|Removes a child from the container |[Container:sortChildrenEvents](#container-sortchildrenevents-eventname)|Container|Sorts the children events of the container|
|[Container:isChildVisible](#container-ischildvisible)|boolean|Returns whether a child is visible |[Container:registerChildrenEvents](#container-registerchildrenevents-child)|Container|Registers the children events of the container|
|[Container:registerChildEvent](#container-registerchildevent)|Container|Registers the children events of the container |[Container:registerChildEvent](#container-registerchildevent-child-eventname)|Container|Registers the children events of the container|
|[Container:registerChildrenEvents](#container-registerchildrenevents)|Container|Registers the children events of the container |[Container:removeChildrenEvents](#container-removechildrenevents-child)|Container|Unregisters the children events of the container|
|[Container:removeChild](#container-removechild)|Container|Removes a child from the container |[Container:unregisterChildEvent](#container-unregisterchildevent-child-eventname)|Container|Unregisters the children events of the container|
|[Container:removeChildrenEvents](#container-removechildrenevents)|Container|Unregisters the children events of the container |[Container:removeChild](#container-removechild-child)|Container|Removes a child from the container|
|[Container:sortChildren](#container-sortchildren)|Container|Sorts the children of the container |[Container:getChild](#container-getchild-path)|self|Removes a child from the container|
|[Container:sortChildrenEvents](#container-sortchildrenevents)|Container|Sorts the children events of the container |[Container:callChildrenEvent](#container-callchildrenevent-visibleonly-event)|boolean, child|Calls a event on all children|
|[Container:unregisterChildEvent](#container-unregisterchildevent)|Container|Unregisters the children events of the container |[Container:handleEvent](#container-handleevent-event)|boolean|Default handler for events|
|[Container:mouse_click](#container-mouse-click-button-x-y)|boolean|Handles mouse click events|
|[Container:mouse_up](#container-mouse-up-button-x-y)|boolean|Handles mouse up events|
|[Container:mouse_release](#container-mouse-release-button-x-y)|-|Handles mouse release events|
|[Container:mouse_move](#container-mouse-move---x-y)|boolean|Handles mouse move events|
|[Container:mouse_drag](#container-mouse-drag-button-x-y)|boolean|Handles mouse drag events|
|[Container:mouse_scroll](#container-mouse-scroll-direction-x-y)|boolean|Handles mouse scroll events|
|[Container:key](#container-key-key)|boolean|Handles key events|
|[Container:char](#container-char-char)|boolean|Handles char events|
|[Container:key_up](#container-key-up-key)|boolean|Handles key up events|
|[Container:multiBlit](#container-multiblit-x-y-width-height-text-fg-bg)|Container|Draws multiple lines of text, fg and bg strings|
|[Container:textFg](#container-textfg-x-y-text-fg)|Container|Draws a line of text and fg as color|
|[Container:textBg](#container-textbg-x-y-text-bg)|Container|Draws a line of text and bg as color|
|[Container:blit](#container-blit-x-y-text-fg-bg)|Container|Draws a line of text and fg and bg as colors|
|[Container:render](#container-render)|-|Renders the container|
|[Container:destroy](#container-destroy)|-||
## Container.new()
## Protected Functions Creates a new Container instance
|Method|Returns|Description| ### Returns
|---|---|---| * `Container` `self` The new container instance
|Container:blit|Container|Draws a line of text and fg and bg as colors
|Container:char|boolean|Handles char events
|Container:handleEvent|boolean|Default handler for events
|Container:init|-|Initializes the Container instance
|Container:key|boolean|Handles key events
|Container:key_up|boolean|Handles key up events
|Container:mouse_click|boolean|Handles mouse click events
|Container:mouse_drag|boolean|Handles mouse drag events
|Container:mouse_move|boolean|Handles mouse move events
|Container:mouse_release|-|Handles mouse release events
|Container:mouse_scroll|boolean|Handles mouse scroll events
|Container:mouse_up|boolean|Handles mouse up events
|Container:multiBlit|Container|Draws multiple lines of text, fg and bg strings
|Container:render|-|Renders the container
|Container:textBg|Container|Draws a line of text and bg as color
|Container:textFg|Container|Draws a line of text and fg as color
## Container:addChild(child)
Adds a child to the container
## Container:init(props, basalt)
### Parameters ### Parameters
* `child` `table` The child to add * `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `Container` `self` The container instance
## Container:callChildrenEvent(visibleOnly, event...)
Calls a event on all children
### Parameters
* `visibleOnly` `boolean` Whether to only call the event on visible children
* `event` `string` The event to call
* `...` *(vararg)* `any` The event arguments
### Returns
* `boolean` `handled` Whether the event was handled
* `table?` `child` The child that handled the event
## Container:clear()
Clears the container
### Returns
* `Container` `self` The container instance
## Container:drawBg()
## Container:drawFg()
## Container:drawText()
## Container:getChild(path)
Removes a child from the container
### Parameters
* `path` `string` The path to the child to remove
### Returns
* `Container?` `self` The container instance
## Container:isChildVisible(child) ## Container:isChildVisible(child)
Returns whether a child is visible Returns whether a child is visible
### Parameters ### Parameters
@@ -122,7 +75,52 @@ Returns whether a child is visible
### Returns ### Returns
* `boolean` `boolean` the child is visible * `boolean` `boolean` the child is visible
## Container:addChild(child)
Adds a child to the container
### Parameters
* `child` `table` The child to add
### Returns
* `Container` `self` The container instance
## Container:clear()
Clears the container
### Returns
* `Container` `self` The container instance
## Container:sortChildren()
Sorts the children of the container
### Returns
* `Container` `self` The container instance
## Container:sortChildrenEvents(eventName)
Sorts the children events of the container
### Parameters
* `eventName` `string` The event name to sort
### Returns
* `Container` `self` The container instance
## Container:registerChildrenEvents(child)
Registers the children events of the container
### Parameters
* `child` `table` The child to register events for
### Returns
* `Container` `self` The container instance
## Container:registerChildEvent(child, eventName) ## Container:registerChildEvent(child, eventName)
Registers the children events of the container Registers the children events of the container
### Parameters ### Parameters
@@ -132,25 +130,8 @@ Registers the children events of the container
### Returns ### Returns
* `Container` `self` The container instance * `Container` `self` The container instance
## Container:registerChildrenEvents(child)
Registers the children events of the container
### Parameters
* `child` `table` The child to register events for
### Returns
* `Container` `self` The container instance
## Container:removeChild(child)
Removes a child from the container
### Parameters
* `child` `table` The child to remove
### Returns
* `Container` `self` The container instance
## Container:removeChildrenEvents(child) ## Container:removeChildrenEvents(child)
Unregisters the children events of the container Unregisters the children events of the container
### Parameters ### Parameters
@@ -159,22 +140,8 @@ Unregisters the children events of the container
### Returns ### Returns
* `Container` `self` The container instance * `Container` `self` The container instance
## Container:sortChildren()
Sorts the children of the container
### Returns
* `Container` `self` The container instance
## Container:sortChildrenEvents(eventName)
Sorts the children events of the container
### Parameters
* `eventName` `string` The event name to sort
### Returns
* `Container` `self` The container instance
## Container:unregisterChildEvent(child, eventName) ## Container:unregisterChildEvent(child, eventName)
Unregisters the children events of the container Unregisters the children events of the container
### Parameters ### Parameters
@@ -184,4 +151,160 @@ Unregisters the children events of the container
### Returns ### Returns
* `Container` `self` The container instance * `Container` `self` The container instance
## Container:removeChild(child)
Removes a child from the container
### Parameters
* `child` `table` The child to remove
### Returns
* `Container` `self` The container instance
## Container:getChild(path)
Removes a child from the container
### Parameters
* `path` `string` The path to the child to remove
### Returns
* `self` `The` container instance
## Container:callChildrenEvent(visibleOnly, event)
Calls a event on all children
### Parameters
* `visibleOnly` `boolean` Whether to only call the event on visible children
* `event` `string` The event to call
### Returns
* `boolean` `handled` Whether the event was handled
* `child` `The` child that handled the event
## Container:handleEvent(event)
### Parameters
* `event` `string` The event to handle
### Returns
* `boolean` `handled` Whether the event was handled
## Container:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Container:mouse_up(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Container:mouse_release(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
## Container:mouse_move(_, x, y)
### Parameters
* `_` `number` unknown
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Container:mouse_drag(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Container:mouse_scroll(direction, x, y)
### Parameters
* `direction` `number` The direction of the scroll
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Container:key(key)
### Parameters
* `key` `number` The key that was pressed
### Returns
* `boolean` `handled` Whether the event was handled
## Container:char(char)
### Parameters
* `char` `string` The character that was pressed
### Returns
* `boolean` `handled` Whether the event was handled
## Container:key_up(key)
### Parameters
* `key` `number` The key that was released
### Returns
* `boolean` `handled` Whether the event was handled
## Container:multiBlit(x, y, width, height, text, fg, bg)
### Parameters
* `x` `number` The x position to draw the text
* `y` `number` The y position to draw the text
* `width` `number` The width of the text
* `height` `number` The height of the text
* `text` `string` The text to draw
* `fg` `string` The foreground color of the text
* `bg` `string` The background color of the text
### Returns
* `Container` `self` The container instance
## Container:textFg(x, y, text, fg)
### Parameters
* `x` `number` The x position to draw the text
* `y` `number` The y position to draw the text
* `text` `string` The text to draw
* `fg` `color` The foreground color of the text
### Returns
* `Container` `self` The container instance
## Container:textBg(x, y, text, bg)
### Parameters
* `x` `number` The x position to draw the text
* `y` `number` The y position to draw the text
* `text` `string` The text to draw
* `bg` `color` The background color of the text
### Returns
* `Container` `self` The container instance
## Container:blit(x, y, text, fg, bg)
### Parameters
* `x` `number` The x position to draw the text
* `y` `number` The y position to draw the text
* `text` `string` The text to draw
* `fg` `string` The foreground color of the text
* `bg` `string` The background color of the text
### Returns
* `Container` `self` The container instance
## Container:render()
## Container:destroy()

View File

@@ -1,36 +1,36 @@
# Display : VisualElement # Display
The Display is a special element where you can use the window (term) API to draw on the display, useful when you need to use external APIs. _The Display is a special element where you can use the window (term) API to draw on the display, useful when you need to use external APIs._
### Usage
```lua
local display = main:addDisplay() -- Create a display element
local displayWindow = display:getWindow() -- Get the window object of the display
displayWindow.write("Hello World!") -- Write "Hello World!" to the display
```
Extends: `VisualElement`
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Display:getWindow](#display-getwindow)|table|Returns the current window object |[Display.new](#display-new)|table|Creates a new Display instance|
|[Display:write](#display-write)|Display|Writes text to the display |[Display:init](#display-init-props-basalt)|-|Initializes the Display instance|
|[Display:getWindow](#display-getwindow)|table|Returns the current window object|
|[Display:write](#display-write-x-y-text-fg-bg)|Display|Writes text to the display|
|[Display:render](#display-render)|-|Renders the Display|
## Display.new()
### Returns
* `table` `self` The created instance
## Protected Functions ## Display:init(props, basalt)
### Parameters
|Method|Returns|Description| * `props` `table` The properties to initialize the element with
|---|---|---| * `basalt` `table` The basalt instance
|Display:init|-|Initializes the Display instance
|Display:render|-|Renders the Display
## Display:getWindow() ## Display:getWindow()
Returns the current window object Returns the current window object
### Returns ### Returns
* `table` `window` The current window object * `table` `window` The current window object
## Display:write(x, y, text, fg?, bg?) ## Display:write(x, y, text, fg?, bg?)
Writes text to the display at the given position with the given foreground and background colors Writes text to the display at the given position with the given foreground and background colors
### Parameters ### Parameters
@@ -43,4 +43,4 @@ Writes text to the display at the given position with the given foreground and b
### Returns ### Returns
* `Display` `self` The display instance * `Display` `self` The display instance
## Display:render()

View File

@@ -1,33 +1,48 @@
# Dropdown : List # Dropdown
This is the dropdown class. It is a visual element that can show a list of selectable items in a dropdown menu. _This is the dropdown class. It is a visual element that can show a list of selectable items in a dropdown menu._
### Usage
```lua
local dropdown = main:addDropdown()
dropdown:setItems({
{text = "Item 1", callback = function() basalt.LOGGER.debug("Item 1 selected") end},
{text = "Item 2", callback = function() basalt.LOGGER.debug("Item 2 selected") end},
{text = "Item 3", callback = function() basalt.LOGGER.debug("Item 3 selected") end},
})
```
Extends: `List`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|isOpen|boolean|false|Whether the dropdown menu is currently open |isOpen|boolean|false|Whether the dropdown menu is currently open|
|dropdownHeight|number|5|Maximum height of the dropdown menu when open |dropdownHeight|number|5|Maximum height of the dropdown menu when open|
|selectedText|string|""|The text to show when no item is selected |selectedText|string|""|The text to show when no item is selected|
|dropSymbol|string|"\31"|The symbol to show for dropdown indication |dropSymbol|string|"\31"|The symbol to show for dropdown indication|
## Functions
## Protected Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|Dropdown:init|Dropdown|Initializes the Dropdown instance |[Dropdown.new](#dropdown-new)|Dropdown|Creates a new Dropdown instance|
|Dropdown:mouse_click|boolean|Handles mouse click events |[Dropdown:init](#dropdown-init-props-basalt)|Dropdown|Initializes the Dropdown instance|
|Dropdown:render|-|Renders the Dropdown |[Dropdown:mouse_click](#dropdown-mouse-click-button-x-y)|boolean|Handles mouse click events|
|[Dropdown:render](#dropdown-render)|-|Renders the Dropdown|
## Dropdown.new()
Creates a new Dropdown instance
### Returns
* `Dropdown` `self` The newly created Dropdown instance
## Dropdown:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `Dropdown` `self` The initialized instance
## Dropdown:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Dropdown:render()

View File

@@ -1,52 +1,46 @@
# Flexbox : Container # Flexbox
This is the Flexbox class. It is a container that arranges its children in a flexible layout. _This is the Flexbox class. It is a container that arranges its children in a flexible layout.
### Usage
```lua
local flex = main:addFlexbox({background=colors.black, width=30, height=10})
flex:addButton():setFlexGrow(1)
flex:addButton():setFlexGrow(1)
flex:addButton():setFlexGrow(1)
```
The flexbox element adds the following properties to its children: The flexbox element adds the following properties to its children:
_
### Usage Extends: `Container`
```lua
flex:addButton():setFlexGrow(1) -- The flex-grow property defines the ability for a flex item to grow if necessary.
flex:addButton():setFlexShrink(1) -- The flex-shrink property defines the ability for a flex item to shrink if necessary.
flex:addButton():setFlexBasis(1) -- The flex-basis property defines the default size of an element before the remaining space is distributed.
```
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|flexDirection|string|"row"|The direction of the flexbox layout "row" or "column" |flexDirection|string|"row"|The direction of the flexbox layout "row" or "column"|
|flexSpacing|number|1|The spacing between flex items |flexSpacing|number|1|The spacing between flex items|
|flexJustifyContent|string|"flex-start"|The alignment of flex items along the main axis |flexJustifyContent|string|"flex-start"|The alignment of flex items along the main axis|
|flexWrap|boolean|false|Whether to wrap flex items onto multiple lines |flexAlignItems|string|"flex-start"|The alignment of flex items along the cross axis|
|flexUpdateLayout|boolean|false|Whether to update the layout of the flexbox |flexCrossPadding|number|0|The padding on both sides of the cross axis|
|flexWrap|boolean|false|Whether to wrap flex items onto multiple lines|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Flexbox:addChild](#flexbox-addchild)|Flexbox|Adds a child element to the flexbox |[Flexbox.new](#flexbox-new)|Flexbox|Creates a new Flexbox instance|
|[Flexbox:addLineBreak](#flexbox-addlinebreak)|Flexbox|Adds a new line break to the flexbox. |[Flexbox:init](#flexbox-init-props-basalt)|Flexbox|Initializes the Flexbox instance|
|[Flexbox:addChild](#flexbox-addchild-element)|Flexbox|Adds a child element to the flexbox|
|[Flexbox:removeChild](#flexbox-removechild-element)|Flexbox|Removes a child element from the flexbox|
|[Flexbox:addLineBreak](#flexbox-addlinebreak-self)|Flexbox|Adds a new line break to the flexbox.|
|[Flexbox:render](#flexbox-render)|-|Renders the flexbox and its children|
## Flexbox.new()
### Returns
* `Flexbox` `object` The newly created Flexbox instance
## Protected Functions ## Flexbox:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
|Method|Returns|Description| ### Returns
|---|---|---| * `Flexbox` `self` The initialized instance
|Flexbox:init|Flexbox|Initializes the Flexbox instance
|Flexbox:removeChild|Flexbox|Removes a child element from the flexbox
|Flexbox:render|-|Renders the flexbox and its children
## Flexbox:addChild(element) ## Flexbox:addChild(element)
Adds a child element to the flexbox Adds a child element to the flexbox
### Parameters ### Parameters
@@ -55,13 +49,21 @@ Adds a child element to the flexbox
### Returns ### Returns
* `Flexbox` `self` The flexbox instance * `Flexbox` `self` The flexbox instance
## Flexbox:removeChild(element)
### Parameters
* `element` `Element` The child element to remove
### Returns
* `Flexbox` `self` The flexbox instance
## Flexbox:addLineBreak(self) ## Flexbox:addLineBreak(self)
Adds a new line break to the flexbox Adds a new line break to the flexbox
### Parameters ### Parameters
* `self` `Flexbox` The element itself * `self` `Flexbox` The element itself
### Returns ### Returns
* `nil` `nil` nil * `Flexbox`
## Flexbox:render()

View File

@@ -1,21 +1,79 @@
# Frame : Container # Frame
This is the frame class. It serves as a grouping container for other elements. _This is the frame class. It serves as a grouping container for other elements._
Extends: `Container`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|draggable|boolean|false|Whether the frame is draggable |draggable|boolean|false|Whether the frame is draggable|
|draggingMap|table|{}|The map of dragging positions |draggingMap|table|{}|The map of dragging positions|
|scrollable|boolean|false|Whether the frame is scrollable|
## Functions
## Protected Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|Frame:init|Frame|Initializes the Frame instance |[Frame.new](#frame-new)|Frame|Creates a new Frame instance|
|Frame:mouse_click|boolean|Handles mouse click events |[Frame:init](#frame-init-props-basalt)|Frame|Initializes the Frame instance|
|Frame:mouse_drag|boolean|Handles mouse drag events |[Frame:mouse_click](#frame-mouse-click-button-x-y)|boolean|Handles mouse click events|
|Frame:mouse_up|boolean|Handles mouse release events |[Frame:mouse_up](#frame-mouse-up-button-x-y)|boolean|Handles mouse release events|
|[Frame:mouse_drag](#frame-mouse-drag-button-x-y)|boolean|Handles mouse drag events|
|[Frame:getChildrenHeight](#frame-getchildrenheight)|number|Calculates the total height of all children elements|
|[Frame:mouse_scroll](#frame-mouse-scroll-direction-x-y)|boolean|Handles mouse scroll events|
## Frame.new()
Creates a new Frame instance
### Returns
* `Frame` `self` The newly created Frame instance
## Frame:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `Frame` `self` The initialized instance
## Frame:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Frame:mouse_up(button, x, y)
### Parameters
* `button` `number` The button that was released
* `x` `number` The x position of the release
* `y` `number` The y position of the release
### Returns
* `boolean` `handled` Whether the event was handled
## Frame:mouse_drag(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the drag position
* `y` `number` The y position of the drag position
### Returns
* `boolean` `handled` Whether the event was handled
## Frame:getChildrenHeight()
### Returns
* `number` `height` The total height needed for all children
## Frame:mouse_scroll(direction, x, y)
### Parameters
* `direction` `number` The scroll direction
* `x` `number` The x position of the scroll
* `y` `number` The y position of the scroll
### Returns
* `boolean` `handled` Whether the event was handled

View File

@@ -1,62 +1,48 @@
# Graph : VisualElement # Graph
This is the base class for all graph elements. It is a point based graph. _This is the base class for all graph elements. It is a point based graph._
### Usage
```lua
local graph = main:addGraph()
:addSeries("input", " ", colors.green, colors.green, 10)
:addSeries("output", " ", colors.red, colors.red, 10)
basalt.schedule(function()
while true do
graph:addPoint("input", math.random(1,100))
graph:addPoint("output", math.random(1,100))
sleep(2)
end
end)
```
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|minValue|number|0|The minimum value of the graph |minValue|number|0|The minimum value of the graph|
|maxValue|number|100|The maximum value of the graph |maxValue|number|100|The maximum value of the graph|
|series|table|{}|The series of the graph |series|table|{}|The series of the graph|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Graph:addPoint](#graph-addpoint)|Graph|Adds a point to a series |[Graph.new](#graph-new)|Graph|Creates a new Graph instance|
|[Graph:addSeries](#graph-addseries)|Graph|Adds a series to the graph |[Graph:init](#graph-init-props-basalt)|Graph|Initializes the Graph instance|
|[Graph:changeSeriesVisibility](#graph-changeseriesvisibility)|Graph|Changes the visibility of a series |[Graph:addSeries](#graph-addseries-name-symbol-bgcol-fgcol-pointcount)|Graph|Adds a series to the graph|
|[Graph:clear](#graph-clear)|Graph|Clears all points from a series |[Graph:removeSeries](#graph-removeseries-name)|Graph|Removes a series from the graph|
|[Graph:focusSeries](#graph-focusseries)|Graph|Focuses a series |[Graph:getSeries](#graph-getseries-name)|series|Gets a series from the graph|
|[Graph:getSeries](#graph-getseries)|table?|Gets a series from the graph |[Graph:changeSeriesVisibility](#graph-changeseriesvisibility-name-visible)|Graph|Changes the visibility of a series|
|[Graph:removeSeries](#graph-removeseries)|Graph|Removes a series from the graph |[Graph:addPoint](#graph-addpoint-name-value)|Graph|Adds a point to a series|
|[Graph:setSeriesPointCount](#graph-setseriespointcount)|Graph|Sets the point count of a series |[Graph:focusSeries](#graph-focusseries-name)|Graph|Focuses a series|
|[Graph:setSeriesPointCount](#graph-setseriespointcount-name-count)|Graph|Sets the point count of a series|
|[Graph:clear](#graph-clear-name)|Graph|Clears all points from a series|
|[Graph:render](#graph-render)|-|Renders the graph|
## Graph.new()
## Protected Functions Creates a new Graph instance
|Method|Returns|Description|
|---|---|---|
|Graph:init|Graph|Initializes the Graph instance
|Graph:render|-|Renders the graph
## Graph:addPoint(name, value)
### Parameters
* `name` `string` The name of the series
* `value` `number` The value of the point
### Returns ### Returns
* `Graph` `self` The graph instance * `Graph` `self` The newly created Graph instance
## Graph:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `Graph` `self` The initialized instance
## Graph:addSeries(name, symbol, bgCol, fgCol, pointCount) ## Graph:addSeries(name, symbol, bgCol, fgCol, pointCount)
### Parameters ### Parameters
* `name` `string` The name of the series * `name` `string` The name of the series
* `symbol` `string` The symbol of the series * `symbol` `string` The symbol of the series
@@ -67,8 +53,21 @@ end)
### Returns ### Returns
* `Graph` `self` The graph instance * `Graph` `self` The graph instance
## Graph:changeSeriesVisibility(name, visible) ## Graph:removeSeries(name)
### Parameters
* `name` `string` The name of the series
### Returns
* `Graph` `self` The graph instance
## Graph:getSeries(name)
### Parameters
* `name` `string` The name of the series
### Returns
* `series` `The` series
## Graph:changeSeriesVisibility(name, visible)
### Parameters ### Parameters
* `name` `string` The name of the series * `name` `string` The name of the series
* `visible` `boolean` Whether the series should be visible * `visible` `boolean` Whether the series should be visible
@@ -76,7 +75,31 @@ end)
### Returns ### Returns
* `Graph` `self` The graph instance * `Graph` `self` The graph instance
## Graph:addPoint(name, value)
### Parameters
* `name` `string` The name of the series
* `value` `number` The value of the point
### Returns
* `Graph` `self` The graph instance
## Graph:focusSeries(name)
### Parameters
* `name` `string` The name of the series
### Returns
* `Graph` `self` The graph instance
## Graph:setSeriesPointCount(name, count)
### Parameters
* `name` `string` The name of the series
* `count` `number` The number of points in the series
### Returns
* `Graph` `self` The graph instance
## Graph:clear(name?) ## Graph:clear(name?)
Clears all points from a series Clears all points from a series
### Parameters ### Parameters
@@ -85,37 +108,4 @@ Clears all points from a series
### Returns ### Returns
* `Graph` `self` The graph instance * `Graph` `self` The graph instance
## Graph:focusSeries(name) ## Graph:render()
### Parameters
* `name` `string` The name of the series
### Returns
* `Graph` `self` The graph instance
## Graph:getSeries(name)
### Parameters
* `name` `string` The name of the series
### Returns
* `table?` `series` The series
## Graph:removeSeries(name)
### Parameters
* `name` `string` The name of the series
### Returns
* `Graph` `self` The graph instance
## Graph:setSeriesPointCount(name, count)
### Parameters
* `name` `string` The name of the series
* `count` `number` The number of points in the series
### Returns
* `Graph` `self` The graph instance

View File

@@ -1,104 +1,80 @@
# Image : VisualElement # Image
This is the Image element class which can be used to display bimg formatted images. _This is the Image element class which can be used to display bimg formatted images.
Bimg is a universal ComputerCraft image format. Bimg is a universal ComputerCraft image format.
See: https://github.com/SkyTheCodeMaster/bimg See: https://github.com/SkyTheCodeMaster/bimg_
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|bimg|table|{}|The bimg image data |bimg|table|{}|The bimg image data|
|currentFrame|number|1|Current animation frame |currentFrame|number|1|Current animation frame|
|autoResize|boolean|false|Whether to automatically resize the image when content exceeds bounds |autoResize|boolean|false|Whether to automatically resize the image when content exceeds bounds|
|offsetX|number|0|Horizontal offset for viewing larger images |offsetX|number|0|Horizontal offset for viewing larger images|
|offsetY|number|0|Vertical offset for viewing larger images |offsetY|number|0|Vertical offset for viewing larger images|
## Combined Properties
|Name|Properties|Description|
|---|---|---|
|offset|`offsetX offsetY`|Combined property for offsetX and offsetY|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Image:addFrame](#image-addframe)|Image|Adds a new frame to the image |[Image.new](#image-new)|Image|Creates a new Image instance|
|[Image:getBg](#image-getbg)|string|Gets the background color at the specified position |[Image:init](#image-init-props-basalt)|Image|Initializes the Image instance|
|[Image:getFg](#image-getfg)|string|Gets the foreground color at the specified position |[Image:resizeImage](#image-resizeimage-width-height)|Image|Resizes the image to the specified width and height|
|[Image:getFrame](#image-getframe)|table|Gets the specified frame |[Image:getImageSize](#image-getimagesize)|number, number|Gets the size of the image|
|[Image:getImageSize](#image-getimagesize)|number|Gets the size of the image |[Image:getPixelData](#image-getpixeldata-x-y)|fg, bg, char|Gets pixel information at position|
|[Image:getMetadata](#image-getmetadata)|table|Gets the metadata of the image |[Image:setText](#image-settext-x-y-text)|Image|Sets the text at the specified position|
|[Image:getPixelData](#image-getpixeldata)|number?|Gets pixel information at position |[Image:getText](#image-gettext-x-y-length)|string|Gets the text at the specified position|
|[Image:getText](#image-gettext)|string|Gets the text at the specified position |[Image:setFg](#image-setfg-x-y-pattern)|Image|Sets the foreground color at the specified position|
|[Image:nextFrame](#image-nextframe)|Image|Advances to the next frame in the animation |[Image:getFg](#image-getfg-x-y-length)|string|Gets the foreground color at the specified position|
|[Image:resizeImage](#image-resizeimage)|Image|Resizes the image to the specified width and height |[Image:setBg](#image-setbg-x-y-pattern)|Image|Sets the background color at the specified position|
|[Image:setBg](#image-setbg)|Image|Sets the background color at the specified position |[Image:getBg](#image-getbg-x-y-length)|string|Gets the background color at the specified position|
|[Image:setFg](#image-setfg)|Image|Sets the foreground color at the specified position |[Image:setPixel](#image-setpixel-x-y-char-fg-bg)|Image|Sets the pixel at the specified position|
|[Image:setMetadata](#image-setmetadata)|Image|Sets the metadata of the image |[Image:nextFrame](#image-nextframe)|Image|Advances to the next frame in the animation|
|[Image:setPixel](#image-setpixel)|Image|Sets the pixel at the specified position |[Image:addFrame](#image-addframe)|Image|Adds a new frame to the image|
|[Image:setText](#image-settext)|Image|Sets the text at the specified position |[Image:updateFrame](#image-updateframe-frameindex-frame)|Image|Updates the specified frame with the provided data|
|[Image:updateFrame](#image-updateframe)|Image|Updates the specified frame with the provided data |[Image:getFrame](#image-getframe-frameindex)|table|Gets the specified frame|
|[Image:getMetadata](#image-getmetadata)|table|Gets the metadata of the image|
|[Image:setMetadata](#image-setmetadata-key-value)|Image|Sets the metadata of the image|
|[Image:render](#image-render)|-|Renders the Image|
## Image.new()
## Protected Functions Creates a new Image instance
|Method|Returns|Description| ### Returns
|---|---|---| * `Image` `self` The newly created Image instance
|Image:init|Image|Initializes the Image instance
|Image:render|-|Renders the Image
## Image:addFrame() ## Image:init(props, basalt)
Adds a new frame to the image ### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `Image` `self` The initialized instance
## Image:resizeImage(width, height)
Resizes the image to the specified width and height
### Parameters
* `width` `number` The new width of the image
* `height` `number` The new height of the image
### Returns ### Returns
* `Image` `self` The Image instance * `Image` `self` The Image instance
## Image:getBg(x, y, length)
Gets the background color at the specified position
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `length` `number` The length of the background color pattern to get
### Returns
* `string` `bg` The background color pattern
## Image:getFg(x, y, length)
Gets the foreground color at the specified position
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `length` `number` The length of the foreground color pattern to get
### Returns
* `string` `fg` The foreground color pattern
## Image:getFrame(frameIndex)
Gets the specified frame
### Parameters
* `frameIndex` `number` The index of the frame to get
### Returns
* `table` `frame` The frame data
## Image:getImageSize() ## Image:getImageSize()
Gets the size of the image Gets the size of the image
### Returns ### Returns
* `number` `width` The width of the image * `number` `width` The width of the image
* `number` `height` The height of the image * `number` `height` The height of the image
## Image:getMetadata()
Gets the metadata of the image
### Returns
* `table` `metadata` The metadata of the image
## Image:getPixelData(x, y) ## Image:getPixelData(x, y)
Gets pixel information at position Gets pixel information at position
### Parameters ### Parameters
@@ -106,11 +82,24 @@ Gets pixel information at position
* `y` `number` Y position * `y` `number` Y position
### Returns ### Returns
* `number?` `fg` Foreground color * `fg` `Foreground` color
* `number?` `bg` Background color * `bg` `Background` color
* `string?` `char` Character at position * `char` `Character` at position
## Image:setText(x, y, text)
Sets the text at the specified position
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `text` `string` The text to set
### Returns
* `Image` `self` The Image instance
## Image:getText(x, y, length) ## Image:getText(x, y, length)
Gets the text at the specified position Gets the text at the specified position
### Parameters ### Parameters
@@ -121,34 +110,8 @@ Gets the text at the specified position
### Returns ### Returns
* `string` `text` The text at the specified position * `string` `text` The text at the specified position
## Image:nextFrame()
Advances to the next frame in the animation
### Returns
* `Image` `self` The Image instance
## Image:resizeImage(width, height)
Resizes the image to the specified width and height
### Parameters
* `width` `number` The new width of the image
* `height` `number` The new height of the image
### Returns
* `Image` `self` The Image instance
## Image:setBg(x, y, pattern)
Sets the background color at the specified position
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `pattern` `string` The background color pattern
### Returns
* `Image` `self` The Image instance
## Image:setFg(x, y, pattern) ## Image:setFg(x, y, pattern)
Sets the foreground color at the specified position Sets the foreground color at the specified position
### Parameters ### Parameters
@@ -159,17 +122,44 @@ Sets the foreground color at the specified position
### Returns ### Returns
* `Image` `self` The Image instance * `Image` `self` The Image instance
## Image:setMetadata(key, value) ## Image:getFg(x, y, length)
Sets the metadata of the image
Gets the foreground color at the specified position
### Parameters ### Parameters
* `key` `string` The key of the metadata to set * `x` `number` The x position
* `value` `string` The value of the metadata to set * `y` `number` The y position
* `length` `number` The length of the foreground color pattern to get
### Returns
* `string` `fg` The foreground color pattern
## Image:setBg(x, y, pattern)
Sets the background color at the specified position
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `pattern` `string` The background color pattern
### Returns ### Returns
* `Image` `self` The Image instance * `Image` `self` The Image instance
## Image:getBg(x, y, length)
Gets the background color at the specified position
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `length` `number` The length of the background color pattern to get
### Returns
* `string` `bg` The background color pattern
## Image:setPixel(x, y, char, fg, bg) ## Image:setPixel(x, y, char, fg, bg)
Sets the pixel at the specified position Sets the pixel at the specified position
### Parameters ### Parameters
@@ -182,18 +172,22 @@ Sets the pixel at the specified position
### Returns ### Returns
* `Image` `self` The Image instance * `Image` `self` The Image instance
## Image:setText(x, y, text) ## Image:nextFrame()
Sets the text at the specified position
### Parameters Advances to the next frame in the animation
* `x` `number` The x position
* `y` `number` The y position ### Returns
* `text` `string` The text to set * `Image` `self` The Image instance
## Image:addFrame()
Adds a new frame to the image
### Returns ### Returns
* `Image` `self` The Image instance * `Image` `self` The Image instance
## Image:updateFrame(frameIndex, frame) ## Image:updateFrame(frameIndex, frame)
Updates the specified frame with the provided data Updates the specified frame with the provided data
### Parameters ### Parameters
@@ -203,4 +197,32 @@ Updates the specified frame with the provided data
### Returns ### Returns
* `Image` `self` The Image instance * `Image` `self` The Image instance
## Image:getFrame(frameIndex)
Gets the specified frame
### Parameters
* `frameIndex` `number` The index of the frame to get
### Returns
* `table` `frame` The frame data
## Image:getMetadata()
Gets the metadata of the image
### Returns
* `table` `metadata` The metadata of the image
## Image:setMetadata(key, value)
Sets the metadata of the image
### Parameters
* `key` `string` The key of the metadata to set
* `value` `string` The value of the metadata to set
### Returns
* `Image` `self` The Image instance
## Image:render()

View File

@@ -1,44 +1,53 @@
# Input : VisualElement # Input
This is the input class. It provides a text input field that can handle user input with various features like _This is the input class. It provides a text input field that can handle user input with various features like
cursor movement, text manipulation, placeholder text, and input validation. cursor movement, text manipulation, placeholder text, and input validation._
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|text|string|-|The current text content of the input |text|string|-|The current text content of the input|
|cursorPos|number|1|The current cursor position in the text |cursorPos|number|1|The current cursor position in the text|
|viewOffset|number|0|The horizontal scroll offset for viewing long text |viewOffset|number|0|The horizontal scroll offset for viewing long text|
|maxLength|number?|nil|Maximum length of input text (optional) |placeholder|string|...|Text to display when input is empty|
|placeholder|string|...|Text to display when input is empty |placeholderColor|color|gray|Color of the placeholder text|
|placeholderColor|color|gray|Color of the placeholder text |focusedBackground|color|blue|Background color when input is focused|
|focusedBackground|color|blue|Background color when input is focused |focusedForeground|color|white|Foreground color when input is focused|
|focusedForeground|color|white|Foreground color when input is focused |cursorColor|number|nil|Color of the cursor|
|pattern|string?|nil|Regular expression pattern for input validation |replaceChar|string|nil|Character to replace the input with (for password fields)|
|cursorColor|number|nil|Color of the cursor
|replaceChar|string|nil|Character to replace the input with (for password fields)
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Input:setCursor](#input-setcursor)|-|Sets the cursor position and color |[Input.new](#input-new)|Input|Creates a new Input instance|
|[Input:updateViewport](#input-updateviewport)|Input|Updates the input's viewport |[Input:init](#input-init-props-basalt)|Input|Initializes the Input instance|
|[Input:setCursor](#input-setcursor-x-y-blink-color)|-|Sets the cursor position and color|
|[Input:char](#input-char-char)|boolean|Handles char events|
|[Input:key](#input-key-key)|boolean|Handles key events|
|[Input:mouse_click](#input-mouse-click-button-x-y)|boolean|Handles mouse click events|
|[Input:updateViewport](#input-updateviewport)|Input|Updates the input's viewport|
|[Input:focus](#input-focus)|-|Handles a focus event|
|[Input:blur](#input-blur)|-|Handles a blur event|
|[Input:paste](#input-paste)|-|Handles paste events|
|[Input:render](#input-render)|-|Renders the input element|
## Input.new()
### Returns
* `Input` `object` The newly created Input instance
## Protected Functions ## Input:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
|Method|Returns|Description| ### Returns
|---|---|---| * `Input` `self` The initialized instance
|Input:blur|-|Handles a blur event
|Input:char|boolean|Handles char events
|Input:focus|-|Handles a focus event
|Input:init|Input|Initializes the Input instance
|Input:key|boolean|Handles key events
|Input:mouse_click|boolean|Handles mouse click events
|Input:render|-|Renders the input element
## Input:setCursor(x, y, blink, color) ## Input:setCursor(x, y, blink, color)
Sets the cursor position and color Sets the cursor position and color
### Parameters ### Parameters
@@ -47,10 +56,37 @@ Sets the cursor position and color
* `blink` `boolean` Whether the cursor should blink * `blink` `boolean` Whether the cursor should blink
* `color` `number` The color of the cursor * `color` `number` The color of the cursor
## Input:char(char)
### Parameters
* `char` `string` The character that was typed
### Returns
* `boolean` `handled` Whether the event was handled
## Input:key(key)
### Parameters
* `key` `number` The key that was pressed
### Returns
* `boolean` `handled` Whether the event was handled
## Input:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Input:updateViewport() ## Input:updateViewport()
Updates the input's viewport Updates the input's viewport
### Returns ### Returns
* `Input` `self` The updated instance * `Input` `self` The updated instance
## Input:focus()
## Input:blur()
## Input:paste()
## Input:render()

View File

@@ -1,32 +1,45 @@
# Label : VisualElement # Label
This is the label class. It provides a simple text display element that automatically _This is the label class. It provides a simple text display element that automatically
resizes its width based on the text content. resizes its width based on the text content._
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|text|string|Label|The text content to display. Can be a string or a function that returns a string |text|string|Label|The text content to display. Can be a string or a function that returns a string|
|autoSize|boolean|true|Whether the label should automatically resize its width based on the text content |autoSize|boolean|true|Whether the label should automatically resize its width based on the text content|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Label:getWrappedText](#label-getwrappedtext)|table|Gets the wrapped lines of the Label |[Label.new](#label-new)|Label|Creates a new Label instance|
|[Label:init](#label-init-props-basalt)|Label|Initializes the Label instance|
|[Label:getWrappedText](#label-getwrappedtext)|table|Gets the wrapped lines of the Label|
|[Label:render](#label-render)|-|Renders the Label by drawing its text content|
## Label.new()
## Protected Functions Creates a new Label instance
|Method|Returns|Description| ### Returns
|---|---|---| * `Label` `self` The newly created Label instance
|Label:init|Label|Initializes the Label instance
|Label:render|-|Renders the Label by drawing its text content ## Label:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `Label` `self` The initialized instance
## Label:getWrappedText() ## Label:getWrappedText()
Gets the wrapped lines of the Label Gets the wrapped lines of the Label
### Returns ### Returns
* `table` `wrappedText` The wrapped lines of the Label * `table` `wrappedText` The wrapped lines of the Label
## Label:render()

View File

@@ -1,28 +1,29 @@
# LineChart : Graph # LineChart
The Line Chart element visualizes data series as connected line graphs. It plots points on a coordinate system and connects them with lines. _The Line Chart element visualizes data series as connected line graphs. It plots points on a coordinate system and connects them with lines._
### Usage Extends: `Graph`
```lua
local chart = main:addLineChart()
:addSeries("input", " ", colors.green, colors.green, 10)
:addSeries("output", " ", colors.red, colors.red, 10)
basalt.schedule(function() ## Functions
while true do
chart:addPoint("input", math.random(1,100))
chart:addPoint("output", math.random(1,100))
sleep(2)
end
end)
```
## Protected Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|LineChart:init|LineChart|Initializes the LineChart instance |[LineChart.new](#linechart-new)|LineChart|Creates a new LineChart instance|
|LineChart:render|-|Renders the LineChart |[LineChart:init](#linechart-init-props-basalt)|LineChart|Initializes the LineChart instance|
|[LineChart:render](#linechart-render)|-|Renders the LineChart|
## LineChart.new()
Creates a new LineChart instance
### Returns
* `LineChart` `self` The newly created LineChart instance
## LineChart:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `LineChart` `self` The initialized instance
## LineChart:render()

View File

@@ -1,17 +1,19 @@
# List : VisualElement # List
This is the list class. It provides a scrollable list of selectable items with support for _This is the list class. It provides a scrollable list of selectable items with support for
custom item rendering, separators, and selection handling. custom item rendering, separators, and selection handling._
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|items|table|{}|List of items to display. Items can be tables with properties including selected state |items|table|{}|List of items to display. Items can be tables with properties including selected state|
|selectable|boolean|true|Whether items in the list can be selected |selectable|boolean|true|Whether items in the list can be selected|
|multiSelection|boolean|false|Whether multiple items can be selected at once |multiSelection|boolean|false|Whether multiple items can be selected at once|
|offset|number|0|Current scroll offset for viewing long lists |offset|number|0|Current scroll offset for viewing long lists|
|selectedBackground|color|blue|Background color for selected items |selectedBackground|color|blue|Background color for selected items|
|selectedForeground|color|white|Text color for selected items |selectedForeground|color|white|Text color for selected items|
## Events ## Events
@@ -23,26 +25,37 @@ custom item rendering, separators, and selection handling.
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[List:addItem](#list-additem)|List|Adds an item to the list |[List.new](#list-new)|List|Creates a new List instance|
|[List:clear](#list-clear)|List|Clears all items from the list |[List:init](#list-init-props-basalt)|List|Initializes the List instance|
|[List:getSelectedItem](#list-getselecteditem)|table?|Gets first selected item |[List:addItem](#list-additem-text)|List|Adds an item to the list|
|[List:getSelectedItems](#list-getselecteditems)|table|Gets the currently selected items |[List:removeItem](#list-removeitem-index)|List|Removes an item from the list|
|[List:onSelect](#list-onselect)|List|Registers a callback for the select event |[List:clear](#list-clear)|List|Clears all items from the list|
|[List:removeItem](#list-removeitem)|List|Removes an item from the list |[List:getSelectedItems](#list-getselecteditems)|table|Gets the currently selected items|
|[List:scrollToBottom](#list-scrolltobottom)|List|Scrolls the list to the bottom |[List:getSelectedItem](#list-getselecteditem)|selected|Gets first selected item|
|[List:scrollToTop](#list-scrolltotop)|List|Scrolls the list to the top |[List:mouse_click](#list-mouse-click-button-x-y)|boolean|Handles mouse click events|
|[List:mouse_scroll](#list-mouse-scroll-direction-x-y)|boolean|Handles mouse scroll events|
|[List:onSelect](#list-onselect-callback)|List|Registers a callback for the select event|
|[List:scrollToBottom](#list-scrolltobottom)|List|Scrolls the list to the bottom|
|[List:scrollToTop](#list-scrolltotop)|List|Scrolls the list to the top|
|[List:render](#list-render)|-|Renders the list|
## List.new()
## Protected Functions Creates a new List instance
|Method|Returns|Description| ### Returns
|---|---|---| * `List` `self` The newly created List instance
|List:init|List|Initializes the List instance
|List:mouse_click|boolean|Handles mouse click events ## List:init(props, basalt)
|List:mouse_scroll|boolean|Handles mouse scroll events ### Parameters
|List:render|-|Renders the list * `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `List` `self` The initialized instance
## List:addItem(text) ## List:addItem(text)
Adds an item to the list Adds an item to the list
### Parameters ### Parameters
@@ -52,54 +65,13 @@ Adds an item to the list
* `List` `self` The List instance * `List` `self` The List instance
### Usage ### Usage
```lua ```lua
list:addItem("New Item") list:addItem("New Item")
list:addItem({text="Item", callback=function() end}) list:addItem({text="Item", callback=function() end})
``` ```
## List:clear()
Clears all items from the list
### Returns
* `List` `self` The List instance
### Usage
```lua
list:clear()
```
## List:getSelectedItem()
Gets first selected item
### Returns
* `table?` `selected` The first item
## List:getSelectedItems()
Gets the currently selected items
### Returns
* `table` `selected` List of selected items
### Usage
```lua
local selected = list:getSelectedItems()
```
## List:onSelect(callback)
Registers a callback for the select event
### Parameters
* `callback` `function` The callback function to register
### Returns
* `List` `self` The List instance
### Usage
```lua
list:onSelect(function(index, item) print("Selected item:", index, item) end)
```
## List:removeItem(index) ## List:removeItem(index)
Removes an item from the list Removes an item from the list
### Parameters ### Parameters
@@ -109,20 +81,86 @@ Removes an item from the list
* `List` `self` The List instance * `List` `self` The List instance
### Usage ### Usage
```lua ```lua
list:removeItem(1) list:removeItem(1)
``` ```
## List:clear()
Clears all items from the list
### Returns
* `List` `self` The List instance
### Usage
```lua
list:clear()
```
## List:getSelectedItems()
Gets the currently selected items
### Returns
* `table` `selected` List of selected items
### Usage
```lua
local selected = list:getSelectedItems()
```
## List:getSelectedItem()
Gets first selected item
### Returns
* `selected` `The` first item
## List:mouse_click(button, x, y)
### Parameters
* `button` `number` The mouse button that was clicked
* `x` `number` The x-coordinate of the click
* `y` `number` The y-coordinate of the click
### Returns
* `boolean` `Whether` the event was handled
## List:mouse_scroll(direction, x, y)
### Parameters
* `direction` `number` The direction of the scroll (1 for down, -1 for up)
* `x` `number` The x-coordinate of the scroll
* `y` `number` The y-coordinate of the scroll
### Returns
* `boolean` `Whether` the event was handled
## List:onSelect(callback)
Registers a callback for the select event
### Parameters
* `callback` `function` The callback function to register
### Returns
* `List` `self` The List instance
### Usage
```lua
list:onSelect(function(index, item) print("Selected item:", index, item) end)
```
## List:scrollToBottom() ## List:scrollToBottom()
Scrolls the list to the bottom Scrolls the list to the bottom
### Returns ### Returns
* `List` `self` The List instance * `List` `self` The List instance
## List:scrollToTop() ## List:scrollToTop()
Scrolls the list to the top Scrolls the list to the top
### Returns ### Returns
* `List` `self` The List instance * `List` `self` The List instance
## List:render()

View File

@@ -1,40 +1,61 @@
# Menu : List # Menu
This is the menu class. It provides a horizontal menu bar with selectable items. _This is the menu class. It provides a horizontal menu bar with selectable items.
Menu items are displayed in a single row and can have custom colors and callbacks. Menu items are displayed in a single row and can have custom colors and callbacks._
Extends: `List`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|separatorColor|color|gray|The color used for separator items in the menu |separatorColor|color|gray|The color used for separator items in the menu|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Menu:setItems](#menu-setitems)|Menu|Sets the menu items and calculates total width |[Menu.new](#menu-new)|Menu|Creates a new Menu instance|
|[Menu:init](#menu-init-props-basalt)|Menu|Initializes the Menu instance|
|[Menu:setItems](#menu-setitems-items)|Menu|Sets the menu items and calculates total width|
|[Menu:render](#menu-render)|-|Renders the menu horizontally with proper spacing and colors|
|[Menu:mouse_click](#menu-mouse-click-button-x-y)|boolean|Handles mouse click events and item selection|
## Menu.new()
## Protected Functions Creates a new Menu instance
|Method|Returns|Description| ### Returns
|---|---|---| * `Menu` `self` The newly created Menu instance
|Menu:init|Menu|Initializes the Menu instance
|Menu:mouse_click|boolean|Handles mouse click events and item selection ## Menu:init(props, basalt)
|Menu:render|-|Renders the menu horizontally with proper spacing and colors ### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `Menu` `self` The initialized instance
## Menu:setItems(items) ## Menu:setItems(items)
Sets the menu items Sets the menu items
### Parameters ### Parameters
* `items` `table[]` List of items with {text, separator, callback, foreground, background} properties * `items` `table` [] List of items with {text, separator, callback, foreground, background} properties
### Returns ### Returns
* `Menu` `self` The Menu instance * `Menu` `self` The Menu instance
### Usage ### Usage
```lua ```lua
menu:setItems({{text="File"}, {separator=true}, {text="Edit"}}) menu:setItems({{text="File"}, {separator=true}, {text="Edit"}})
``` ```
## Menu:render()
## Menu:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `Whether` the event was handled

View File

@@ -1,37 +1,112 @@
# Program : VisualElement # Program
This is the program class. It provides a program that runs in a window. _This is the program class. It provides a program that runs in a window._
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|program|table|nil|The program instance |program|table|nil|The program instance|
|path|string|""|The path to the program |path|string|""|The path to the program|
|running|boolean|false|Whether the program is running |running|boolean|false|Whether the program is running|
|errorCallback|function|nil|The error callback function|
|doneCallback|function|nil|The done callback function|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Program:execute](#program-execute)|Program|Executes a program |[Program.new](#program-new)|-||
|[Program:run](#program-run)|-||
|[Program:resize](#program-resize)|-||
|[Program:resume](#program-resume)|-||
|[Program:stop](#program-stop)|-||
|[Program.new](#program-new)|Program|Creates a new Program instance|
|[Program:init](#program-init-props-basalt)|Program|Initializes the Program instance|
|[Program:execute](#program-execute-path-env-addenvironment)|Program|Executes a program|
|[Program:stop](#program-stop)|Program|Stops the program|
|[Program:sendEvent](#program-sendevent-event-any)|Program|Sends an event to the program|
|[Program:onError](#program-onerror-fn)|Program|Registers a callback for the program's error event|
|[Program:onDone](#program-ondone-fn)|Program|Registers a callback for the program's done event|
|[Program:dispatchEvent](#program-dispatchevent-event-any)|any|Handles all incomming events|
|[Program:focus](#program-focus)|-|Gets called when the element gets focused|
|[Program:render](#program-render)|-|Renders the program|
## Program.new()
## Program:run()
## Program:resize()
## Program:resume()
## Program:stop()
## Program.new()
### Returns
* `Program` `object` The newly created Program instance
## Protected Functions ## Program:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
|Method|Returns|Description| ### Returns
|---|---|---| * `Program` `self` The initialized instance
|Program:dispatchEvent|any|Handles all incomming events
|Program:focus|-|Gets called when the element gets focused ## Program:execute(path, env?, addEnvironment?)
|Program:init|Program|Initializes the Program instance
|Program:render|-|Renders the program
## Program:execute(path)
Executes a program Executes a program
### Parameters ### Parameters
* `path` `string` The path to the program * `path` `string` The path to the program
* `env` *(optional)* `table` The environment to run the program in
* `addEnvironment` *(optional)* `boolean` Whether to add the environment to the program's environment (false = overwrite instead of adding)
### Returns ### Returns
* `Program` `self` The Program instance * `Program` `self` The Program instance
## Program:stop()
Stops the program
### Returns
* `Program` `self` The Program instance
## Program:sendEvent(event, any)
Sends an event to the program
### Parameters
* `event` `string` The event to send
* `any` `The` event arguments
### Returns
* `Program` `self` The Program instance
## Program:onError(fn)
Registers a callback for the program's error event, if the function returns false, the program won't stop
### Parameters
* `fn` `function` The callback function to register
### Returns
* `Program` `self` The Program instance
## Program:onDone(fn)
Registers a callback for the program's done event
### Parameters
* `fn` `function` The callback function to register
### Returns
* `Program` `self` The Program instance
## Program:dispatchEvent(event, any)
### Parameters
* `event` `string` The event to handle
* `any` `The` event arguments
### Returns
* `any` `result` The event result
## Program:focus()
## Program:render()

View File

@@ -1,30 +1,39 @@
# ProgressBar : VisualElement # ProgressBar
This is the progress bar class. It provides a visual representation of progress _This is the progress bar class. It provides a visual representation of progress
with optional percentage display and customizable colors. with optional percentage display and customizable colors._
### Usage
```lua
local progressBar = main:addProgressBar()
progressBar:setDirection("up")
progressBar:setProgress(50)
```
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|progress|number|0|Current progress value (0-100) |progress|number|0|Current progress value (0-100)|
|showPercentage|boolean|false|Whether to show the percentage text in the center |showPercentage|boolean|false|Whether to show the percentage text in the center|
|progressColor|color|lime|The color used for the filled portion of the progress bar |progressColor|color|lime|The color used for the filled portion of the progress bar|
|direction|string|right|The direction of the progress bar ("up", "down", "left", "right") |direction|string|right|The direction of the progress bar ("up", "down", "left", "right")|
## Functions
## Protected Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|ProgressBar:init|ProgressBar|Initializes the ProgressBar instance |[ProgressBar.new](#progressbar-new)|ProgressBar|Creates a new ProgressBar instance|
|ProgressBar:render|-|Renders the progress bar with filled portion and optional percentage text |[ProgressBar:init](#progressbar-init-props-basalt)|ProgressBar|Initializes the ProgressBar instance|
|[ProgressBar:render](#progressbar-render)|-|Renders the progress bar with filled portion and optional percentage text|
## ProgressBar.new()
Creates a new ProgressBar instance
### Returns
* `ProgressBar` `self` The newly created ProgressBar instance
## ProgressBar:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `ProgressBar` `self` The initialized instance
## ProgressBar:render()

View File

@@ -1,58 +1,97 @@
# Scrollbar : VisualElement # ScrollBar
A scrollbar element that can be attached to other elements to control their scroll properties _A ScrollBar element that can be attached to other elements to control their scroll properties_
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|value|number|0|Current scroll value |value|number|0|Current scroll value|
|min|number|0|Minimum scroll value |min|number|0|Minimum scroll value|
|max|number|100|Maximum scroll value |max|number|100|Maximum scroll value|
|step|number|1|Step size for scroll operations |step|number|1|Step size for scroll operations|
|dragMultiplier|number|1|How fast the scrollbar moves when dragging |dragMultiplier|number|1|How fast the ScrollBar moves when dragging|
|symbol|string|"|" Symbol used for the scrollbar handle |symbol|string|"|" Symbol used for the ScrollBar handle|
|backgroundSymbol|string|"\127"|Symbol used for the scrollbar background |backgroundSymbol|string|"\127"|Symbol used for the ScrollBar background|
|symbolBackgroundColor|color|black|Background color of the scrollbar handle |symbolBackgroundColor|color|black|Background color of the ScrollBar handle|
|backgroundSymbol|string|"\127"|Symbol used for the scrollbar background |backgroundSymbol|string|"\127"|Symbol used for the ScrollBar background|
|attachedElement|table?|nil|The element this scrollbar is attached to |minValue|number|function|0|Minimum value or function that returns it|
|attachedProperty|string?|nil|The property being controlled |maxValue|number|function|100|Maximum value or function that returns it|
|minValue|number|function|0|Minimum value or function that returns it |orientation|string|vertical|Orientation of the ScrollBar ("vertical" or "horizontal")|
|maxValue|number|function|100|Maximum value or function that returns it |handleSize|number|2|Size of the ScrollBar handle in characters|
|orientation|string|vertical|Orientation of the scrollbar ("vertical" or "horizontal")
|handleSize|number|2|Size of the scrollbar handle in characters
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Scrollbar:attach](#scrollbar-attach)|Scrollbar|Attaches the scrollbar to an element's property |[ScrollBar.new](#scrollbar-new)|ScrollBar|Creates a new ScrollBar instance|
|[Scrollbar:updateAttachedElement](#scrollbar-updateattachedelement)|Scrollbar|Updates the attached element's property based on the scrollbar value |[ScrollBar:init](#scrollbar-init-props-basalt)|ScrollBar|Initializes the ScrollBar instance|
|[ScrollBar:attach](#scrollbar-attach-element-config)|ScrollBar|Attaches the ScrollBar to an element's property|
|[ScrollBar:updateAttachedElement](#scrollbar-updateattachedelement)|ScrollBar|Updates the attached element's property based on the ScrollBar value|
|[ScrollBar:mouse_click](#scrollbar-mouse-click-button-x-y)|boolean|Handles mouse click events|
|[ScrollBar:mouse_drag](#scrollbar-mouse-drag-button-x-y)|boolean|Handles mouse drag events|
|[ScrollBar:mouse_scroll](#scrollbar-mouse-scroll-direction-x-y)|boolean|Handles mouse scroll events|
|[ScrollBar:render](#scrollbar-render)|-|Renders the ScrollBar|
## ScrollBar.new()
## Protected Functions Creates a new ScrollBar instance
|Method|Returns|Description| ### Returns
|---|---|---| * `ScrollBar` `self` The newly created ScrollBar instance
|Scrollbar:init|Scrollbar|Initializes the Scrollbar instance
|Scrollbar:mouse_click|boolean|Handles mouse click events
|Scrollbar:mouse_drag|boolean|Handles mouse drag events
|Scrollbar:mouse_scroll|boolean|Handles mouse scroll events
|Scrollbar:render|-|Renders the scrollbar
## Scrollbar:attach(element, config) ## ScrollBar:init(props, basalt)
Attaches the scrollbar to an element's property ### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `ScrollBar` `self` The initialized instance
## ScrollBar:attach(element, config)
Attaches the ScrollBar to an element's property
### Parameters ### Parameters
* `element` `BaseElement` The element to attach to * `element` `BaseElement` The element to attach to
* `config` `table` Configuration {property = "propertyName", min = number|function, max = number|function} * `config` `table` Configuration {property = "propertyName", min = number|function, max = number|function}
### Returns ### Returns
* `Scrollbar` `self` The scrollbar instance * `ScrollBar` `self` The ScrollBar instance
## Scrollbar:updateAttachedElement() ## ScrollBar:updateAttachedElement()
Updates the attached element's property based on the scrollbar value
Updates the attached element's property based on the ScrollBar value
### Returns ### Returns
* `Scrollbar` `self` The scrollbar instance * `ScrollBar` `self` The ScrollBar instance
## ScrollBar:mouse_click(button, x, y)
### Parameters
* `button` `number` The mouse button clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `Whether` the event was handled
## ScrollBar:mouse_drag(button, x, y)
### Parameters
* `button` `number` The mouse button being dragged
* `x` `number` The x position of the drag
* `y` `number` The y position of the drag
### Returns
* `boolean` `Whether` the event was handled
## ScrollBar:mouse_scroll(direction, x, y)
### Parameters
* `direction` `number` The scroll direction (1 for up, -1 for down)
* `x` `number` The x position of the scroll
* `y` `number` The y position of the scroll
### Returns
* `boolean` `Whether` the event was handled
## ScrollBar:render()

View File

@@ -1,16 +1,18 @@
# Slider : VisualElement # Slider
This is the slider class. It provides a draggable slider control that can be either horizontal or vertical, _This is the slider class. It provides a draggable slider control that can be either horizontal or vertical,
with customizable colors and value ranges. with customizable colors and value ranges._
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|step|number|1|Current position of the slider handle (1 to width/height) |step|number|1|Current position of the slider handle (1 to width/height)|
|max|number|100|Maximum value for value conversion (maps slider position to this range) |max|number|100|Maximum value for value conversion (maps slider position to this range)|
|horizontal|boolean|true|Whether the slider is horizontal (false for vertical) |horizontal|boolean|true|Whether the slider is horizontal (false for vertical)|
|barColor|color|gray|Color of the slider track |barColor|color|gray|Color of the slider track|
|sliderColor|color|blue|Color of the slider handle |sliderColor|color|blue|Color of the slider handle|
## Events ## Events
@@ -22,27 +24,56 @@ with customizable colors and value ranges.
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Slider:getValue](#slider-getvalue)|number|Gets the current value mapped to the max range |[Slider.new](#slider-new)|Slider|Creates a new Slider instance|
|[Slider:init](#slider-init-props-basalt)|Slider|Initializes the Slider instance|
|[Slider:getValue](#slider-getvalue)|number|Gets the current value mapped to the max range|
|[Slider:mouse_click](#slider-mouse-click-button-x-y)|boolean|Updates slider position on mouse click|
|[Slider:mouse_scroll](#slider-mouse-scroll-button-x-y)|boolean|Handles mouse release events|
|[Slider:render](#slider-render)|-|Renders the slider with track and handle|
## Slider.new()
## Protected Functions Creates a new Slider instance
|Method|Returns|Description| ### Returns
|---|---|---| * `Slider` `self` The newly created Slider instance
|Slider:init|Slider|Initializes the Slider instance
|Slider:mouse_click|boolean|Updates slider position on mouse click ## Slider:init(props, basalt)
|Slider:mouse_scroll|boolean|Handles mouse release events ### Parameters
|Slider:render|-|Renders the slider with track and handle * `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `Slider` `self` The initialized instance
## Slider:getValue() ## Slider:getValue()
Gets the current value of the slider Gets the current value of the slider
### Returns ### Returns
* `number` `value` The current value (0 to max) * `number` `value` The current value (0 to max)
### Usage ### Usage
```lua ```lua
local value = slider:getValue() local value = slider:getValue()
``` ```
## Slider:mouse_click(button, x, y)
### Parameters
* `button` `number` The mouse button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Slider:mouse_scroll(button, x, y)
### Parameters
* `button` `number` The mouse button that was released
* `x` `number` The x position of the release
* `y` `number` The y position of the release
### Returns
* `boolean` `handled` Whether the event was handled
## Slider:render()

View File

@@ -1,18 +1,43 @@
# Switch : VisualElement # Switch
The Switch is a standard Switch element with click handling and state management. _The Switch is a standard Switch element with click handling and state management._
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|checked|boolean|Whether|switch is checked |checked|boolean|Whether|switch is checked|
|text|string|Text|to display next to switch|
|autoSize|boolean|Whether|to automatically size the element to fit switch and text|
|onBackground|number|Background|color when ON|
|offBackground|number|Background|color when OFF|
## Functions
## Protected Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|Switch:init|-|Initializes the Switch instance |[Switch.new](#switch-new)|table|Creates a new Switch instance|
|Switch:render|-|Renders the Switch |[Switch:init](#switch-init-props-basalt)|-|Initializes the Switch instance|
|[Switch:mouse_click](#switch-mouse-click-button-x-y)|boolean|Handles mouse click events|
|[Switch:render](#switch-render)|-|Renders the Switch|
## Switch.new()
### Returns
* `table` `self` The created instance
## Switch:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
## Switch:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `Whether` the event was handled
## Switch:render()

View File

@@ -0,0 +1,105 @@
# TabControl
_The TabControl is a container that provides tabbed interface functionality_
Extends: `Container`
## Properties
|Property|Type|Default|Description|
|---|---|---|---|
|activeTab|number|The|currently active tab ID|
|tabHeight|number|Height|of the tab header area|
|tabs|table|List|of tab definitions|
|headerBackground|color|Background|color for the tab header area|
|activeTabBackground|color|Background|color for the active tab|
|activeTabTextColor|color|Foreground|color for the active tab text|
## Functions
|Method|Returns|Description|
|---|---|---|
|[TabControl.new](#tabcontrol-new)|TabControl|Creates a new TabControl instance|
|[TabControl:init](#tabcontrol-init-props-basalt)|-|Initializes the TabControl instance|
|[TabControl:newTab](#tabcontrol-newtab-title)|table|Creates a new tab handler proxy|
|[TabControl:setTab](#tabcontrol-settab-element-tabid)|TabControl|Sets an element to belong to a specific tab|
|[TabControl:addElement](#tabcontrol-addelement-elementtype-tabid)|table|Adds an element to the TabControl and assigns it to the active tab|
|[TabControl:addChild](#tabcontrol-addchild-child)|Container|Overrides Container's addChild to assign new elements to tab 1 by default|
|[TabControl:updateTabVisibility](#tabcontrol-updatetabvisibility)|-|Updates visibility of tab containers|
|[TabControl:setActiveTab](#tabcontrol-setactivetab-tabid)|-|Sets the active tab|
|[TabControl:isChildVisible](#tabcontrol-ischildvisible-child)|boolean|Checks if a child should be visible (overrides Container)|
|[TabControl:getContentYOffset](#tabcontrol-getcontentyoffset)|number|Gets the content area Y offset (below tab headers)|
|[TabControl:mouse_click](#tabcontrol-mouse-click-button-x-y)|boolean|Handles mouse click events for tab switching|
|[TabControl:setCursor](#tabcontrol-setcursor)|-|Sets the cursor position; accounts for tab header offset when delegating to parent|
|[TabControl:render](#tabcontrol-render)|-|Renders the TabControl (header + children)|
|[TabControl:sortChildrenEvents](#tabcontrol-sortchildrenevents)|-||
## TabControl.new()
### Returns
* `TabControl` `self` The created instance
## TabControl:init(props, basalt)
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
## TabControl:newTab(title)
returns a proxy for adding elements to the tab
### Parameters
* `title` `string` The title of the tab
### Returns
* `table` `tabHandler` The tab handler proxy for adding elements to the new tab
## TabControl:setTab(element, tabId)
### Parameters
* `element` `table` The element to assign to a tab
* `tabId` `number` The ID of the tab to assign the element to
### Returns
* `TabControl` `self` For method chaining
## TabControl:addElement(elementType, tabId)
### Parameters
* `elementType` `string` The type of element to add
* `tabId` `number` Optional tab ID, defaults to active tab
### Returns
* `table` `element` The created element
## TabControl:addChild(child)
### Parameters
* `child` `table` The child element to add
### Returns
* `Container` `self` For method chaining
## TabControl:updateTabVisibility()
## TabControl:setActiveTab(tabId)
### Parameters
* `tabId` `number` The ID of the tab to activate
## TabControl:isChildVisible(child)
### Parameters
* `child` `table` The child element to check
### Returns
* `boolean` `Whether` the child should be visible
## TabControl:getContentYOffset()
### Returns
* `number` `yOffset` The Y offset for content
## TabControl:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click (global)
* `y` `number` The y position of the click (global)
### Returns
* `boolean` `Whether` the event was handled
## TabControl:setCursor()
## TabControl:render()
## TabControl:sortChildrenEvents()

View File

@@ -1,53 +1,143 @@
# Table : VisualElement # Table
This is the table class. It provides a sortable data grid with customizable columns, _This is the table class. It provides a sortable data grid with customizable columns,
row selection, and scrolling capabilities. row selection, and scrolling capabilities._
### Usage
```lua
local people = container:addTable():setWidth(40)
people:setColumns({{name="Name",width=12}, {name="Age",width=10}, {name="Country",width=15}})
people:setData({{"Alice", 30, "USA"}, {"Bob", 25, "UK"}})
```
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|columns|table|{}|List of column definitions with {name, width} properties |columns|table|{}|List of column definitions with {name, width} properties|
|data|table|{}|The table data as array of row arrays |data|table|{}|The table data as array of row arrays|
|selectedRow|number?|nil|Currently selected row index |headerColor|color|blue|Color of the column headers|
|headerColor|color|blue|Color of the column headers |selectedColor|color|lightBlue|Background color of selected row|
|selectedColor|color|lightBlue|Background color of selected row |gridColor|color|gray|Color of grid lines|
|gridColor|color|gray|Color of grid lines |sortDirection|string|"asc"|Sort direction ("asc" or "desc")|
|sortColumn|number?|nil|Currently sorted column index |scrollOffset|number|0|Current scroll position|
|sortDirection|string|"asc"|Sort direction ("asc" or "desc") |customSortFunction|table|{}|Custom sort functions for columns|
|scrollOffset|number|0|Current scroll position
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Table:sortData](#table-sortdata)|Table|Sorts the table data by the specified column |[Table.new](#table-new)|Table|Creates a new Table instance|
|[Table:init](#table-init-props-basalt)|Table|Initializes the Table instance|
|[Table:addColumn](#table-addcolumn-name-width)|Table|Adds a new column to the table|
|[Table:addData](#table-adddata-any)|Table|Adds a new row of data to the table|
|[Table:setColumnSortFunction](#table-setcolumnsortfunction-columnindex-sortfn)|Table|Sets a custom sort function for a column|
|[Table:setFormattedData](#table-setformatteddata-displaydata-sortdata)|Table|Adds formatted data with raw sort values|
|[Table:setData](#table-setdata-rawdata-formatters)|Table|Sets table data with optional column formatters|
|[Table:calculateColumnWidths](#table-calculatecolumnwidths-columns-totalwidth)|table|Calculates column widths for rendering|
|[Table:sortData](#table-sortdata-columnindex-fn)|Table|Sorts the table data by the specified column|
|[Table:mouse_click](#table-mouse-click-button-x-y)|boolean|Handles header clicks for sorting and row selection|
|[Table:mouse_scroll](#table-mouse-scroll-direction-x-y)|boolean|Handles scrolling through the table data|
|[Table:render](#table-render)|-|Renders the table with headers, data and scrollbar|
## Table.new()
## Protected Functions Creates a new Table instance
|Method|Returns|Description| ### Returns
|---|---|---| * `Table` `self` The newly created Table instance
|Table:init|Table|Initializes the Table instance
|Table:mouse_click|boolean|Handles header clicks for sorting and row selection
|Table:mouse_scroll|boolean|Handles scrolling through the table data
|Table:render|-|Renders the table with headers, data and scrollbar
## Table:sortData(columnIndex, fn) ## Table:init(props, basalt)
Sorts the table data by column ### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `Table` `self` The initialized instance
## Table:addColumn(name, width)
Adds a new column to the table
### Parameters ### Parameters
* `columnIndex` `number` The index of the column to sort by * `name` `string` The name of the column
* `fn` `function?` Optional custom sorting function * `width` `number` The width of the column
### Returns ### Returns
* `Table` `self` The Table instance * `Table` `self` The Table instance
## Table:addData(any)
Adds a new row of data to the table
### Parameters
* `any` `The` data for the new row
### Returns
* `Table` `self` The Table instance
## Table:setColumnSortFunction(columnIndex, sortFn)
Sets a custom sort function for a specific column
### Parameters
* `columnIndex` `number` The index of the column
* `sortFn` `function` Function that takes (rowA, rowB) and returns comparison result
### Returns
* `Table` `self` The Table instance
## Table:setFormattedData(displayData, sortData)
Adds data with both display and sort values
### Parameters
* `displayData` `table` The formatted data for display
* `sortData` `table` The raw data for sorting (optional)
### Returns
* `Table` `self` The Table instance
## Table:setData(rawData, formatters)
Set data with automatic formatting
### Parameters
* `rawData` `table` The raw data array
* `formatters` `table` Optional formatter functions for columns {[2] = function(value) return value end}
### Returns
* `Table` `self` The Table instance
## Table:calculateColumnWidths(columns, totalWidth)
### Parameters
* `columns` `table` The column definitions
* `totalWidth` `number` The total available width
### Returns
* `table` `The` columns with calculated visibleWidth
## Table:sortData(columnIndex, fn)
Sorts the table data by column
### Parameters
* `columnIndex` `number` The index of the column to sort by
* `fn` `function` ? Optional custom sorting function
### Returns
* `Table` `self` The Table instance
## Table:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Table:mouse_scroll(direction, x, y)
### Parameters
* `direction` `number` The scroll direction (-1 up, 1 down)
* `x` `number` The x position of the scroll
* `y` `number` The y position of the scroll
### Returns
* `boolean` `handled` Whether the event was handled
## Table:render()

View File

@@ -1,57 +1,125 @@
# TextBox : VisualElement # TextBox
A multi-line text editor component with cursor support and text manipulation features _A multi-line text editor component with cursor support and text manipulation features_
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|lines|table|{}|Array of text lines |lines|table|{}|Array of text lines|
|cursorX|number|1|Cursor X position |cursorX|number|1|Cursor X position|
|cursorY|number|1|Cursor Y position (line number) |cursorY|number|1|Cursor Y position (line number)|
|scrollX|number|0|Horizontal scroll offset |scrollX|number|0|Horizontal scroll offset|
|scrollY|number|0|Vertical scroll offset |scrollY|number|0|Vertical scroll offset|
|editable|boolean|true|Whether text can be edited |editable|boolean|true|Whether text can be edited|
|syntaxPatterns|table|{}|Syntax highlighting patterns |syntaxPatterns|table|{}|Syntax highlighting patterns|
|cursorColor|number|nil|Color of the cursor |cursorColor|number|nil|Color of the cursor|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[TextBox:addSyntaxPattern](#textbox-addsyntaxpattern)|TextBox|Adds a new syntax highlighting pattern |[TextBox.new](#textbox-new)|TextBox|Creates a new TextBox instance|
|[TextBox:getText](#textbox-gettext)|string|Gets the text of the TextBox |[TextBox:init](#textbox-init-props-basalt)|TextBox|Initializes the TextBox instance|
|[TextBox:setText](#textbox-settext)|TextBox|Sets the text of the TextBox |[TextBox:addSyntaxPattern](#textbox-addsyntaxpattern-pattern-color)|TextBox|Adds a new syntax highlighting pattern|
|[TextBox:updateViewport](#textbox-updateviewport)|TextBox|Updates the viewport to keep the cursor in view |[TextBox:removeSyntaxPattern](#textbox-removesyntaxpattern-index)|TextBox|Removes a syntax pattern by index (1-based)|
|[TextBox:clearSyntaxPatterns](#textbox-clearsyntaxpatterns)|TextBox|Clears all syntax highlighting patterns|
|[TextBox:updateViewport](#textbox-updateviewport)|TextBox|Updates the viewport to keep the cursor in view|
|[TextBox:char](#textbox-char-char)|boolean|Handles character input|
|[TextBox:key](#textbox-key-key)|boolean|Handles key events|
|[TextBox:mouse_scroll](#textbox-mouse-scroll-direction-x-y)|boolean|Handles mouse scroll events|
|[TextBox:mouse_click](#textbox-mouse-click-button-x-y)|boolean|Handles mouse click events|
|[TextBox:paste](#textbox-paste)|-|Handles paste events|
|[TextBox:setText](#textbox-settext-text)|TextBox|Sets the text of the TextBox|
|[TextBox:getText](#textbox-gettext)|string|Gets the text of the TextBox|
|[TextBox:render](#textbox-render)|-|Renders the TextBox with syntax highlighting|
## TextBox.new()
## Protected Functions Creates a new TextBox instance
|Method|Returns|Description| ### Returns
|---|---|---| * `TextBox` `self` The newly created TextBox instance
|TextBox:char|boolean|Handles character input
|TextBox:init|TextBox|Initializes the TextBox instance ## TextBox:init(props, basalt)
|TextBox:key|boolean|Handles key events ### Parameters
|TextBox:mouse_click|boolean|Handles mouse click events * `props` `table` The properties to initialize the element with
|TextBox:mouse_scroll|boolean|Handles mouse scroll events * `basalt` `table` The basalt instance
|TextBox:render|-|Renders the TextBox with syntax highlighting
### Returns
* `TextBox` `self` The initialized instance
## TextBox:addSyntaxPattern(pattern, color) ## TextBox:addSyntaxPattern(pattern, color)
Adds a new syntax highlighting pattern Adds a new syntax highlighting pattern
### Parameters ### Parameters
* `pattern` `string` The regex pattern to match * `pattern` `string` The regex pattern to match
* `color` `colors` The color to apply * `color` `number` The color to apply
### Returns ### Returns
* `TextBox` `self` The TextBox instance * `TextBox` `self` The TextBox instance
## TextBox:getText() ## TextBox:removeSyntaxPattern(index)
Gets the text of the TextBox
Removes a syntax pattern by index (1-based)
### Parameters
* `index` `number` The index of the pattern to remove
### Returns ### Returns
* `string` `text` The text of the TextBox * `TextBox` self
## TextBox:clearSyntaxPatterns()
Clears all syntax highlighting patterns
### Returns
* `TextBox` self
## TextBox:updateViewport()
Updates the viewport to keep the cursor in view
### Returns
* `TextBox` `self` The TextBox instance
## TextBox:char(char)
### Parameters
* `char` `string` The character that was typed
### Returns
* `boolean` `handled` Whether the event was handled
## TextBox:key(key)
### Parameters
* `key` `number` The key that was pressed
### Returns
* `boolean` `handled` Whether the event was handled
## TextBox:mouse_scroll(direction, x, y)
### Parameters
* `direction` `number` The scroll direction
* `x` `number` The x position of the scroll
* `y` `number` The y position of the scroll
### Returns
* `boolean` `handled` Whether the event was handled
## TextBox:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## TextBox:paste()
## TextBox:setText(text) ## TextBox:setText(text)
Sets the text of the TextBox Sets the text of the TextBox
### Parameters ### Parameters
@@ -60,10 +128,11 @@ Sets the text of the TextBox
### Returns ### Returns
* `TextBox` `self` The TextBox instance * `TextBox` `self` The TextBox instance
## TextBox:updateViewport() ## TextBox:getText()
Updates the viewport to keep the cursor in view
Gets the text of the TextBox
### Returns ### Returns
* `TextBox` `self` The TextBox instance * `string` `text` The text of the TextBox
## TextBox:render()

View File

@@ -17,21 +17,21 @@ Extends: `BaseElement`
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Timer.new](#timer-new)|table|Creates a new Timer instance| |[Timer.new](#timer-new)|table|Creates a new Timer instance|
|[Timer:Timer](#timer-timer-props-basalt)|-|Initializes the Timer instance| |[Timer:init](#timer-init-props-basalt)|-|Initializes the Timer instance|
|[Timer:Timer](#timer-timer-self)|Timer|Starts the timer| |[Timer:start](#timer-start-self)|Timer|Starts the timer|
|[Timer:Timer](#timer-timer-self)|Timer|Stops the timer| |[Timer:stop](#timer-stop-self)|Timer|Stops the timer|
|[Timer:Timer](#timer-timer)|-|Dispatches events to the Timer instance| |[Timer:dispatchEvent](#timer-dispatchevent)|-|Dispatches events to the Timer instance|
## Timer.new() ## Timer.new()
### Returns ### Returns
* `table` `self` The created instance * `table` `self` The created instance
## Timer:Timer(props, basalt) ## Timer:init(props, basalt)
### Parameters ### Parameters
* `props` `table` The properties to initialize the element with * `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance * `basalt` `table` The basalt instance
## Timer:Timer(self) ## Timer:start(self)
Starts the timer with the specified interval. Starts the timer with the specified interval.
@@ -41,7 +41,7 @@ Starts the timer with the specified interval.
### Returns ### Returns
* `Timer` `self` The Timer instance * `Timer` `self` The Timer instance
## Timer:Timer(self) ## Timer:stop(self)
Stops the timer if it is currently running. Stops the timer if it is currently running.
@@ -51,4 +51,4 @@ Stops the timer if it is currently running.
### Returns ### Returns
* `Timer` `self` The Timer instance * `Timer` `self` The Timer instance
## Timer:Timer() ## Timer:dispatchEvent()

View File

@@ -1,49 +1,55 @@
# Tree : VisualElement # Tree
This is the tree class. It provides a hierarchical view of nodes that can be expanded and collapsed, _This is the tree class. It provides a hierarchical view of nodes that can be expanded and collapsed,
with support for selection and scrolling. with support for selection and scrolling._
Extends: `VisualElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|nodes|table|{}|The tree structure containing node objects with {text, children} properties |nodes|table|{}|The tree structure containing node objects with {text, children} properties|
|selectedNode|table?|nil|Currently selected node |expandedNodes|table|{}|Table of nodes that are currently expanded|
|expandedNodes|table|{}|Table of nodes that are currently expanded |scrollOffset|number|0|Current vertical scroll position|
|scrollOffset|number|0|Current vertical scroll position |horizontalOffset|number|0|Current horizontal scroll position|
|horizontalOffset|number|0|Current horizontal scroll position |nodeColor|color|white|Color of unselected nodes|
|nodeColor|color|white|Color of unselected nodes |selectedColor|color|lightBlue|Background color of selected node|
|selectedColor|color|lightBlue|Background color of selected node
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Tree:collapseNode](#tree-collapsenode)|Tree|Collapses a node to hide its children |[Tree.new](#tree-new)|Tree|Creates a new Tree instance|
|[Tree:expandNode](#tree-expandnode)|Tree|Expands a node to show its children |[Tree:init](#tree-init-props-basalt)|Tree|Initializes the Tree instance|
|[Tree:getNodeSize](#tree-getnodesize)|number|Gets the size of the tree |[Tree:expandNode](#tree-expandnode-node)|Tree|Expands a node to show its children|
|[Tree:onSelect](#tree-onselect)|Tree|Registers a callback for when a node is selected |[Tree:collapseNode](#tree-collapsenode-node)|Tree|Collapses a node to hide its children|
|[Tree:toggleNode](#tree-togglenode)|Tree|Toggles between expanded and collapsed state |[Tree:toggleNode](#tree-togglenode-node)|Tree|Toggles between expanded and collapsed state|
|[Tree:mouse_click](#tree-mouse-click-button-x-y)|boolean|Handles mouse click events for node selection and expansion|
|[Tree:onSelect](#tree-onselect-callback)|Tree|Registers a callback for when a node is selected|
|[Tree:mouse_scroll](#tree-mouse-scroll-direction-x-y)|boolean|Handles mouse scroll events for vertical scrolling|
|[Tree:getNodeSize](#tree-getnodesize)|number, number|Gets the size of the tree|
|[Tree:render](#tree-render)|-|Renders the tree with nodes, selection and scrolling|
## Tree.new()
## Protected Functions Creates a new Tree instance
|Method|Returns|Description|
|---|---|---|
|Tree:init|Tree|Initializes the Tree instance
|Tree:mouse_click|boolean|Handles mouse click events for node selection and expansion
|Tree:mouse_scroll|boolean|Handles mouse scroll events for vertical scrolling
|Tree:render|-|Renders the tree with nodes, selection and scrolling
## Tree:collapseNode(node)
Collapses a node
### Parameters
* `node` `table` The node to collapse
### Returns ### Returns
* `Tree` `self` The Tree instance * `Tree` `self` The newly created Tree instance
## Tree:init(props, basalt)
Initializes the Tree instance
### Parameters
* `props` `table` The properties to initialize the element with
* `basalt` `table` The basalt instance
### Returns
* `Tree` `self` The initialized instance
## Tree:expandNode(node) ## Tree:expandNode(node)
Expands a node Expands a node
### Parameters ### Parameters
@@ -52,23 +58,18 @@ Expands a node
### Returns ### Returns
* `Tree` `self` The Tree instance * `Tree` `self` The Tree instance
## Tree:getNodeSize() ## Tree:collapseNode(node)
Gets the size of the tree
### Returns Collapses a node
* `number` `width` The width of the tree
* `number` `height` The height of the tree
## Tree:onSelect(callback)
Registers a callback for when a node is selected
### Parameters ### Parameters
* `callback` `function` The callback function * `node` `table` The node to collapse
### Returns ### Returns
* `Tree` `self` The Tree instance * `Tree` `self` The Tree instance
## Tree:toggleNode(node) ## Tree:toggleNode(node)
Toggles a node's expanded state Toggles a node's expanded state
### Parameters ### Parameters
@@ -77,4 +78,43 @@ Toggles a node's expanded state
### Returns ### Returns
* `Tree` `self` The Tree instance * `Tree` `self` The Tree instance
## Tree:mouse_click(button, x, y)
Handles mouse click events
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `handled` Whether the event was handled
## Tree:onSelect(callback)
Registers a callback for when a node is selected
### Parameters
* `callback` `function` The callback function
### Returns
* `Tree` `self` The Tree instance
## Tree:mouse_scroll(direction, x, y)
### Parameters
* `direction` `number` The scroll direction (1 for up, -1 for down)
* `x` `number` The x position of the scroll
* `y` `number` The y position of the scroll
### Returns
* `boolean` `handled` Whether the event was handled
## Tree:getNodeSize()
Gets the size of the tree
### Returns
* `number` `width` The width of the tree
* `number` `height` The height of the tree
## Tree:render()

View File

@@ -1,102 +1,193 @@
# VisualElement : BaseElement # VisualElement
This is the visual element class. It serves as the base class for all visual UI elements _This is the visual element class. It serves as the base class for all visual UI elements
and provides core functionality for positioning, sizing, colors, and rendering. and provides core functionality for positioning, sizing, colors, and rendering._
Extends: `BaseElement`
## Properties ## Properties
|Property|Type|Default|Description| |Property|Type|Default|Description|
|---|---|---|---| |---|---|---|---|
|x|number|1|The horizontal position relative to parent |x|number|1|The horizontal position relative to parent|
|y|number|1|The vertical position relative to parent |y|number|1|The vertical position relative to parent|
|z|number|1|The z-index for layering elements |z|number|1|The z-index for layering elements|
|width|number|1|The width of the element |width|number|1|The width of the element|
|height|number|1|The height of the element |height|number|1|The height of the element|
|background|color|black|The background color |background|color|black|The background color|
|foreground|color|white|The text/foreground color |foreground|color|white|The text/foreground color|
|clicked|boolean|false|Whether the element is currently clicked |clicked|boolean|false|Whether the element is currently clicked|
|hover|boolean|false|Whether the mouse is currently hover over the element (Craftos-PC only) |hover|boolean|false|Whether the mouse is currently hover over the element (Craftos-PC only)|
|backgroundEnabled|boolean|true|Whether to render the background |backgroundEnabled|boolean|true|Whether to render the background|
|focused|boolean|false|Whether the element has input focus |focused|boolean|false|Whether the element has input focus|
|visible|boolean|true|Whether the element is visible |visible|boolean|true|Whether the element is visible|
|ignoreOffset|boolean|false|Whether to ignore the parent's offset |ignoreOffset|boolean|false|Whether to ignore the parent's offset|
## Combined Properties
|Name|Properties|Description|
|---|---|---|
|position|`x number, y number`|Combined x, y position|
|size|`width number, height number`|Combined width, height|
|color|`foreground number, background number`|Combined foreground, background colors|
## Events ## Events
|Event|Parameters|Description| |Event|Parameters|Description|
|---|---|---| |---|---|---|
|onClick|`button string, x number, y number`|Fired on mouse click| |onClick|`button string, x number, y number`|Fired on mouse click|
|onMouseUp|`button, x, y`|Fired on mouse button release|
|onRelease|`button, x, y`|Fired when mouse leaves while clicked|
|onDrag|`button, x, y`|Fired when mouse moves while clicked|
|onScroll|`direction, x, y`|Fired on mouse scroll|
|onEnter|`-`|Fired when mouse enters element|
|onLeave|`-`|Fired when mouse leaves element|
|onFocus|`-`|Fired when element receives focus|
|onBlur|`-`|Fired when element loses focus|
|onKey|`key`|Fired on key press|
|onKeyUp|`key`|Fired on key release|
|onChar|`char`|Fired on character input|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[VisualElement:calculatePosition](#visualelement-calculateposition)|number|Calculates the position of the element |[VisualElement.new](#visualelement-new)|VisualElement|Creates a new visual element|
|[VisualElement:drawBg](#visualelement-drawbg)|-| |[VisualElement:init](#visualelement-init-props-basalt)|-|Initializes a new visual element with properties|
|[VisualElement:drawFg](#visualelement-drawfg)|-| |[VisualElement:multiBlit](#visualelement-multiblit-x-y-width-height-text-fg-bg)|-|Multi-character drawing with colors|
|[VisualElement:drawText](#visualelement-drawtext)|-| |[VisualElement:textFg](#visualelement-textfg-x-y-text-fg)|-|Draws text with foreground color|
|[VisualElement:getAbsolutePosition](#visualelement-getabsoluteposition)|number|Returns the absolute position of the element |[VisualElement:textBg](#visualelement-textbg-x-y-text-bg)|-|Draws text with background color|
|[VisualElement:getRelativePosition](#visualelement-getrelativeposition)|number|Returns the relative position of the element |[VisualElement:blit](#visualelement-blit-x-y-text-fg-bg)|-|Draws text with both colors|
|[VisualElement:isInBounds](#visualelement-isinbounds)|boolean|Checks if point is within bounds |[VisualElement:isInBounds](#visualelement-isinbounds-x-y)|boolean|Checks if point is within bounds|
|[VisualElement:prioritize](#visualelement-prioritize)|VisualElement|Prioritizes the element by moving it to the top of its parent's children |[VisualElement:mouse_click](#visualelement-mouse-click-button-x-y)|boolean|Handles a mouse click event|
|[VisualElement:mouse_up](#visualelement-mouse-up-button-x-y)|boolean|Handles a mouse up event|
|[VisualElement:mouse_release](#visualelement-mouse-release-button-x-y)|-|Handles a mouse release event|
|[VisualElement:mouse_move](#visualelement-mouse-move---x-y)|boolean|Handles a mouse move event|
|[VisualElement:mouse_scroll](#visualelement-mouse-scroll-direction-x-y)|boolean|Handles a mouse scroll event|
|[VisualElement:mouse_drag](#visualelement-mouse-drag-button-x-y)|boolean|Handles a mouse drag event|
|[VisualElement:focus](#visualelement-focus)|-|Handles a focus event|
|[VisualElement:blur](#visualelement-blur)|-|Handles a blur event|
|[VisualElement:key](#visualelement-key-key)|-|Handles a key event|
|[VisualElement:key_up](#visualelement-key-up-key)|-|Handles a key up event|
|[VisualElement:char](#visualelement-char-char)|-|Handles a character event|
|[VisualElement:calculatePosition](#visualelement-calculateposition)|number, number|Calculates the position of the element|
|[VisualElement:getAbsolutePosition](#visualelement-getabsoluteposition-x-y)|number, number|Returns the absolute position of the element|
|[VisualElement:getRelativePosition](#visualelement-getrelativeposition-x-y)|number, number|Returns the relative position of the element|
|[VisualElement:setCursor](#visualelement-setcursor-x-y-blink-color)|VisualElement|Sets the cursor position|
|[VisualElement:prioritize](#visualelement-prioritize)|VisualElement|Prioritizes the element by moving it to the top of its parent's children|
|[VisualElement:render](#visualelement-render)|-|Renders the element|
|[VisualElement:postRender](#visualelement-postrender)|-|Post-rendering function for the element|
## VisualElement.new()
## Protected Functions Creates a new VisualElement instance
|Method|Returns|Description| ### Returns
|---|---|---| * `VisualElement` `object` The newly created VisualElement instance
|VisualElement:blit|-|Draws text with both colors
|VisualElement:blur|-|Handles a blur event ## VisualElement:init(props, basalt)
|VisualElement:char|-|Handles a character event ### Parameters
|VisualElement:focus|-|Handles a focus event * `props` `table` The properties to initialize the element with
|VisualElement:init|-|Initializes a new visual element with properties * `basalt` `table` The basalt instance
|VisualElement:key|-|Handles a key event
|VisualElement:key_up|-|Handles a key up event ## VisualElement:multiBlit(x, y, width, height, text, fg, bg)
|VisualElement:mouse_click|boolean|Handles a mouse click event ### Parameters
|VisualElement:mouse_drag|boolean|Handles a mouse drag event * `x` `number` The x position to draw
|VisualElement:mouse_move|boolean|Handles a mouse move event * `y` `number` The y position to draw
|VisualElement:mouse_release|-|Handles a mouse release event * `width` `number` The width of the area to draw
|VisualElement:mouse_scroll|boolean|Handles a mouse scroll event * `height` `number` The height of the area to draw
|VisualElement:mouse_up|boolean|Handles a mouse up event * `text` `string` The text to draw
|VisualElement:multiBlit|-|Multi-character drawing with colors * `fg` `string` The foreground color
|VisualElement:postRender|-|Post-rendering function for the element * `bg` `string` The background color
|VisualElement:render|-|Renders the element
|VisualElement:setCursor|VisualElement|Sets the cursor position ## VisualElement:textFg(x, y, text, fg)
|VisualElement:textBg|-|Draws text with background color ### Parameters
|VisualElement:textFg|-|Draws text with foreground color * `x` `number` The x position to draw
* `y` `number` The y position to draw
* `text` `string` The text char to draw
* `fg` `color` The foreground color
## VisualElement:textBg(x, y, text, bg)
### Parameters
* `x` `number` The x position to draw
* `y` `number` The y position to draw
* `text` `string` The text char to draw
* `bg` `color` The background color
## VisualElement:blit(x, y, text, fg, bg)
### Parameters
* `x` `number` The x position to draw
* `y` `number` The y position to draw
* `text` `string` The text char to draw
* `fg` `string` The foreground color
* `bg` `string` The background color
## VisualElement:isInBounds(x, y)
Checks if the specified coordinates are within the bounds of the element
### Parameters
* `x` `number` The x position to check
* `y` `number` The y position to check
### Returns
* `boolean` `isInBounds` Whether the coordinates are within the bounds of the element
## VisualElement:mouse_click(button, x, y)
### Parameters
* `button` `number` The button that was clicked
* `x` `number` The x position of the click
* `y` `number` The y position of the click
### Returns
* `boolean` `clicked` Whether the element was clicked
## VisualElement:mouse_up(button, x, y)
### Parameters
* `button` `number` The button that was released
* `x` `number` The x position of the release
* `y` `number` The y position of the release
### Returns
* `boolean` `release` Whether the element was released on the element
## VisualElement:mouse_release(button, x, y)
### Parameters
* `button` `number` The button that was released
* `x` `number` The x position of the release
* `y` `number` The y position of the release
## VisualElement:mouse_move(_, x, y)
### Parameters
* `_` `number` unknown
* `x` `number` The x position of the mouse
* `y` `number` The y position of the mouse
### Returns
* `boolean` `hover` Whether the mouse has moved over the element
## VisualElement:mouse_scroll(direction, x, y)
### Parameters
* `direction` `number` The scroll direction
* `x` `number` The x position of the scroll
* `y` `number` The y position of the scroll
### Returns
* `boolean` `scroll` Whether the element was scrolled
## VisualElement:mouse_drag(button, x, y)
### Parameters
* `button` `number` The button that was clicked while dragging
* `x` `number` The x position of the drag
* `y` `number` The y position of the drag
### Returns
* `boolean` `drag` Whether the element was dragged
## VisualElement:focus()
## VisualElement:blur()
## VisualElement:key(key)
### Parameters
* `key` `number` The key that was pressed
## VisualElement:key_up(key)
### Parameters
* `key` `number` The key that was released
## VisualElement:char(char)
### Parameters
* `char` `string` The character that was pressed
## VisualElement:calculatePosition() ## VisualElement:calculatePosition()
Calculates the position of the element relative to its parent Calculates the position of the element relative to its parent
### Returns ### Returns
* `number` `x` The x position * `number` `x` The x position
* `number` `y` The y position * `number` `y` The y position
## VisualElement:drawBg()
## VisualElement:drawFg()
## VisualElement:drawText()
## VisualElement:getAbsolutePosition(x?, y?) ## VisualElement:getAbsolutePosition(x?, y?)
Returns the absolute position of the element or the given coordinates. Returns the absolute position of the element or the given coordinates.
### Parameters ### Parameters
@@ -108,6 +199,7 @@ Returns the absolute position of the element or the given coordinates.
* `number` `y` The absolute y position * `number` `y` The absolute y position
## VisualElement:getRelativePosition(x?, y?) ## VisualElement:getRelativePosition(x?, y?)
Returns the relative position of the element or the given coordinates. Returns the relative position of the element or the given coordinates.
### Parameters ### Parameters
@@ -118,20 +210,22 @@ Returns the relative position of the element or the given coordinates.
* `number` `x` The relative x position * `number` `x` The relative x position
* `number` `y` The relative y position * `number` `y` The relative y position
## VisualElement:isInBounds(x, y) ## VisualElement:setCursor(x, y, blink, color)
Checks if the specified coordinates are within the bounds of the element
### Parameters ### Parameters
* `x` `number` The x position to check * `x` `number` The x position of the cursor
* `y` `number` The y position to check * `y` `number` The y position of the cursor
* `blink` `boolean` Whether the cursor should blink
* `color` `number` The color of the cursor
### Returns ### Returns
* `boolean` `isInBounds` Whether the coordinates are within the bounds of the element * `VisualElement` `self` The VisualElement instance
## VisualElement:prioritize() ## VisualElement:prioritize()
This function is used to prioritize the element by moving it to the top of its parent's children. It removes the element from its parent and adds it back, effectively changing its order. This function is used to prioritize the element by moving it to the top of its parent's children. It removes the element from its parent and adds it back, effectively changing its order.
### Returns ### Returns
* `VisualElement` `self` The VisualElement instance * `VisualElement` `self` The VisualElement instance
## VisualElement:render()
## VisualElement:postRender()

View File

@@ -1,29 +1,20 @@
# ErrorHandler # ErrorHandler
This is Basalt's error handler. All the errors are handled by this module. _This is Basalt's error handler. All the errors are handled by this module._
## Fields
|Field|Type|Description|
|---|---|---|
|tracebackEnabled|`boolean`|If the error handler should print a stack trace|
|header|`string`|The header of the error message|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[errorHandler.error](#errorhandler-error)|-| |[ErrorHandler.error](#errorhandler-error-errmsg)|-|Handles an error|
## ErrorHandler.error(errMsg)
## errorHandler.error(errMsg)
Handles an error Handles an error
### Parameters ### Parameters
* `errMsg` `string` The error message * `errMsg` `string` The error message
### Usage ### Usage
```lua ```lua
errorHandler.error("An error occurred") errorHandler.error("An error occurred")
``` ```

View File

@@ -0,0 +1 @@
!! EMPTY MARKDOWN GENERATED !!

View File

@@ -0,0 +1 @@
!! EMPTY MARKDOWN GENERATED !!

View File

@@ -0,0 +1 @@
!! EMPTY MARKDOWN GENERATED !!

View File

@@ -0,0 +1 @@
!! EMPTY MARKDOWN GENERATED !!

View File

@@ -1,76 +1,57 @@
# Log # Log
Logger module for Basalt. Logs messages to the console and optionally to a file. _Logger module for Basalt. Logs messages to the console and optionally to a file._
## Fields
|Field|Type|Description|
|---|---|---|
|_logs|`table`|The complete log history|
|_enabled|`boolean`|If the logger is enabled|
|_logToFile|`boolean`|If the logger should log to a file|
|_logFile|`string`|The file to log to|
|LEVEL|`table`|The log levels|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Log.debug](#log-debug)|-|Sends a debug message |[Log.setLogToFile](#log-setlogtofile)|-|Sets if the logger should log to a file|
|[Log.error](#log-error)|-|Sends an error message |[Log.setEnabled](#log-setenabled)|-|Sets if the logger should log|
|[Log.info](#log-info)|-|Sends an info message |[Log.debug](#log-debug)|-|Sends a debug message|
|[Log.setEnabled](#log-setenabled)|-|Sets if the logger should log |[Log.info](#log-info)|-|Sends an info message|
|[Log.setLogToFile](#log-setlogtofile)|-|Sets if the logger should log to a file |[Log.warn](#log-warn)|-|Sends a warning message|
|[Log.warn](#log-warn)|-|Sends a warning message |[Log.error](#log-error)|-|Sends an error message|
## Log.setLogToFile()
Sets if the logger should log to a file.
## Log.setEnabled()
Sets if the logger should log
## Log.debug()
## Log.debug(...)
Sends a debug message to the logger. Sends a debug message to the logger.
### Parameters
* `...` *(vararg)* `string` The message to log
### Usage ### Usage
```lua ```lua
Log.debug("This is a debug message") Log.debug("This is a debug message")
``` ```
## Log.error(...) ## Log.info()
Sends an error message to the logger.
### Parameters
* `...` *(vararg)* `string` The message to log
### Usage
```lua
Log.error("This is an error message")
```
## Log.info(...)
Sends an info message to the logger. Sends an info message to the logger.
### Parameters
* `...` *(vararg)* `string` The message to log
### Usage ### Usage
```lua ```lua
Log.info("This is an info message") Log.info("This is an info message")
``` ```
## Log.setEnabled() ## Log.warn()
Sets if the logger should log
## Log.setLogToFile()
Sets if the logger should log to a file.
## Log.warn(...)
Sends a warning message to the logger. Sends a warning message to the logger.
### Parameters
* `...` *(vararg)* `string` The message to log
### Usage ### Usage
```lua ```lua
Log.warn("This is a warning message") Log.warn("This is a warning message")
``` ```
## Log.error()
Sends an error message to the logger.
### Usage
```lua
Log.error("This is an error message")
```

View File

@@ -1,50 +1,35 @@
# basalt # basalt
This is the UI Manager and the starting point for your project. The following functions allow you to influence the default behavior of Basalt. _This is the UI Manager and the starting point for your project. The following functions allow you to influence the default behavior of Basalt.
Before you can access Basalt, you need to add the following code on top of your file: Before you can access Basalt, you need to add the following code on top of your file:
What this code does is it loads basalt into the project, and you can access it by using the variable defined as "basalt"._
### Usage
```lua
local basalt = require("basalt")
```
What this code does is it loads basalt into the project, and you can access it by using the variable defined as "basalt".
## Fields
|Field|Type|Description|
|---|---|---|
|traceback|`boolean`|Whether to show a traceback on errors|
|_events|`table`|A table of events and their callbacks|
|_schedule|`function[]`|A table of scheduled functions|
|_plugins|`table`|A table of plugins|
|isRunning|`boolean`|Whether the Basalt runtime is active|
|LOGGER|`Log`|The logger instance|
|path|`string`|The path to the Basalt library|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[basalt.create](#basalt-create)|table|Creates a new UI element |[basalt.create](#basalt-create-type-properties)|table|Creates a new UI element|
|[basalt.createFrame](#basalt-createframe)|BaseFrame|Creates a new BaseFrame |[basalt.createFrame](#basalt-createframe)|BaseFrame|Creates a new BaseFrame|
|[basalt.getAPI](#basalt-getapi)|table|Returns a Plugin API |[basalt.getElementManager](#basalt-getelementmanager)|table|Returns the element manager|
|[basalt.getActiveFrame](#basalt-getactiveframe)|BaseFrame?|Returns the active frame |[basalt.getErrorManager](#basalt-geterrormanager)|table|Returns the error manager|
|[basalt.getElementClass](#basalt-getelementclass)|table|Returns an element class |[basalt.getMainFrame](#basalt-getmainframe)|BaseFrame|Gets or creates the main frame|
|[basalt.getElementManager](#basalt-getelementmanager)|table|Returns the element manager |[basalt.setActiveFrame](#basalt-setactiveframe-frame-setactive)|-|Sets the active frame|
|[basalt.getErrorManager](#basalt-geterrormanager)|table|Returns the error manager |[basalt.getActiveFrame](#basalt-getactiveframe-t)|BaseFrame|Returns the active frame|
|[basalt.getFocus](#basalt-getfocus)|BaseFrame?|Returns the focused frame |[basalt.setFocus](#basalt-setfocus-frame)|-|Sets a frame as focused|
|[basalt.getMainFrame](#basalt-getmainframe)|BaseFrame|Gets or creates the main frame |[basalt.getFocus](#basalt-getfocus)|BaseFrame|Returns the focused frame|
|[basalt.removeSchedule](#basalt-removeschedule)|boolean|Removes a scheduled update |[basalt.schedule](#basalt-schedule-func)|thread|Schedules a function to run in a coroutine|
|[basalt.run](#basalt-run)|-|Starts the Basalt runtime |[basalt.removeSchedule](#basalt-removeschedule-func)|boolean|Removes a scheduled update|
|[basalt.schedule](#basalt-schedule)|thread|Schedules a function to run in a coroutine |[basalt.update](#basalt-update)|-|Runs basalt once|
|[basalt.setActiveFrame](#basalt-setactiveframe)|-|Sets the active frame |[basalt.stop](#basalt-stop)|-|Stops the Basalt runtime|
|[basalt.setFocus](#basalt-setfocus)|-|Sets a frame as focused |[basalt.run](#basalt-run-isactive)|-|Starts the Basalt runtime|
|[basalt.stop](#basalt-stop)|-|Stops the Basalt runtime |[basalt.getElementClass](#basalt-getelementclass-name)|table|Returns an element class|
|[basalt.update](#basalt-update)|-|Runs basalt once |[basalt.getAPI](#basalt-getapi-name)|table|Returns a Plugin API|
|[basalt.onEvent](#basalt-onevent-eventname-callback)|-|Registers an event callback|
|[basalt.removeEvent](#basalt-removeevent-eventname-callback)|boolean|Removes an event callback|
|[basalt.triggerEvent](#basalt-triggerevent-eventname)|-|Triggers a custom event|
## basalt.create(type, properties?) ## basalt.create(type, properties?)
Creates and returns a new UI element of the specified type. Creates and returns a new UI element of the specified type.
### Parameters ### Parameters
@@ -55,83 +40,72 @@ Creates and returns a new UI element of the specified type.
* `table` `element` The created element instance * `table` `element` The created element instance
### Usage ### Usage
```lua ```lua
local button = basalt.create("Button") local button = basalt.create("Button")
``` ```
## basalt.createFrame() ## basalt.createFrame()
Creates and returns a new BaseFrame Creates and returns a new BaseFrame
### Returns ### Returns
* `BaseFrame` `BaseFrame` The created frame instance * `BaseFrame` `BaseFrame` The created frame instance
## basalt.getAPI(name)
Returns a Plugin API
### Parameters
* `name` `string` The name of the plugin
### Returns
* `table` `Plugin` The plugin API
## basalt.getActiveFrame(t?)
Returns the active frame
### Parameters
* `t` *(optional)* `term` The term to get the active frame for (default: current term)
### Returns
* `BaseFrame?` `BaseFrame` The frame to set as active
## basalt.getElementClass(name)
Returns an element's class without creating a instance
### Parameters
* `name` `string` The name of the element
### Returns
* `table` `Element` The element class
## basalt.getElementManager() ## basalt.getElementManager()
Returns the element manager instance Returns the element manager instance
### Returns ### Returns
* `table` `ElementManager` The element manager * `table` `ElementManager` The element manager
## basalt.getErrorManager() ## basalt.getErrorManager()
Returns the error manager instance Returns the error manager instance
### Returns ### Returns
* `table` `ErrorManager` The error manager * `table` `ErrorManager` The error manager
## basalt.getFocus()
Returns the focused frame
### Returns
* `BaseFrame?` `BaseFrame` The focused frame
## basalt.getMainFrame() ## basalt.getMainFrame()
Gets or creates the main frame Gets or creates the main frame
### Returns ### Returns
* `BaseFrame` `BaseFrame` The main frame instance * `BaseFrame` `BaseFrame` The main frame instance
## basalt.removeSchedule(func) ## basalt.setActiveFrame(frame, setActive?)
Removes a scheduled update
Sets the active frame
### Parameters ### Parameters
* `func` `thread` The scheduled function to remove * `frame` `BaseFrame` The frame to set as active
* `setActive` *(optional)* `boolean` Whether to set the frame as active (default: true)
## basalt.getActiveFrame(t?)
Returns the active frame
### Parameters
* `t` *(optional)* `term` The term to get the active frame for (default: current term)
### Returns ### Returns
* `boolean` `success` Whether the scheduled function was removed * `BaseFrame` `The` frame to set as active
## basalt.run(isActive?) ## basalt.setFocus(frame)
Starts the Basalt runtime
Sets a frame as focused
### Parameters ### Parameters
* `isActive` *(optional)* `boolean` Whether to start active (default: true) * `frame` `BaseFrame` The frame to set as focused
## basalt.getFocus()
Returns the focused frame
### Returns
* `BaseFrame` `The` focused frame
## basalt.schedule(func) ## basalt.schedule(func)
Schedules a function to run in a coroutine Schedules a function to run in a coroutine
### Parameters ### Parameters
@@ -140,26 +114,83 @@ Schedules a function to run in a coroutine
### Returns ### Returns
* `thread` `func` The scheduled function * `thread` `func` The scheduled function
## basalt.setActiveFrame(frame, setActive?) ## basalt.removeSchedule(func)
Sets the active frame
Removes a scheduled update
### Parameters ### Parameters
* `frame` `BaseFrame` The frame to set as active * `func` `thread` The scheduled function to remove
* `setActive` *(optional)* `boolean` Whether to set the frame as active (default: true)
## basalt.setFocus(frame) ### Returns
Sets a frame as focused * `boolean` `success` Whether the scheduled function was removed
### Parameters ## basalt.update()
* `frame` `BaseFrame` The frame to set as focused
## basalt.stop()
Stops the Basalt runtime
## basalt.update(...)
Runs basalt once, can be used to update the UI manually, but you have to feed it the events Runs basalt once, can be used to update the UI manually, but you have to feed it the events
## basalt.stop()
Stops the Basalt runtime
## basalt.run(isActive?)
Starts the Basalt runtime
### Parameters ### Parameters
* `...` *(vararg)* `any` The event to run with * `isActive` *(optional)* `boolean` Whether to start active (default: true)
## basalt.getElementClass(name)
Returns an element's class without creating a instance
### Parameters
* `name` `string` The name of the element
### Returns
* `table` `Element` The element class
## basalt.getAPI(name)
Returns a Plugin API
### Parameters
* `name` `string` The name of the plugin
### Returns
* `table` `Plugin` The plugin API
## basalt.onEvent(eventName, callback)
Registers a callback function for a specific event
### Parameters
* `eventName` `string` The name of the event to listen for (e.g. "mouse_click", "key", "timer")
* `callback` `function` The callback function to execute when the event occurs
### Usage
```lua
basalt.onEvent("mouse_click", function(button, x, y) basalt.debug("Clicked at", x, y) end)
```
## basalt.removeEvent(eventName, callback)
Removes a callback function for a specific event
### Parameters
* `eventName` `string` The name of the event
* `callback` `function` The callback function to remove
### Returns
* `boolean` `success` Whether the callback was found and removed
## basalt.triggerEvent(eventName)
Triggers a custom event and calls all registered callbacks
### Parameters
* `eventName` `string` The name of the event to trigger
### Usage
```lua
basalt.triggerEvent("custom_event", "data1", "data2")
```

View File

@@ -0,0 +1,185 @@
# AnimationInstance
_This is the AnimationInstance class. It represents a single animation instance_
## Functions
|Method|Returns|Description|
|---|---|---|
|[AnimationInstance.new](#animationinstance-new-element-animtype-args-duration-easing)|AnimationInstance|Creates a new animation instance|
|[AnimationInstance:start](#animationinstance-start)|AnimationInstance|Starts the animation|
|[AnimationInstance:update](#animationinstance-update-elapsed)|boolean|Updates the animation|
|[AnimationInstance:complete](#animationinstance-complete)|-|Called when the animation is completed|
## AnimationInstance.new(element, animType, args, duration, easing)
Creates a new AnimationInstance
### Parameters
* `element` `VisualElement` The element to animate
* `animType` `string` The type of animation
* `args` `table` The animation arguments
* `duration` `number` Duration in seconds
* `easing` `string` The easing function name
### Returns
* `AnimationInstance` `The` new animation instance
## AnimationInstance:start()
Starts the animation
### Returns
* `AnimationInstance` `self` The animation instance
## AnimationInstance:update(elapsed)
Updates the animation
### Parameters
* `elapsed` `number` The elapsed time in seconds
### Returns
* `boolean` `Whether` the animation is finished
## AnimationInstance:complete()
Gets called when the animation is completed
# Animation
_This is the animation plugin. It provides a animation system for visual elements
with support for sequences, easing functions, and multiple animation types._
## Functions
|Method|Returns|Description|
|---|---|---|
|[Animation.registerAnimation](#animation-registeranimation-name-handlers)|-|Registers a custom animation type|
|[Animation.registerEasing](#animation-registereasing-name-func)|-|Adds a custom easing function|
|[Animation.new](#animation-new-element)|Animation|Creates a new animation|
|[Animation:sequence](#animation-sequence)|Animation|Creates a new sequence|
|[Animation:onStart](#animation-onstart-callback)|-|Registers a callback for the start event|
|[Animation:onUpdate](#animation-onupdate-callback)|Animation|Registers a callback for the update event|
|[Animation:onComplete](#animation-oncomplete-callback)|Animation|Registers a callback for the complete event|
|[Animation:addAnimation](#animation-addanimation-type-args-duration-easing)|-|Adds a new animation to the sequence|
|[Animation:start](#animation-start)|Animation|Starts the animation|
|[Animation:event](#animation-event-event-timerid)|-|The event handler for the animation|
|[Animation:stop](#animation-stop)|-|Stops the animation|
## Animation.registerAnimation(name, handlers)
Registers a new animation type
### Parameters
* `name` `string` The name of the animation
* `handlers` `table` Table containing start, update and complete handlers
### Usage
```lua
Animation.registerAnimation("fade", {start=function(anim) end, update=function(anim,progress) end})
```
## Animation.registerEasing(name, func)
Registers a new easing function
### Parameters
* `name` `string` The name of the easing function
* `func` `function` The easing function (takes progress 0-1, returns modified progress)
## Animation.new(element)
Creates a new Animation
### Parameters
* `element` `VisualElement` The element to animate
### Returns
* `Animation` `The` new animation
## Animation:sequence()
Creates a new sequence
### Returns
* `Animation` `self` The animation instance
## Animation:onStart(callback)
Registers a callback for the start event
### Parameters
* `callback` `function` The callback function to register
## Animation:onUpdate(callback)
Registers a callback for the update event
### Parameters
* `callback` `function` The callback function to register
### Returns
* `Animation` `self` The animation instance
## Animation:onComplete(callback)
Registers a callback for the complete event
### Parameters
* `callback` `function` The callback function to register
### Returns
* `Animation` `self` The animation instance
## Animation:addAnimation(type, args, duration, easing)
Adds a new animation to the sequence
### Parameters
* `type` `string` The type of animation
* `args` `table` The animation arguments
* `duration` `number` The duration in seconds
* `easing` `string` The easing function name
## Animation:start()
Starts the animation
### Returns
* `Animation` `self` The animation instance
## Animation:event(event, timerId)
The event handler for the animation (listens to timer events)
### Parameters
* `event` `string` The event type
* `timerId` `number` The timer ID
## Animation:stop()
Stops the animation immediately: cancels timers, completes running anim instances and clears the element property
# VisualElement
_Adds additional methods for VisualElement when adding animation plugin_
## Functions
|Method|Returns|Description|
|---|---|---|
|[VisualElement.hooks](#visualelement-hooks)|-||
|[VisualElement.setup](#visualelement-setup)|-||
|[VisualElement.stopAnimation](#visualelement-stopanimation)|-|Convenience to stop animations from the element|
|[VisualElement:animate](#visualelement-animate)|Animation|Creates a new animation|
## VisualElement.hooks()
## VisualElement.setup()
## VisualElement.stopAnimation()
Convenience to stop animations from the element
## VisualElement:animate()
Creates a new Animation Object
### Returns
* `Animation` `animation` The new animation

View File

@@ -1,48 +1,175 @@
# Benchmark # BaseElement
This is the benchmark plugin. It provides performance measurement tools for elements and methods,
with support for hierarchical profiling and detailed statistics. The plugin is meant to be used for very big projects
where performance is critical. It allows you to measure the time taken by specific methods and log the results.
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[API.clear](#api-clear)|-|Removes a benchmark's data |[BaseElement:startProfile](#baseelement-startprofile-methodname)|BaseElement|Starts timing a method call|
|[API.clearAll](#api-clearall)|-|Removes all custom benchmark data |[BaseElement:endProfile](#baseelement-endprofile-methodname)|BaseElement|Ends timing a method call and records statistics|
|[API.getStats](#api-getstats)|table?|Retrieves benchmark statistics |[BaseElement:benchmark](#baseelement-benchmark-methodname)|BaseElement|Enables performance measurement for a method|
|[API.start](#api-start)|-|Starts timing a custom operation |[BaseElement:logBenchmark](#baseelement-logbenchmark-methodname)|BaseElement|Logs benchmark statistics for a method|
|[API.stop](#api-stop)|-|Stops timing and logs results |[BaseElement:stopBenchmark](#baseelement-stopbenchmark-methodname)|BaseElement|Disables performance measurement for a method|
|[BaseElement:getBenchmarkStats](#baseelement-getbenchmarkstats-methodname)|stats|Retrieves benchmark statistics for a method|
## BaseElement:startProfile(methodName)
## API.clear(name) Starts profiling a method
Clears a specific benchmark
### Parameters ### Parameters
* `name` `string` The name of the benchmark to clear * `methodName` `string` The name of the method to profile
## API.clearAll()
Clears all custom benchmarks
## API.getStats(name)
Gets statistics for a benchmark
### Parameters
* `name` `string` The name of the benchmark
### Returns ### Returns
* `table?` `stats` The benchmark statistics or nil * `BaseElement` `self` The element instance
## BaseElement:endProfile(methodName)
Ends profiling a method
### Parameters
* `methodName` `string` The name of the method to stop profiling
### Returns
* `BaseElement` `self` The element instance
## BaseElement:benchmark(methodName)
Enables benchmarking for a method
### Parameters
* `methodName` `string` The name of the method to benchmark
### Returns
* `BaseElement` `self` The element instance
### Usage
```lua
element:benchmark("render")
```
## BaseElement:logBenchmark(methodName)
Logs benchmark statistics for a method
### Parameters
* `methodName` `string` The name of the method to log
### Returns
* `BaseElement` `self` The element instance
## BaseElement:stopBenchmark(methodName)
Stops benchmarking for a method
### Parameters
* `methodName` `string` The name of the method to stop benchmarking
### Returns
* `BaseElement` `self` The element instance
## BaseElement:getBenchmarkStats(methodName)
Gets benchmark statistics for a method
### Parameters
* `methodName` `string` The name of the method to get statistics for
### Returns
* `stats` `The` benchmark statistics or nil
# Container
Extends: `VisualElement`
## Functions
|Method|Returns|Description|
|---|---|---|
|[Container:benchmarkContainer](#container-benchmarkcontainer-methodname)|Container|Recursively enables benchmarking|
|[Container:logContainerBenchmarks](#container-logcontainerbenchmarks-methodname)|Container|Recursively logs benchmark statistics|
|[Container:stopContainerBenchmark](#container-stopcontainerbenchmark-methodname)|Container|Recursively stops benchmarking|
## Container:benchmarkContainer(methodName)
Enables benchmarking for a container and all its children
### Parameters
* `methodName` `string` The method to benchmark
### Returns
* `Container` `self` The container instance
### Usage
```lua
container:benchmarkContainer("render")
```
## Container:logContainerBenchmarks(methodName)
Logs benchmark statistics for a container and all its children
### Parameters
* `methodName` `string` The method to log
### Returns
* `Container` `self` The container instance
## Container:stopContainerBenchmark(methodName)
Stops benchmarking for a container and all its children
### Parameters
* `methodName` `string` The method to stop benchmarking
### Returns
* `Container` `self` The container instance
# Benchmark
_This is the benchmark plugin. It provides performance measurement tools for elements and methods,
with support for hierarchical profiling and detailed statistics. The plugin is meant to be used for very big projects
where performance is critical. It allows you to measure the time taken by specific methods and log the results._
## Functions
|Method|Returns|Description|
|---|---|---|
|[Benchmark.start](#benchmark-start-name-options)|-|Starts timing a custom operation|
|[Benchmark.stop](#benchmark-stop-name)|-|Stops timing and logs results|
|[Benchmark.getStats](#benchmark-getstats-name)|stats|Retrieves benchmark statistics|
|[Benchmark.clear](#benchmark-clear-name)|-|Removes a benchmark's data|
|[Benchmark.clearAll](#benchmark-clearall)|-|Removes all custom benchmark data|
## Benchmark.start(name, options?)
## API.start(name, options?)
Starts a custom benchmark Starts a custom benchmark
### Parameters ### Parameters
* `name` `string` The name of the benchmark * `name` `string` The name of the benchmark
* `options` *(optional)* `table` Optional configuration * `options` *(optional)* `table` Optional configuration
## API.stop(name) ## Benchmark.stop(name)
Stops a custom benchmark Stops a custom benchmark
### Parameters ### Parameters
* `name` `string` The name of the benchmark to stop * `name` `string` The name of the benchmark to stop
## Benchmark.getStats(name)
Gets statistics for a benchmark
### Parameters
* `name` `string` The name of the benchmark
### Returns
* `stats` `The` benchmark statistics or nil
## Benchmark.clear(name)
Clears a specific benchmark
### Parameters
* `name` `string` The name of the benchmark to clear
## Benchmark.clearAll()
Clears all custom benchmarks

View File

@@ -0,0 +1 @@
!! EMPTY MARKDOWN GENERATED !!

View File

@@ -1,15 +1,15 @@
# BaseElement # BaseElement
No Description _No Description_
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[BaseElement.debug](#baseelement-debug)|-|Enables debugging for this element |[BaseElement.debug](#baseelement-debug-self-level)|-|Enables debugging for this element|
|[BaseElement.dumpDebug](#baseelement-dumpdebug)|-|Dumps debug information |[BaseElement.dumpDebug](#baseelement-dumpdebug-self)|-|Dumps debug information|
## BaseElement.debug(self, level) ## BaseElement.debug(self, level)
Enables debugging for this element Enables debugging for this element
### Parameters ### Parameters
@@ -17,62 +17,55 @@ Enables debugging for this element
* `level` `number` The debug level * `level` `number` The debug level
## BaseElement.dumpDebug(self) ## BaseElement.dumpDebug(self)
Dumps debug information for this element Dumps debug information for this element
### Parameters ### Parameters
* `self` `BaseElement` The element to dump debug info for * `self` `BaseElement` The element to dump debug info for
---
<br>
# BaseFrame # BaseFrame
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[BaseFrame.closeConsole](#baseframe-closeconsole)|-|Hides the debug log frame |[BaseFrame.openConsole](#baseframe-openconsole-self)|-|Shows the debug log frame|
|[BaseFrame.openConsole](#baseframe-openconsole)|-|Shows the debug log frame |[BaseFrame.closeConsole](#baseframe-closeconsole-self)|-|Hides the debug log frame|
|[BaseFrame.toggleConsole](#baseframe-toggleconsole)|-|Toggles the debug log frame |[BaseFrame.toggleConsole](#baseframe-toggleconsole-self)|-|Toggles the debug log frame|
## BaseFrame.closeConsole(self)
Hides the debug log frame
### Parameters
* `self` `BaseFrame` The frame to hide debug log for
## BaseFrame.openConsole(self) ## BaseFrame.openConsole(self)
Shows the debug log frame Shows the debug log frame
### Parameters ### Parameters
* `self` `BaseFrame` The frame to show debug log in * `self` `BaseFrame` The frame to show debug log in
## BaseFrame.closeConsole(self)
Hides the debug log frame
### Parameters
* `self` `BaseFrame` The frame to hide debug log for
## BaseFrame.toggleConsole(self) ## BaseFrame.toggleConsole(self)
Toggles the debug log frame Toggles the debug log frame
### Parameters ### Parameters
* `self` `BaseFrame` The frame to toggle debug log for * `self` `BaseFrame` The frame to toggle debug log for
---
<br>
# Container # Container
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Container.debugChildren](#container-debugchildren)|-|Debug container and children |[Container.debugChildren](#container-debugchildren-self-level)|-|Debug container and children|
## Container.debugChildren(self, level) ## Container.debugChildren(self, level)
Enables debugging for this container and all its children Enables debugging for this container and all its children
### Parameters ### Parameters
* `self` `Container` The container to debug * `self` `Container` The container to debug
* `level` `number` The debug level * `level` `number` The debug level

View File

@@ -1,15 +1,3 @@
# Reactive # Reactive
This module provides reactive functionality for elements, it adds no new functionality for elements. _This module provides reactive functionality for elements, it adds no new functionality for elements.
It is used to evaluate expressions in property values and update the element when the expression changes. It is used to evaluate expressions in property values and update the element when the expression changes._
### Usage
```lua
local button = main:addButton({text="Exit"})
button:setX("{parent.x - 12}")
button:setBackground("{self.clicked and colors.red or colors.green}")
button:setWidth("{self.text:len() + 2}")
```

View File

@@ -1,92 +1,15 @@
# BaseElement # BaseFrame
This is the state plugin. It provides a state management system for UI elements with support for
persistent states, computed states, and state sharing between elements. Extends: `Container`
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[BaseElement:bind](#baseelement-bind)|BaseElement| |[BaseFrame:initializeState](#baseframe-initializestate-self-name-default-persist-path)|BaseFrame|Initializes a new state|
|[BaseElement:computed](#baseelement-computed)|-|
|[BaseElement:getState](#baseelement-getstate)|any|Gets a state value
|[BaseElement:onStateChange](#baseelement-onstatechange)|BaseElement|Watches for state changes
|[BaseElement:removeStateChange](#baseelement-removestatechange)|BaseElement|Removes a state change observer
|[BaseElement:setState](#baseelement-setstate)|BaseElement|Sets a state value
## BaseElement:bind(self, propertyName, stateName)
Binds a property to a state
### Parameters
* `self` `BaseElement` The element to bind
* `propertyName` `string` The property to bind
* `stateName` `string` The state to bind to (optional, uses propertyName if not provided)
### Returns
* `BaseElement` `self` The element instance
## BaseElement:computed()
## BaseElement:getState(self, name)
Gets the value of a state
### Parameters
* `self` `BaseElement` The element to get state from
* `name` `string` The name of the state
### Returns
* `any` `value` The current state value
## BaseElement:onStateChange(self, stateName, callback)
Registers a callback for state changes
### Parameters
* `self` `BaseElement` The element to watch
* `stateName` `string` The state to watch
* `callback` `function` Called with (element, newValue, oldValue)
### Returns
* `BaseElement` `self` The element instance
## BaseElement:removeStateChange(self, stateName, callback)
Removes a state change observer
### Parameters
* `self` `BaseElement` The element to remove observer from
* `stateName` `string` The state to remove observer from
* `callback` `function` The callback function to remove
### Returns
* `BaseElement` `self` The element instance
## BaseElement:setState(self, name, value)
Sets the value of a state
### Parameters
* `self` `BaseElement` The element to set state for
* `name` `string` The name of the state
* `value` `any` The new value for the state
### Returns
* `BaseElement` `self` The element instance
---
<br>
# BaseFrame : Container
## Functions
|Method|Returns|Description|
|---|---|---|
|[BaseFrame.setup](#baseframe-setup)|-|
|[BaseFrame:initializeState](#baseframe-initializestate)|BaseFrame|Initializes a new state
## BaseFrame.setup()
## BaseFrame:initializeState(self, name, default, persist?, path?) ## BaseFrame:initializeState(self, name, default, persist?, path?)
Initializes a new state for this element Initializes a new state for this element
### Parameters ### Parameters
@@ -99,4 +22,75 @@ Initializes a new state for this element
### Returns ### Returns
* `BaseFrame` `self` The element instance * `BaseFrame` `self` The element instance
# BaseElement
_This is the state plugin. It provides a state management system for UI elements with support for
persistent states, computed states, and state sharing between elements._
## Functions
|Method|Returns|Description|
|---|---|---|
|[BaseElement:setState](#baseelement-setstate-self-name-value)|BaseElement|Sets a state value|
|[BaseElement:getState](#baseelement-getstate-self-name)|any|Gets a state value|
|[BaseElement:onStateChange](#baseelement-onstatechange-self-statename-callback)|BaseElement|Watches for state changes|
|[BaseElement:removeStateChange](#baseelement-removestatechange-self-statename-callback)|BaseElement|Removes a state change observer|
|[BaseElement:bind](#baseelement-bind-self-propertyname-statename)|BaseElement|Binds a property to a state|
## BaseElement:setState(self, name, value)
Sets the value of a state
### Parameters
* `self` `BaseElement` The element to set state for
* `name` `string` The name of the state
* `value` `any` The new value for the state
### Returns
* `BaseElement` `self` The element instance
## BaseElement:getState(self, name)
Gets the value of a state
### Parameters
* `self` `BaseElement` The element to get state from
* `name` `string` The name of the state
### Returns
* `any` `value` The current state value
## BaseElement:onStateChange(self, stateName, callback)
Registers a callback for state changes
### Parameters
* `self` `BaseElement` The element to watch
* `stateName` `string` The state to watch
* `callback` `function` Called with (element, newValue, oldValue)
### Returns
* `BaseElement` `self` The element instance
## BaseElement:removeStateChange(self, stateName, callback)
Removes a state change observer
### Parameters
* `self` `BaseElement` The element to remove observer from
* `stateName` `string` The state to remove observer from
* `callback` `function` The callback function to remove
### Returns
* `BaseElement` `self` The element instance
## BaseElement:bind(self, propertyName, stateName)
Binds a property to a state
### Parameters
* `self` `BaseElement` The element to bind
* `propertyName` `string` The property to bind
* `stateName` `string` The state to bind to (optional, uses propertyName if not provided)
### Returns
* `BaseElement` `self` The element instance

View File

@@ -1,26 +1,29 @@
# BaseElement # BaseElement
This is the theme plugin. It provides a theming system that allows for consistent styling across elements _This is the theme plugin. It provides a theming system that allows for consistent styling across elements
with support for inheritance, named styles, and dynamic theme switching. with support for inheritance, named styles, and dynamic theme switching._
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[BaseElement:applyTheme](#baseelement-applytheme)|BaseElement|Applies theme styles to the element |[BaseElement.____getElementPath](#baseelement-----getelementpath)|-||
|[BaseElement:getTheme](#baseelement-gettheme)|table|Gets theme properties for the element |[BaseElement:applyTheme](#baseelement-applytheme-self-applytochildren)|BaseElement|Applies theme styles to the element|
|[BaseElement:getTheme](#baseelement-gettheme-self)|table|Gets theme properties for the element|
## BaseElement.____getElementPath()
## BaseElement:applyTheme(self, applyToChildren) ## BaseElement:applyTheme(self, applyToChildren)
Applies the current theme to this element Applies the current theme to this element
### Parameters ### Parameters
* `self` `BaseElement` The element to apply theme to * `self` `BaseElement` The element to apply theme to
* `applyToChildren` `boolean?` Whether to apply theme to child elements (default: true) * `applyToChildren` `boolean` ? Whether to apply theme to child elements (default: true)
### Returns ### Returns
* `BaseElement` `self` The element instance * `BaseElement` `self` The element instance
## BaseElement:getTheme(self) ## BaseElement:getTheme(self)
Gets the theme properties for this element Gets the theme properties for this element
### Parameters ### Parameters
@@ -29,38 +32,34 @@ Gets the theme properties for this element
### Returns ### Returns
* `table` `styles` The theme properties * `table` `styles` The theme properties
---
<br>
# ThemeAPI # ThemeAPI
The Theme API provides methods for managing themes globally _The Theme API provides methods for managing themes globally_
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[ThemeAPI.getTheme](#themeapi-gettheme)|table|Gets the current theme |[ThemeAPI.setTheme](#themeapi-settheme-newtheme)|-|Sets a new theme|
|[ThemeAPI.loadTheme](#themeapi-loadtheme)|-|Loads theme from JSON file |[ThemeAPI.getTheme](#themeapi-gettheme)|table|Gets the current theme|
|[ThemeAPI.setTheme](#themeapi-settheme)|-|Sets a new theme |[ThemeAPI.loadTheme](#themeapi-loadtheme-path)|-|Loads theme from JSON file|
## ThemeAPI.setTheme(newTheme)
Sets the current theme
### Parameters
* `newTheme` `table` The theme configuration to set
## ThemeAPI.getTheme() ## ThemeAPI.getTheme()
Gets the current theme configuration Gets the current theme configuration
### Returns ### Returns
* `table` `theme` The current theme configuration * `table` `theme` The current theme configuration
## ThemeAPI.loadTheme(path) ## ThemeAPI.loadTheme(path)
Loads a theme from a JSON file Loads a theme from a JSON file
### Parameters ### Parameters
* `path` `string` Path to the theme JSON file * `path` `string` Path to the theme JSON file
## ThemeAPI.setTheme(newTheme)
Sets the current theme
### Parameters
* `newTheme` `table` The theme configuration to set

View File

@@ -0,0 +1 @@
!! EMPTY MARKDOWN GENERATED !!

View File

@@ -1,43 +1,51 @@
# PropertySystem # PropertySystem
PropertySystem is a class that allows Elements to have properties that can be observed and updated. _PropertySystem is a class that allows Elements to have properties that can be observed and updated.
It also allows for properties to have custom getters and setters. This is the base system for all Elements. It also allows for properties to have custom getters and setters. This is the base system for all Elements._
## Fields
|Field|Type|Description|
|---|---|---|
|_properties|`table`|A table containing all property configurations|
|_values|`table`|A table containing all property values|
|_observers|`table`|A table containing all property observers|
|set|`function`|A function to set a property value|
|get|`function`|A function to get a property value|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[PropertySystem.addSetterHook](#propertysystem-addsetterhook)|-|Adds a setter hook to the PropertySystem |[PropertySystem.addSetterHook](#propertysystem-addsetterhook-hook)|-|Adds a setter hook to the PropertySystem|
|[PropertySystem.blueprint](#propertysystem-blueprint)|table|Creates a blueprint of an element class |[PropertySystem.defineProperty](#propertysystem-defineproperty-class-name-config)|-|Defines a property for an element class|
|[PropertySystem.combineProperties](#propertysystem-combineproperties)|-|Combines multiple properties |[PropertySystem.combineProperties](#propertysystem-combineproperties-class-name)|-|Combines multiple properties|
|[PropertySystem.createFromBlueprint](#propertysystem-createfromblueprint)|table|Creates an element from a blueprint |[PropertySystem.blueprint](#propertysystem-blueprint-elementclass)|table|Creates a blueprint of an element class|
|[PropertySystem.defineProperty](#propertysystem-defineproperty)|-|Defines a property for an element class |[PropertySystem.createFromBlueprint](#propertysystem-createfromblueprint-elementclass-blueprint)|table|Creates an element from a blueprint|
|[PropertySystem:__init](#propertysystem-__init)|table|Initializes the PropertySystem |[PropertySystem:__init](#propertysystem---init)|table|Initializes the PropertySystem|
|[PropertySystem:_updateProperty](#propertysystem-_updateproperty)|table|Update call for a property |[PropertySystem:_updateProperty](#propertysystem--updateproperty-name-value)|table|Update call for a property|
|[PropertySystem:getPropertyConfig](#propertysystem-getpropertyconfig)|table|Gets a property configuration |[PropertySystem:observe](#propertysystem-observe-name-callback)|table|Observers a property|
|[PropertySystem:instanceProperty](#propertysystem-instanceproperty)|table|Adds a property to the PropertySystem on instance level |[PropertySystem:removeObserver](#propertysystem-removeobserver-name-callback)|table|Removes an observer from a property|
|[PropertySystem:observe](#propertysystem-observe)|table|Observers a property |[PropertySystem:removeAllObservers](#propertysystem-removeallobservers-name)|table|Removes all observers from a property|
|[PropertySystem:removeAllObservers](#propertysystem-removeallobservers)|table|Removes all observers from a property |[PropertySystem:instanceProperty](#propertysystem-instanceproperty-name-config)|table|Adds a property to the PropertySystem on instance level|
|[PropertySystem:removeObserver](#propertysystem-removeobserver)|table|Removes an observer from a property |[PropertySystem:removeProperty](#propertysystem-removeproperty-name)|table|Removes a property from the PropertySystem|
|[PropertySystem:removeProperty](#propertysystem-removeproperty)|table|Removes a property from the PropertySystem |[PropertySystem:getPropertyConfig](#propertysystem-getpropertyconfig-name)|table|Gets a property configuration|
## PropertySystem.addSetterHook(hook) ## PropertySystem.addSetterHook(hook)
Adds a setter hook to the PropertySystem. Setter hooks are functions that are called before a property is set. Adds a setter hook to the PropertySystem. Setter hooks are functions that are called before a property is set.
### Parameters ### Parameters
* `hook` `function` The hook function to add * `hook` `function` The hook function to add
## PropertySystem.defineProperty(class, name, config)
Defines a property for an element class
### Parameters
* `class` `table` The element class to define the property for
* `name` `string` The name of the property
* `config` `table` The configuration of the property
## PropertySystem.combineProperties(class, name)
Combines multiple properties into a single getter and setter
### Parameters
* `class` `table` The element class to combine the properties for
* `name` `string` The name of the combined property
## PropertySystem.blueprint(elementClass) ## PropertySystem.blueprint(elementClass)
Creates a blueprint of an element class with all its properties Creates a blueprint of an element class with all its properties
### Parameters ### Parameters
@@ -46,15 +54,8 @@ Creates a blueprint of an element class with all its properties
### Returns ### Returns
* `table` `blueprint` A table containing all property definitions * `table` `blueprint` A table containing all property definitions
## PropertySystem.combineProperties(class, name...)
Combines multiple properties into a single getter and setter
### Parameters
* `class` `table` The element class to combine the properties for
* `name` `string` The name of the combined property
* `...` *(vararg)* `string` The names of the properties to combine
## PropertySystem.createFromBlueprint(elementClass, blueprint) ## PropertySystem.createFromBlueprint(elementClass, blueprint)
Creates an element from a blueprint Creates an element from a blueprint
### Parameters ### Parameters
@@ -64,21 +65,15 @@ Creates an element from a blueprint
### Returns ### Returns
* `table` `element` The created element * `table` `element` The created element
## PropertySystem.defineProperty(class, name, config)
Defines a property for an element class
### Parameters
* `class` `table` The element class to define the property for
* `name` `string` The name of the property
* `config` `table` The configuration of the property
## PropertySystem:__init() ## PropertySystem:__init()
Initializes the PropertySystem IS USED INTERNALLY Initializes the PropertySystem IS USED INTERNALLY
### Returns ### Returns
* `table` `self` The PropertySystem * `table` `self` The PropertySystem
## PropertySystem:_updateProperty(name, value) ## PropertySystem:_updateProperty(name, value)
Update call for a property IS USED INTERNALLY Update call for a property IS USED INTERNALLY
### Parameters ### Parameters
@@ -88,26 +83,8 @@ Update call for a property IS USED INTERNALLY
### Returns ### Returns
* `table` `self` The PropertySystem * `table` `self` The PropertySystem
## PropertySystem:getPropertyConfig(name)
Gets a property configuration
### Parameters
* `name` `string` The name of the property
### Returns
* `table` `config` The configuration of the property
## PropertySystem:instanceProperty(name, config)
Adds a property to the PropertySystem on instance level
### Parameters
* `name` `string` The name of the property
* `config` `table` The configuration of the property
### Returns
* `table` `self` The PropertySystem
## PropertySystem:observe(name, callback) ## PropertySystem:observe(name, callback)
Observers a property Observers a property
### Parameters ### Parameters
@@ -117,16 +94,8 @@ Observers a property
### Returns ### Returns
* `table` `self` The PropertySystem * `table` `self` The PropertySystem
## PropertySystem:removeAllObservers(name)
Removes all observers from a property
### Parameters
* `name` `string` The name of the property
### Returns
* `table` `self` The PropertySystem
## PropertySystem:removeObserver(name, callback) ## PropertySystem:removeObserver(name, callback)
Removes an observer from a property Removes an observer from a property
### Parameters ### Parameters
@@ -136,7 +105,29 @@ Removes an observer from a property
### Returns ### Returns
* `table` `self` The PropertySystem * `table` `self` The PropertySystem
## PropertySystem:removeAllObservers(name?)
Removes all observers from a property
### Parameters
* `name` *(optional)* `string` The name of the property
### Returns
* `table` `self` The PropertySystem
## PropertySystem:instanceProperty(name, config)
Adds a property to the PropertySystem on instance level
### Parameters
* `name` `string` The name of the property
* `config` `table` The configuration of the property
### Returns
* `table` `self` The PropertySystem
## PropertySystem:removeProperty(name) ## PropertySystem:removeProperty(name)
Removes a property from the PropertySystem on instance level Removes a property from the PropertySystem on instance level
### Parameters ### Parameters
@@ -145,4 +136,12 @@ Removes a property from the PropertySystem on instance level
### Returns ### Returns
* `table` `self` The PropertySystem * `table` `self` The PropertySystem
## PropertySystem:getPropertyConfig(name)
Gets a property configuration
### Parameters
* `name` `string` The name of the property
### Returns
* `table` `config` The configuration of the property

View File

@@ -1,55 +1,44 @@
# Render # Render
This is the render module for Basalt. It tries to mimic the functionality of the `term` API. but with additional _This is the render module for Basalt. It tries to mimic the functionality of the `term` API. but with additional
functionality. It also has a buffer system to reduce the number of calls functionality. It also has a buffer system to reduce the number of calls_
## Fields
|Field|Type|Description|
|---|---|---|
|terminal|`table`|The terminal object to render to|
|width|`number`|The width of the render|
|height|`number`|The height of the render|
|buffer|`table`|The buffer to render|
|xCursor|`number`|The x position of the cursor|
|yCursor|`number`|The y position of the cursor|
|blink|`boolean`|Whether the cursor should blink|
## Functions ## Functions
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Render.new](#render-new)|Render| |[Render.new](#render-new-terminal)|Render|Creates a new Render object|
|[Render:addDirtyRect](#render-adddirtyrect)|Render| |[Render:addDirtyRect](#render-adddirtyrect-x-y-width-height)|Render|Adds a dirty rectangle to the buffer|
|[Render:bg](#render-bg)|Render| |[Render:blit](#render-blit-x-y-text-fg-bg)|Render|Blits text to the screen|
|[Render:bg](#render-bg)|Render| |[Render:multiBlit](#render-multiblit-x-y-width-height-text-fg-bg)|Render|Blits text to the screen with multiple lines|
|[Render:blit](#render-blit)|Render| |[Render:textFg](#render-textfg-x-y-text-fg)|Render|Blits text to the screen with a foreground color|
|[Render:clear](#render-clear)|Render| |[Render:textBg](#render-textbg-x-y-text-bg)|Render|Blits text to the screen with a background color|
|[Render:clearArea](#render-cleararea)|Render| |[Render:text](#render-text-x-y-text)|Render|Renders the text to the screen|
|[Render:fg](#render-fg)|Render| |[Render:fg](#render-fg-x-y-fg)|Render|Blits a foreground color to the screen|
|[Render:fg](#render-fg)|Render| |[Render:bg](#render-bg-x-y-bg)|Render|Blits a background color to the screen|
|[Render:getSize](#render-getsize)|number,| |[Render:text](#render-text-x-y-text)|Render|Blits text to the screen|
|[Render:mergeRects](#render-mergerects)|Render| |[Render:fg](#render-fg-x-y-fg)|Render|Blits a foreground color to the screen|
|[Render:multiBlit](#render-multiblit)|Render| |[Render:bg](#render-bg-x-y-bg)|Render|Blits a background color to the screen|
|[Render:rectOverlaps](#render-rectoverlaps)|boolean| |[Render:clear](#render-clear-bg)|Render|Clears the screen|
|[Render:render](#render-render)|Render| |[Render:render](#render-render)|Render|Renders the buffer to the screen|
|[Render:setCursor](#render-setcursor)|Render| |[Render:rectOverlaps](#render-rectoverlaps-r1-r2)|boolean|Checks if two rectangles overlap|
|[Render:setSize](#render-setsize)|Render| |[Render:mergeRects](#render-mergerects-target-source)|Render|Merges two rectangles|
|[Render:text](#render-text)|Render| |[Render:setCursor](#render-setcursor-x-y-blink)|Render|Sets the cursor position|
|[Render:text](#render-text)|Render| |[Render:clearArea](#render-cleararea-x-y-width-height-bg)|Render|Clears an area of the screen|
|[Render:textBg](#render-textbg)|Render| |[Render:getSize](#render-getsize)|number|Gets the size of the render|
|[Render:textFg](#render-textfg)|Render| |[Render:setSize](#render-setsize-width-height)|Render|Sets the size of the render|
## Render.new(terminal) ## Render.new(terminal)
Creates a new Render object Creates a new Render object
### Parameters ### Parameters
* `terminal` `table` The terminal object to render to * `terminal` `table` The terminal object to render to
### Returns ### Returns
* `nil` `nil` nil * `Render`
## Render:addDirtyRect(x, y, width, height) ## Render:addDirtyRect(x, y, width, height)
Adds a dirty rectangle to the buffer Adds a dirty rectangle to the buffer
### Parameters ### Parameters
@@ -59,31 +48,10 @@ Adds a dirty rectangle to the buffer
* `height` `number` The height of the rectangle * `height` `number` The height of the rectangle
### Returns ### Returns
* `nil` `nil` nil * `Render`
## Render:bg(x, y, bg)
Blits a background color to the screen
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `bg` `string` The background color to blit
### Returns
* `nil` `nil` nil
## Render:bg(x, y, bg)
Blits a background color to the screen
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `bg` `string` The background color to blit
### Returns
* `nil` `nil` nil
## Render:blit(x, y, text, fg, bg) ## Render:blit(x, y, text, fg, bg)
Blits text to the screen Blits text to the screen
### Parameters ### Parameters
@@ -94,69 +62,10 @@ Blits text to the screen
* `bg` `string` The background color of the text * `bg` `string` The background color of the text
### Returns ### Returns
* `nil` `nil` nil * `Render`
## Render:clear(bg)
Clears the screen
### Parameters
* `bg` `colors` The background color to clear the screen with
### Returns
* `nil` `nil` nil
## Render:clearArea(x, y, width, height, bg)
Clears an area of the screen
### Parameters
* `x` `number` The x position of the area
* `y` `number` The y position of the area
* `width` `number` The width of the area
* `height` `number` The height of the area
* `bg` `colors` The background color to clear the area with
### Returns
* `nil` `nil` nil
## Render:fg(x, y, fg)
Blits a foreground color to the screen
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `fg` `string` The foreground color to blit
### Returns
* `nil` `nil` nil
## Render:fg(x, y, fg)
Blits a foreground color to the screen
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `fg` `string` The foreground color to blit
### Returns
* `nil` `nil` nil
## Render:getSize()
Gets the size of the render
### Returns
* `nil` `nil` nil
## Render:mergeRects(target, source)
Merges two rectangles
### Parameters
* `target` `table` The target rectangle
* `source` `table` The source rectangle
### Returns
* `nil` `nil` nil
## Render:multiBlit(x, y, width, height, text, fg, bg) ## Render:multiBlit(x, y, width, height, text, fg, bg)
Blits text to the screen with multiple lines Blits text to the screen with multiple lines
### Parameters ### Parameters
@@ -169,80 +78,10 @@ Blits text to the screen with multiple lines
* `bg` `colors` The background color of the text * `bg` `colors` The background color of the text
### Returns ### Returns
* `nil` `nil` nil * `Render`
## Render:rectOverlaps(r1, r2)
Checks if two rectangles overlap
### Parameters
* `r1` `table` The first rectangle
* `r2` `table` The second rectangle
### Returns
* `nil` `nil` nil
## Render:render()
Renders the buffer to the screen
### Returns
* `nil` `nil` nil
## Render:setCursor(x, y, blink)
Sets the cursor position
### Parameters
* `x` `number` The x position of the cursor
* `y` `number` The y position of the cursor
* `blink` `boolean` Whether the cursor should blink
### Returns
* `nil` `nil` nil
## Render:setSize(width, height)
Sets the size of the render
### Parameters
* `width` `number` The width of the render
* `height` `number` The height of the render
### Returns
* `nil` `nil` nil
## Render:text(x, y, text)
Blits text to the screen
### Parameters
* `x` `number` The x position to blit to
* `y` `number` The y position to blit to
* `text` `string` The text to blit
### Returns
* `nil` `nil` nil
## Render:text(x, y, text)
Renders the text to the screen
### Parameters
* `x` `number` The x position to blit to
* `y` `number` The y position to blit to
* `text` `string` The text to blit
### Returns
* `nil` `nil` nil
## Render:textBg(x, y, text, bg)
Blits text to the screen with a background color
### Parameters
* `x` `number` The x position to blit to
* `y` `number` The y position to blit to
* `text` `string` The text to blit
* `bg` `colors` The background color of the text
### Returns
* `nil` `nil` nil
## Render:textFg(x, y, text, fg) ## Render:textFg(x, y, text, fg)
Blits text to the screen with a foreground color Blits text to the screen with a foreground color
### Parameters ### Parameters
@@ -252,6 +91,172 @@ Blits text to the screen with a foreground color
* `fg` `colors` The foreground color of the text * `fg` `colors` The foreground color of the text
### Returns ### Returns
* `nil` `nil` nil * `Render`
## Render:textBg(x, y, text, bg)
Blits text to the screen with a background color
### Parameters
* `x` `number` The x position to blit to
* `y` `number` The y position to blit to
* `text` `string` The text to blit
* `bg` `colors` The background color of the text
### Returns
* `Render`
## Render:text(x, y, text)
Renders the text to the screen
### Parameters
* `x` `number` The x position to blit to
* `y` `number` The y position to blit to
* `text` `string` The text to blit
### Returns
* `Render`
## Render:fg(x, y, fg)
Blits a foreground color to the screen
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `fg` `string` The foreground color to blit
### Returns
* `Render`
## Render:bg(x, y, bg)
Blits a background color to the screen
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `bg` `string` The background color to blit
### Returns
* `Render`
## Render:text(x, y, text)
Blits text to the screen
### Parameters
* `x` `number` The x position to blit to
* `y` `number` The y position to blit to
* `text` `string` The text to blit
### Returns
* `Render`
## Render:fg(x, y, fg)
Blits a foreground color to the screen
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `fg` `string` The foreground color to blit
### Returns
* `Render`
## Render:bg(x, y, bg)
Blits a background color to the screen
### Parameters
* `x` `number` The x position
* `y` `number` The y position
* `bg` `string` The background color to blit
### Returns
* `Render`
## Render:clear(bg)
Clears the screen
### Parameters
* `bg` `colors` The background color to clear the screen with
### Returns
* `Render`
## Render:render()
Renders the buffer to the screen
### Returns
* `Render`
## Render:rectOverlaps(r1, r2)
Checks if two rectangles overlap
### Parameters
* `r1` `table` The first rectangle
* `r2` `table` The second rectangle
### Returns
* `boolean`
## Render:mergeRects(target, source)
Merges two rectangles
### Parameters
* `target` `table` The target rectangle
* `source` `table` The source rectangle
### Returns
* `Render`
## Render:setCursor(x, y, blink)
Sets the cursor position
### Parameters
* `x` `number` The x position of the cursor
* `y` `number` The y position of the cursor
* `blink` `boolean` Whether the cursor should blink
### Returns
* `Render`
## Render:clearArea(x, y, width, height, bg)
Clears an area of the screen
### Parameters
* `x` `number` The x position of the area
* `y` `number` The y position of the area
* `width` `number` The width of the area
* `height` `number` The height of the area
* `bg` `colors` The background color to clear the area with
### Returns
* `Render`
## Render:getSize()
Gets the size of the render
### Returns
* `number`
## Render:setSize(width, height)
Sets the size of the render
### Parameters
* `width` `number` The width of the render
* `height` `number` The height of the render
### Returns
* `Render`