Merge branch 'gh-pages' of https://github.com/Pyroxenium/Basalt2 into gh-pages

This commit is contained in:
Robert Jelic
2025-03-24 20:47:00 +01:00
4 changed files with 91 additions and 80 deletions

View File

@@ -7,17 +7,19 @@ This is the base frame class. It is the root element of all elements and the onl
|---|---|---| |---|---|---|
|_render|`Render`|The render object| |_render|`Render`|The render object|
|_renderUpdate|`boolean`|Whether the render object needs to be updated| |_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|
|---|---|---|---| |---|---|---|---|
|text|term|nil|The terminal 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:setCursor](#baseframe-setcursor)|-|Sets the cursor position |[BaseFrame:setCursor](#baseframe-setcursor)|-|Sets the cursor position
@@ -30,6 +32,8 @@ This is the base frame class. It is the root element of all elements and the onl
|BaseFrame:init|table|Initializes the Frame instance |BaseFrame:init|table|Initializes the Frame instance
|BaseFrame:key|-|Handles key events |BaseFrame:key|-|Handles key events
|BaseFrame:key_up|-|Handles key up 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:mouse_up|-|Handles mouse up events
|BaseFrame:multiBlit|-|Renders a multiBlit to the render Object |BaseFrame:multiBlit|-|Renders a multiBlit to the render Object
|BaseFrame:render|-|Renders the Frame |BaseFrame:render|-|Renders the Frame
@@ -37,6 +41,8 @@ This is the base frame class. It is the root element of all elements and the onl
|BaseFrame:textBg|-|Renders a text with a background color to the render Object |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:textFg|-|Renders a text with a foreground color to the render Object
## BaseFrame:dispatchEvent()
## BaseFrame:setCursor(x, y, blink) ## BaseFrame:setCursor(x, y, blink)
Sets the cursor position Sets the cursor position

View File

@@ -6,6 +6,7 @@ The Display is a special element where you can use the window (term) API to draw
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[Display:getWindow](#display-getwindow)|table|Returns the current window object |[Display:getWindow](#display-getwindow)|table|Returns the current window object
|[Display:write](#display-write)|Display|Writes text to the display
## Protected Functions ## Protected Functions
@@ -21,4 +22,17 @@ 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?)
Writes text to the display at the given position with the given foreground and background colors
### Parameters
* `x` `number` The x position to write to
* `y` `number` The y position to write to
* `text` `string` The text to write
* `fg` *(optional)* `colors` The foreground color (optional)
* `bg` *(optional)* `colors` The background color (optional)
### Returns
* `Display` `self` The display instance

View File

@@ -32,11 +32,14 @@ What this code does is it loads basalt into the project, and you can access it b
|[basalt.getActiveFrame](#basalt-getactiveframe)|BaseFrame?|Returns the active frame |[basalt.getActiveFrame](#basalt-getactiveframe)|BaseFrame?|Returns the active frame
|[basalt.getElementClass](#basalt-getelementclass)|table|Returns an element class |[basalt.getElementClass](#basalt-getelementclass)|table|Returns an element class
|[basalt.getElementManager](#basalt-getelementmanager)|table|Returns the element manager |[basalt.getElementManager](#basalt-getelementmanager)|table|Returns the element manager
|[basalt.getErrorManager](#basalt-geterrormanager)|table|Returns the error manager
|[basalt.getFocus](#basalt-getfocus)|BaseFrame?|Returns the focused frame
|[basalt.getMainFrame](#basalt-getmainframe)|BaseFrame|Gets or creates the main frame |[basalt.getMainFrame](#basalt-getmainframe)|BaseFrame|Gets or creates the main frame
|[basalt.removeSchedule](#basalt-removeschedule)|boolean|Removes a scheduled update |[basalt.removeSchedule](#basalt-removeschedule)|boolean|Removes a scheduled update
|[basalt.run](#basalt-run)|-|Starts the Basalt runtime |[basalt.run](#basalt-run)|-|Starts the Basalt runtime
|[basalt.schedule](#basalt-schedule)|thread|Schedules a function to run in a coroutine |[basalt.schedule](#basalt-schedule)|thread|Schedules a function to run in a coroutine
|[basalt.setActiveFrame](#basalt-setactiveframe)|-|Sets the active frame |[basalt.setActiveFrame](#basalt-setactiveframe)|-|Sets the active frame
|[basalt.setFocus](#basalt-setfocus)|-|Sets a frame as focused
|[basalt.stop](#basalt-stop)|-|Stops the Basalt runtime |[basalt.stop](#basalt-stop)|-|Stops the Basalt runtime
|[basalt.update](#basalt-update)|-|Runs basalt once |[basalt.update](#basalt-update)|-|Runs basalt once
@@ -62,11 +65,6 @@ Creates and returns a new BaseFrame
### Returns ### Returns
* `BaseFrame` `BaseFrame` The created frame instance * `BaseFrame` `BaseFrame` The created frame instance
### Usage
```lua
local mainFrame = basalt.createFrame()
```
## basalt.getAPI(name) ## basalt.getAPI(name)
Returns a Plugin API Returns a Plugin API
@@ -76,17 +74,15 @@ Returns a Plugin API
### Returns ### Returns
* `table` `Plugin` The plugin API * `table` `Plugin` The plugin API
## basalt.getActiveFrame() ## basalt.getActiveFrame(t?)
Returns the active frame Returns the active frame
### Parameters
* `t` *(optional)* `term` The term to get the active frame for (default: current term)
### Returns ### Returns
* `BaseFrame?` `BaseFrame` The frame to set as active * `BaseFrame?` `BaseFrame` The frame to set as active
### Usage
```lua
local frame = basalt.getActiveFrame()
```
## basalt.getElementClass(name) ## basalt.getElementClass(name)
Returns an element's class without creating a instance Returns an element's class without creating a instance
@@ -102,10 +98,17 @@ Returns the element manager instance
### Returns ### Returns
* `table` `ElementManager` The element manager * `table` `ElementManager` The element manager
### Usage ## basalt.getErrorManager()
```lua Returns the error manager instance
local manager = basalt.getElementManager()
``` ### Returns
* `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
@@ -113,11 +116,6 @@ Gets or creates the main frame
### Returns ### Returns
* `BaseFrame` `BaseFrame` The main frame instance * `BaseFrame` `BaseFrame` The main frame instance
### Usage
```lua
local frame = basalt.getMainFrame()
```
## basalt.removeSchedule(func) ## basalt.removeSchedule(func)
Removes a scheduled update Removes a scheduled update
@@ -127,23 +125,12 @@ Removes a scheduled update
### Returns ### Returns
* `boolean` `success` Whether the scheduled function was removed * `boolean` `success` Whether the scheduled function was removed
### Usage
```lua
basalt.removeSchedule(scheduleId)
```
## basalt.run(isActive?) ## basalt.run(isActive?)
Starts the Basalt runtime Starts the Basalt runtime
### Parameters ### Parameters
* `isActive` *(optional)* `boolean` Whether to start active (default: true) * `isActive` *(optional)* `boolean` Whether to start active (default: true)
### Usage
```lua
basalt.run()
basalt.run(false)
```
## basalt.schedule(func) ## basalt.schedule(func)
Schedules a function to run in a coroutine Schedules a function to run in a coroutine
@@ -153,39 +140,26 @@ Schedules a function to run in a coroutine
### Returns ### Returns
* `thread` `func` The scheduled function * `thread` `func` The scheduled function
### Usage ## basalt.setActiveFrame(frame, setActive?)
```lua
local id = basalt.scheduleUpdate(myFunction)
```
## basalt.setActiveFrame(frame)
Sets the active frame Sets the active frame
### Parameters ### Parameters
* `frame` `BaseFrame` The frame to set as active * `frame` `BaseFrame` The frame to set as active
* `setActive` *(optional)* `boolean` Whether to set the frame as active (default: true)
### Usage ## basalt.setFocus(frame)
```lua Sets a frame as focused
basalt.setActiveFrame(myFrame)
``` ### Parameters
* `frame` `BaseFrame` The frame to set as focused
## basalt.stop() ## basalt.stop()
Stops the Basalt runtime Stops the Basalt runtime
### Usage
```lua
basalt.stop()
```
## basalt.update(...) ## 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
### Parameters ### Parameters
* `...` *(vararg)* `any` The event to run with * `...` *(vararg)* `any` The event to run with
### Usage
```lua
basalt.update()
```

View File

@@ -6,25 +6,27 @@ persistent states, computed states, and state sharing between elements.
|Method|Returns|Description| |Method|Returns|Description|
|---|---|---| |---|---|---|
|[BaseElement:computed](#baseelement-computed)|BaseElement|Creates a computed state |[BaseElement:bind](#baseelement-bind)|BaseElement|
|[BaseElement:computed](#baseelement-computed)|-|
|[BaseElement:getState](#baseelement-getstate)|any|Gets a state value |[BaseElement:getState](#baseelement-getstate)|any|Gets a state value
|[BaseElement:initializeState](#baseelement-initializestate)|BaseElement|Initializes a new state
|[BaseElement:onStateChange](#baseelement-onstatechange)|BaseElement|Watches for state changes |[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:setState](#baseelement-setstate)|BaseElement|Sets a state value
|[BaseElement:shareState](#baseelement-sharestate)|BaseElement|Shares state between elements
## BaseElement:computed(self, key, computeFn) ## BaseElement:bind(self, propertyName, stateName)
Creates a computed state that derives its value from other states Binds a property to a state
### Parameters ### Parameters
* `self` `BaseElement` The element to create computed state for * `self` `BaseElement` The element to bind
* `key` `string` The name of the computed state * `propertyName` `string` The property to bind
* `computeFn` `function` Function that computes the state value * `stateName` `string` The state to bind to (optional, uses propertyName if not provided)
### Returns ### Returns
* `BaseElement` `self` The element instance * `BaseElement` `self` The element instance
## BaseElement:computed()
## BaseElement:getState(self, name) ## BaseElement:getState(self, name)
Gets the value of a state Gets the value of a state
@@ -35,20 +37,6 @@ Gets the value of a state
### Returns ### Returns
* `any` `value` The current state value * `any` `value` The current state value
## BaseElement:initializeState(self, name, default, canTriggerRender?, persist?, path?)
Initializes a new state for this element
### Parameters
* `self` `BaseElement` The element to initialize state for
* `name` `string` The name of the state
* `default` `any` The default value of the state
* `canTriggerRender` *(optional)* `boolean` Whether state changes trigger a render
* `persist` *(optional)* `boolean` Whether to persist the state to disk
* `path` *(optional)* `string` Custom file path for persistence
### Returns
* `BaseElement` `self` The element instance
## BaseElement:onStateChange(self, stateName, callback) ## BaseElement:onStateChange(self, stateName, callback)
Registers a callback for state changes Registers a callback for state changes
@@ -60,6 +48,17 @@ Registers a callback for state changes
### Returns ### Returns
* `BaseElement` `self` The element instance * `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) ## BaseElement:setState(self, name, value)
Sets the value of a state Sets the value of a state
@@ -71,15 +70,33 @@ Sets the value of a state
### Returns ### Returns
* `BaseElement` `self` The element instance * `BaseElement` `self` The element instance
## BaseElement:shareState(self, stateKey...)
Shares a state with other elements, keeping them in sync ---
<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?)
Initializes a new state for this element
### Parameters ### Parameters
* `self` `BaseElement` The source element * `self` `BaseFrame` The element to initialize state for
* `stateKey` `string` The state to share * `name` `string` The name of the state
* `...` *(vararg)* `BaseElement` The target elements to share with * `default` `any` The default value of the state
* `persist` *(optional)* `boolean` Whether to persist the state to disk
* `path` *(optional)* `string` Custom file path for persistence
### Returns ### Returns
* `BaseElement` `self` The source element * `BaseFrame` `self` The element instance