This commit is contained in:
NoryiE
2025-02-17 08:37:58 +00:00
parent 056897dd1b
commit ca2521d237
6 changed files with 98 additions and 45 deletions

View File

@@ -19,7 +19,7 @@ The base class for all UI elements in Basalt
|[BaseElement:destroy](#BaseElement:destroy)|-|
|[BaseElement:dispatchEvent](#BaseElement:dispatchEvent)|boolean?|
|[BaseElement:fireEvent](#BaseElement:fireEvent)|table|
|[BaseElement:getBaseFrame](#BaseElement:getBaseFrame)|-|
|[BaseElement:getBaseFrame](#BaseElement:getBaseFrame)|table|
|[BaseElement:handleEvent](#BaseElement:handleEvent)|boolean?|
|[BaseElement:init](#BaseElement:init)|table|
|[BaseElement:isType](#BaseElement:isType)|boolean|
@@ -56,6 +56,12 @@ local element = BaseElement.new("myId", basalt)
```
## BaseElement:destroy()
Destroys the element and cleans up all references
### Usage
```lua
element:destroy()
```
## BaseElement:dispatchEvent(event)
Handles all events
@@ -83,6 +89,10 @@ element:fireEvent("mouse_click", 1, 2)
```
## BaseElement:getBaseFrame()
Returns the base frame of the element
### Returns
* `table` `BaseFrame` The base frame of the element
## BaseElement:handleEvent(event)
The default event handler for all events
@@ -129,7 +139,7 @@ element:listenEvent("mouse_click", true)
```
## BaseElement:postInit()
Post initialization hook
Post initialization
### Returns
* `table` `self` The BaseElement instance

View File

@@ -6,6 +6,11 @@
|---|---|---|---|
|text|string|Button|Button text
## Events
|Event|Parameters|Description|
|---|---|---|
## Functions
|Method|Returns|Description|
@@ -14,7 +19,6 @@
|[Button:init](#Button:init)|-|
|[Button:render](#Button:render)|-|
@event mouse_click The event that is triggered when the button is clicked
## Button.new()
Creates a new Button instance

View File

@@ -22,6 +22,7 @@
|[Container:blit](#Container:blit)|Container|
|[Container:char](#Container:char)|boolean|
|[Container:clear](#Container:clear)|Container|
|[Container:destroy](#Container:destroy)|-|
|[Container:getChild](#Container:getChild)|Container?|
|[Container:handleEvent](#Container:handleEvent)|boolean|
|[Container:init](#Container:init)|-|
@@ -84,6 +85,8 @@ Clears the container
### Returns
* `Container` `self` The container instance
## Container:destroy()
## Container:getChild(path)
Removes a child from the container

View File

@@ -1,4 +1,3 @@
@alias color number
# VisualElement : BaseElement
## Properties
@@ -17,6 +16,28 @@
|focused|boolean|false|whether the element is focused
|visible|boolean|true|whether the element is visible
## Combined Properties
|Name|Properties|Description|
|---|---|---|
|position|{x|y}|Position of the element
|size|{width|height}|Size of the element
|color|{foreground|background}|Color of the element
## Events
|Event|Parameters|Description|
|---|---|---|
|onMouseClick|`button number, x number, y number`|Fired when the element is clicked|
|onMouseUp|`button number, x number, y number`|Fired when the mouse is released|
|onMouseRelease|`button number, x number, y number`|Fired when the mouse is released|
|onMouseDrag|`button number, x number, y number`|Fired when the mouse is dragged|
|onFocus|`-`|Fired when the element is focused|
|onBlur|`-`|Fired when the element is blurred|
|onKey|`key number, code number, isRepeat boolean`|Fired when a key is pressed|
|onKeyUp|`key number, code number`|Fired when a key is released|
|onChar|`char string`|Fired when a key is pressed|
## Functions
|Method|Returns|Description|
@@ -32,15 +53,11 @@
|[VisualElement:mouse_click](#VisualElement:mouse_click)|boolean|
|[VisualElement:mouse_release](#VisualElement:mouse_release)|boolean|
|[VisualElement:mouse_up](#VisualElement:mouse_up)|boolean|
|[VisualElement:multiBlit](#VisualElement:multiBlit)|-|
|[VisualElement:render](#VisualElement:render)|-|
|[VisualElement:setCursor](#VisualElement:setCursor)|-|
|[VisualElement:textBg](#VisualElement:textBg)|-|
|[VisualElement:textFg](#VisualElement:textFg)|-|
@combinedProperty position x y
@combinedProperty size width height
@combinedProperty color foreground background
## VisualElement.new(props, basalt)
Creates a new VisualElement instance
@@ -135,26 +152,9 @@ Handles a mouse up event
### Returns
* `boolean` `release` Whether the element was released on the element
## VisualElement:multiBlit(x, y, width, height, text, fg, bg)
Draws a text character/fg/bg at the specified position with a certain size, used in the rendering system
### Parameters
* `x` `number` The x position to draw
* `y` `number` The y position to draw
* `width` `number` The width of the element
* `height` `number` The height of the element
* `text` `string` The text char to draw
* `fg` `color` The foreground color
* `bg` `color` The background color
## VisualElement:render()
Renders the element
### Usage
```lua
element:render()
```
## VisualElement:setCursor(x, y, blink)
Sets the cursor position

View File

@@ -1,7 +1,31 @@
Log levels
# Log
## Fields
|Field|Type|Description|
|---|---|---|
## Functions
|Method|Returns|Description|
|---|---|---|
|[Log.error](#Log.error)|-|
|[Log.setEnabled](#Log.setEnabled)|-|
|[Log.setLogToFile](#Log.setLogToFile)|-|
## Log.error()
Sends a debug message to the logger.
@vararg string The message to log
Sends an info message to the logger.
@vararg string The message to log
Sends a warning message to the logger.
@vararg string The message to log
Sends an error message to the logger.
@vararg string The message to log
## Log.setEnabled()
sets if the logger should log
## Log.setLogToFile()
Sets if the logger should log to a file.

View File

@@ -1,30 +1,35 @@
# 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:
### 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".
# 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|
|LOGGER|`Log`|The logger instance|
|path|`string`|The path to the Basalt library|
## Functions
|Method|Returns|Description|
|---|---|---|
|[basalt.create](#basalt.create)|table|Creates a new UI element
|[basalt.createFrame](#basalt.createFrame)|table|
|[basalt.getAPI](#basalt.getAPI)|-|
|[basalt.getElementManager](#basalt.getElementManager)|table|
|[basalt.getMainFrame](#basalt.getMainFrame)|BaseFrame|
|[basalt.removeSchedule](#basalt.removeSchedule)|-|
|[basalt.run](#basalt.run)|-|
|[basalt.scheduleUpdate](#basalt.scheduleUpdate)|number|
|[basalt.setActiveFrame](#basalt.setActiveFrame)|-|
|[basalt.stop](#basalt.stop)|-|
|[basalt.update](#basalt.update)|-|
|[basalt.createFrame](#basalt.createFrame)|table|Creates a new BaseFrame
|[basalt.getAPI](#basalt.getAPI)|table|Returns a Plugin API
|[basalt.getElementManager](#basalt.getElementManager)|table|Returns the element manager
|[basalt.getMainFrame](#basalt.getMainFrame)|BaseFrame|Gets or creates the main frame
|[basalt.removeSchedule](#basalt.removeSchedule)|-|Removes a scheduled update
|[basalt.run](#basalt.run)|-|Starts the Basalt runtime
|[basalt.scheduleUpdate](#basalt.scheduleUpdate)|number|Schedules a function to be updated
|[basalt.setActiveFrame](#basalt.setActiveFrame)|-|Sets the active frame
|[basalt.stop](#basalt.stop)|-|Stops the Basalt runtime
|[basalt.update](#basalt.update)|-|Updates all scheduled functions
## basalt.create(type, properties?)
Creates and returns a new UI element of the specified type.
@@ -42,7 +47,7 @@ local button = basalt.create("Button")
```
## basalt.createFrame()
Creates and returns a new frame
Creates and returns a new BaseFrame
### Returns
* `table` `BaseFrame` The created frame instance
@@ -52,7 +57,14 @@ Creates and returns a new frame
local mainFrame = basalt.createFrame()
```
## basalt.getAPI()
## basalt.getAPI(name)
Returns a Plugin API
### Parameters
* `name` `string` The name of the plugin
### Returns
* `table` `Plugin` The plugin API
## basalt.getElementManager()
Returns the element manager instance