This commit is contained in:
NoryiE
2025-02-10 05:23:41 +00:00
parent 63fff2224c
commit 443182ed9f
18 changed files with 394 additions and 719 deletions

112
BaseElement.md Normal file
View File

@@ -0,0 +1,112 @@
# BaseElement
The base class for all UI elements in Basalt
## Properties
|Property|Type|Default|Description|
|---|---|---|---|
|type|string|BaseElement|The type identifier of the element
|eventCallbacks|table|{}|Table containing all registered event callbacks
## Functions
|Method|Returns|Description|
|---|---|---|
|[BaseElement.listenTo](#BaseElement.listenTo)|-|
|[BaseElement.new](#BaseElement.new)|table|
|[BaseElement:fireEvent](#BaseElement:fireEvent)|table|
|[BaseElement:init](#BaseElement:init)|table|
|[BaseElement:listenEvent](#BaseElement:listenEvent)|table|
|[BaseElement:registerCallback](#BaseElement:registerCallback)|table|
|[BaseElement:updateRender](#BaseElement:updateRender)|-|
## BaseElement.listenTo(class, eventName)
Registers an event that this class can listen to
### Parameters
* `class` `table` The class to add the event to
* `eventName` `string` The name of the event to register
### Usage
```lua
BaseElement.listenTo(MyClass, "mouse_click")
```
## BaseElement.new(id, basalt)
Creates a new BaseElement instance
### Parameters
* `id` `string` The unique identifier for this element
* `basalt` `table` The basalt instance
### Returns
* `table` `The` newly created BaseElement instance
### Usage
```lua
local element = BaseElement.new("myId", basalt)
```
## BaseElement:fireEvent(event, ...)
Triggers an event and calls all registered callbacks
### Parameters
* `event` `string` The event to fire
* `...` `any` Additional arguments to pass to the callbacks
### Returns
* `table` `self` The BaseElement instance
### Usage
```lua
element:fireEvent("mouse_click", 1, 2)
```
## BaseElement:init(id, basalt)
Initializes the BaseElement instance
### Parameters
* `id` `string` The unique identifier for this element
* `basalt` `table` The basalt instance
### Returns
* `table` `self` The initialized instance
## BaseElement:listenEvent(eventName, enable?)
Enables or disables event listening for a specific event
### Parameters
* `eventName` `string` The name of the event to listen for
* `enable` *(optional)* `boolean` Whether to enable or disable the event (default: true)
### Returns
* `table` `self` The BaseElement instance
### Usage
```lua
element:listenEvent("mouse_click", true)
```
## BaseElement:registerCallback(event, callback)
Registers a callback function for an event
### Parameters
* `event` `string` The event to register the callback for
* `callback` `function` The callback function to register
### Returns
* `table` `self` The BaseElement instance
### Usage
```lua
element:registerCallback("mouse_click", function(self, ...) end)
```
## BaseElement:updateRender()
Requests a render update for this element
### Usage
```lua
element:updateRender()
```

10
BaseFrame.md Normal file
View File

@@ -0,0 +1,10 @@
## BaseFrame.new()
@diagnostic disable-next-line: duplicate-set-field
## BaseFrame:multiBlit()
## BaseFrame:render()
@diagnostic disable-next-line: duplicate-set-field
## BaseFrame:textFg()

6
Button.md Normal file
View File

@@ -0,0 +1,6 @@
## Button.new()
@diagnostic disable-next-line: duplicate-set-field
## Button:render()
@diagnostic disable-next-line: duplicate-set-field

28
Container.md Normal file
View File

@@ -0,0 +1,28 @@
## Container.new()
@diagnostic disable-next-line: duplicate-set-field
## Container:addChild()
## Container:handleEvent()
## Container:multiBlit()
## Container:registerChildEvent()
## Container:registerChildrenEvents()
## Container:removeChild()
## Container:removeChildrenEvents()
## Container:render()
@diagnostic disable-next-line: duplicate-set-field
## Container:sortChildren()
## Container:sortChildrenEvents()
## Container:textFg()
## Container:unregisterChildEvent()

3
Frame.md Normal file
View File

@@ -0,0 +1,3 @@
## Frame.new()
@diagnostic disable-next-line: duplicate-set-field

37
VisualElement.md Normal file
View File

@@ -0,0 +1,37 @@
## VisualElement.new()
@diagnostic disable-next-line: duplicate-set-field
## VisualElement:getAbsolutePosition(x?, y?)
Returns the absolute position of the element or the given coordinates.
### Parameters
* `x` *(optional)* `number` -- x position
* `y` *(optional)* `number` -- y position
## VisualElement:getRelativePosition(x?, y?)
Returns the relative position of the element or the given coordinates.
### Parameters
* `x` *(optional)* `number` -- x position
* `y` *(optional)* `number` -- y position
### Returns
* `nil` `nil` nil
## VisualElement:handleEvent()
## VisualElement:isInBounds()
## VisualElement:mouse_click()
## VisualElement:mouse_release()
## VisualElement:mouse_up()
## VisualElement:multiBlit()
## VisualElement:render()
@diagnostic disable-next-line: duplicate-set-field
## VisualElement:textFg()

0
colorHex.md Normal file
View File

14
elementManager.md Normal file
View File

@@ -0,0 +1,14 @@
## ElementManager.extendMethod()
## ElementManager.generateId()
## ElementManager.getElement()
## ElementManager.getElementList()
## ElementManager.loadElement()
## ElementManager.loadPlugin()
## ElementManager.registerPlugin()

2
errorManager.md Normal file
View File

@@ -0,0 +1,2 @@
## errorHandler.error()

1
expect.md Normal file
View File

@@ -0,0 +1 @@
Simple type checking without stack traces

View File

@@ -1,414 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Basalt Documentation</title>
<link rel="stylesheet" href="ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>Basalt 2</h1>
<h2>Contents</h2>
<ul>
<li><a href="#Class_Basalt">Class Basalt </a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><strong>basalt</strong></li>
</ul>
</div>
<div id="content">
<h1>Module <code>basalt</code></h1>
<p>Basalt UI Framework main module.</p>
<p> This is the main entry point for the Basalt UI Framework.
It provides functions for creating and managing UI elements and handling events.</p>
<h3>Usage:</h3>
<ul>
<pre class="example">local basalt = require(&quot;basalt&quot;)
local mainFrame = basalt.createFrame()
mainFrame:show()
basalt.run()
</pre>
</ul>
<h2><a href="#Class_Basalt">Class Basalt </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#basalt:create">basalt:create (type, id)</a></td>
<td class="summary">Creates and returns a new UI element of the specified type</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt:createFrame">basalt:createFrame ()</a></td>
<td class="summary">Creates and returns a new frame</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt:getElementManager">basalt:getElementManager ()</a></td>
<td class="summary">Returns the element manager instance</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt:getMainFrame">basalt:getMainFrame ()</a></td>
<td class="summary">Gets or creates the main frame</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt:setActiveFrame">basalt:setActiveFrame (frame)</a></td>
<td class="summary">Sets the active frame</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt:scheduleUpdate">basalt:scheduleUpdate (func)</a></td>
<td class="summary">Schedules a function to be updated</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt:removeSchedule">basalt:removeSchedule (id)</a></td>
<td class="summary">Removes a scheduled update</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt.updateEvent">basalt.updateEvent (event, ...)</a></td>
<td class="summary">Internal event handler</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt.renderFrames">basalt.renderFrames ()</a></td>
<td class="summary">Internal render function</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt:update">basalt:update ()</a></td>
<td class="summary">Updates all scheduled functions</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt:stop">basalt:stop ()</a></td>
<td class="summary">Stops the Basalt runtime</td>
</tr>
<tr>
<td class="name" nowrap><a href="#basalt:run">basalt:run (isActive)</a></td>
<td class="summary">Starts the Basalt runtime</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header has-description"><a name="Class_Basalt"></a>Class Basalt </h2>
<div class="section-description">
The main Basalt instance
Contains all core functionality and management functions
</div>
<dl class="function">
<dt>
<a name = "basalt:create"></a>
<strong>basalt:create (type, id)</strong>
</dt>
<dd>
Creates and returns a new UI element of the specified type
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">type</span>
string The type of element to create (e.g. "Button", "Label", "BaseFrame")
</li>
<li><span class="parameter">id</span>
? string Optional unique identifier for the element
</li>
</ul>
<h3>Returns:</h3>
<ol>
table element The created element instance
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> button = basalt.<span class="function-name">create</span>(<span class="string">"Button"</span>)</pre>
</ul>
</dd>
<dt>
<a name = "basalt:createFrame"></a>
<strong>basalt:createFrame ()</strong>
</dt>
<dd>
Creates and returns a new frame
<h3>Returns:</h3>
<ol>
table BaseFrame The created frame instance
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> mainFrame = basalt.<span class="function-name">createFrame</span>()</pre>
</ul>
</dd>
<dt>
<a name = "basalt:getElementManager"></a>
<strong>basalt:getElementManager ()</strong>
</dt>
<dd>
Returns the element manager instance
<h3>Returns:</h3>
<ol>
table ElementManager The element manager
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> manager = basalt.<span class="function-name">getElementManager</span>()</pre>
</ul>
</dd>
<dt>
<a name = "basalt:getMainFrame"></a>
<strong>basalt:getMainFrame ()</strong>
</dt>
<dd>
Gets or creates the main frame
<h3>Returns:</h3>
<ol>
BaseFrame table The main frame instance
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> frame = basalt.<span class="function-name">getMainFrame</span>()</pre>
</ul>
</dd>
<dt>
<a name = "basalt:setActiveFrame"></a>
<strong>basalt:setActiveFrame (frame)</strong>
</dt>
<dd>
Sets the active frame
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">frame</span>
table The frame to set as active
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">basalt.<span class="function-name">setActiveFrame</span>(myFrame)</pre>
</ul>
</dd>
<dt>
<a name = "basalt:scheduleUpdate"></a>
<strong>basalt:scheduleUpdate (func)</strong>
</dt>
<dd>
Schedules a function to be updated
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">func</span>
function The function to schedule
</li>
</ul>
<h3>Returns:</h3>
<ol>
number Id The schedule ID
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> id = basalt.<span class="function-name">scheduleUpdate</span>(myFunction)</pre>
</ul>
</dd>
<dt>
<a name = "basalt:removeSchedule"></a>
<strong>basalt:removeSchedule (id)</strong>
</dt>
<dd>
Removes a scheduled update
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">id</span>
number The schedule ID to remove
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">basalt.<span class="function-name">removeSchedule</span>(scheduleId)</pre>
</ul>
</dd>
<dt>
<a name = "basalt.updateEvent"></a>
<strong>basalt.updateEvent (event, ...)</strong>
</dt>
<dd>
Internal event handler
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">event</span>
</li>
<li><span class="parameter">...</span>
</li>
</ul>
</dd>
<dt>
<a name = "basalt.renderFrames"></a>
<strong>basalt.renderFrames ()</strong>
</dt>
<dd>
Internal render function
</dd>
<dt>
<a name = "basalt:update"></a>
<strong>basalt:update ()</strong>
</dt>
<dd>
Updates all scheduled functions
<h3>Usage:</h3>
<ul>
<pre class="example">basalt.<span class="function-name">update</span>()</pre>
</ul>
</dd>
<dt>
<a name = "basalt:stop"></a>
<strong>basalt:stop ()</strong>
</dt>
<dd>
Stops the Basalt runtime
<h3>Usage:</h3>
<ul>
<pre class="example">basalt.<span class="function-name">stop</span>()</pre>
</ul>
</dd>
<dt>
<a name = "basalt:run"></a>
<strong>basalt:run (isActive)</strong>
</dt>
<dd>
Starts the Basalt runtime
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">isActive</span>
boolean Whether to start active (default: true)
</li>
</ul>
<h3>Usage:</h3>
<ul>
<li><pre class="example">basalt.<span class="function-name">run</span>()</pre></li>
<li><pre class="example">basalt.<span class="function-name">run</span>(<span class="keyword">false</span>)</pre></li>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
<i style="float:right;">Last updated 2025-02-09 18:44:59 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

1
init.md Normal file
View File

@@ -0,0 +1 @@
Use xpcall with error handler

305
ldoc.css
View File

@@ -1,305 +0,0 @@
/* BEGIN RESET
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 2.8.2r1
*/
html {
color: #dfdfdf;
background: #1b1b1b;
}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td {
margin: 0;
padding: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fieldset,img {
border: 0;
}
address,caption,cite,code,dfn,em,strong,th,var,optgroup {
font-style: inherit;
font-weight: inherit;
}
del,ins {
text-decoration: none;
}
li {
list-style: bullet;
margin-left: 20px;
}
caption,th {
text-align: left;
}
h1,h2,h3,h4,h5,h6 {
font-size: 100%;
font-weight: bold;
}
q:before,q:after {
content: '';
}
abbr,acronym {
border: 0;
font-variant: normal;
}
sup {
vertical-align: baseline;
}
sub {
vertical-align: baseline;
}
legend {
color: #000;
}
input,button,textarea,select,optgroup,option {
font-family: inherit;
font-size: inherit;
font-style: inherit;
font-weight: inherit;
}
input,button,textarea,select {*font-size:100%;}
/* END RESET */
body {
margin-left: 1em;
margin-right: 1em;
font-family: arial, helvetica, geneva, sans-serif;
background-color: #1a1a1a;
color: #e0e0e0;
}
code, tt {
font-family: monospace;
color: #88ccff;
}
body, p, td, th { font-size: .95em; line-height: 1.2em;}
p, ul { margin: 10px 0 0 10px;}
strong { font-weight: bold;}
em { font-style: italic;}
h1 {
font-size: 1.5em;
margin: 0 0 20px 0;
color: #ffffff;
}
h2, h3, h4 { margin: 15px 0 10px 0; color: #ffffff; }
h2 { font-size: 1.25em; }
h3 { font-size: 1.15em; }
h4 { font-size: 1.06em; }
a:link { font-weight: bold; color: #66b3ff; text-decoration: none; }
a:visited { font-weight: bold; color: #b366ff; text-decoration: none; }
a:link:hover { text-decoration: underline; }
hr {
color: #c9c9c9;
background: #444444;
height: 1px;
}
blockquote { margin-left: 3em; }
ul { list-style-type: disc; }
p.name {
font-family: "Andale Mono", monospace;
padding-top: 1em;
}
pre.example {
background-color: #2d2d2d;
border: 1px solid #444444;
padding: 10px;
margin: 10px 0 10px 0;
font-family: "Andale Mono", monospace;
font-size: .85em;
color: #e0e0e0;
}
pre {
background-color: #2d2d2d;
border: 1px solid #444444;
padding: 10px;
margin: 10px 0 10px 0;
font-family: "Andale Mono", monospace;
color: #e0e0e0;
}
table.index { border: 1px #00007f; }
table.index td { text-align: left; vertical-align: top; }
#container {
margin-left: 1em;
margin-right: 1em;
background-color: #242424;
}
#product {
text-align: center;
border-bottom: 1px solid #cccccc;
background-color: #3a3a3a;
}
#product big {
font-size: 2em;
}
#main {
background-color: #131313;
border-left: 2px solid #cccccc;
}
#navigation {
float: left;
width: 14em;
vertical-align: top;
background-color: #2d2d2d;
overflow: visible;
}
#navigation h2 {
background-color: #333333;
font-size: 1.1em;
color: #ffffff;
text-align: left;
padding: 0.2em;
border-top: 1px solid #444444;
border-bottom: 1px solid #444444;
}
#navigation ul
{
font-size: 1em;
list-style-type: none;
margin: 1px 1px 10px 1px;
}
#navigation li {
text-indent: -1em;
display: block;
margin: 3px 0px 0px 22px;
}
#navigation li li a {
margin: 0px 3px 0px -1em;
}
#content {
margin-left: 14em;
width: 40em;
padding: 1em;
border-left: 2px solid #444444;
border-right: 2px solid #444444;
background-color: #242424;
}
#about {
clear: both;
padding: 5px;
border-top: 2px solid #cccccc;
background-color: #202020;
}
@media print {
body {
font: 12pt "Times New Roman", "TimeNR", Times, serif;
}
a { font-weight: bold; color: #004080; text-decoration: underline; }
#main {
background-color: #1d1a1a;
border-left: 0px;
}
#container {
margin-left: 2%;
margin-right: 2%;
background-color: #1b1a1a;
}
#content {
padding: 1em;
background-color: #1d1a1a;
}
#navigation {
display: none;
}
pre.example {
font-family: "Andale Mono", monospace;
font-size: 10pt;
page-break-inside: avoid;
}
}
table.module_list td {
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: #444444;
}
table.module_list td.name { background-color: #333333; }
table.module_list td.summary { width: 100%; }
table.file_list {
border-width: 1px;
border-style: solid;
border-color: #444444;
border-collapse: collapse;
}
table.file_list td {
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: #444444;
}
table.file_list td.name { background-color: #333333; }
table.file_list td.summary { width: 100%; }
table.function_list {
border-width: 1px;
border-style: solid;
border-color: #444444;
border-collapse: collapse;
}
table.function_list td {
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: #444444;
}
table.function_list td.name { background-color: #333333; }
table.function_list td.summary { width: 100%; }
table.table_list {
border-width: 1px;
border-style: solid;
border-color: #444444;
border-collapse: collapse;
}
table.table_list td {
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: #444444;
}
table.table_list td.name { background-color: #333333; }
table.table_list td.summary { width: 100%; }
dl.table dt, dl.function dt {border-top: 1px solid #444444; padding-top: 1em;}
dl.table dd, dl.function dd {padding-bottom: 1em; margin: 10px 0 0 20px;}
dl.table h3, dl.function h3 {font-size: .95em;}

7
log.md Normal file
View File

@@ -0,0 +1,7 @@
Log levels
## Log.error()
## Log.setEnabled()
## Log.setLogToFile()

139
main.md Normal file
View File

@@ -0,0 +1,139 @@
# 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".
## Functions
|Method|Returns|Description|
|---|---|---|
|[basalt.create](#basalt.create)|table|Creates a new UI element
|[basalt.createFrame](#basalt.createFrame)|table|
|[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.create(type, id?)
Creates and returns a new UI element of the specified type
### Parameters
* `type` `string` The type of element to create (e.g. "Button", "Label", "BaseFrame")
* `id` *(optional)* `string` Optional unique identifier for the element
### Returns
* `table` `element` The created element instance
### Usage
```lua
local button = basalt.create("Button")
```
## basalt.createFrame()
Creates and returns a new frame
### Returns
* `table` `BaseFrame` The created frame instance
### Usage
```lua
local mainFrame = basalt.createFrame()
```
## basalt.getElementManager()
Returns the element manager instance
### Returns
* `table` `ElementManager` The element manager
### Usage
```lua
local manager = basalt.getElementManager()
```
## basalt.getMainFrame()
Gets or creates the main frame
### Returns
* `BaseFrame` `table` The main frame instance
### Usage
```lua
local frame = basalt.getMainFrame()
```
## basalt.removeSchedule(id)
Removes a scheduled update
### Parameters
* `id` `number` The schedule ID to remove
### Usage
```lua
basalt.removeSchedule(scheduleId)
```
## basalt.run(isActive)
Starts the Basalt runtime
### Parameters
* `isActive` `boolean` Whether to start active (default: true)
### Usage
```lua
basalt.run()
basalt.run(false)
```
## basalt.scheduleUpdate(func)
Schedules a function to be updated
### Parameters
* `func` `function` The function to schedule
### Returns
* `number` `Id` The schedule ID
### Usage
```lua
local id = basalt.scheduleUpdate(myFunction)
```
## basalt.setActiveFrame(frame)
Sets the active frame
### Parameters
* `frame` `table` The frame to set as active
### Usage
```lua
basalt.setActiveFrame(myFrame)
```
## basalt.stop()
Stops the Basalt runtime
### Usage
```lua
basalt.stop()
```
## basalt.update()
Updates all scheduled functions
### Usage
```lua
basalt.update()
```

8
propertySystem.md Normal file
View File

@@ -0,0 +1,8 @@
## PropertySystem.defineProperty()
## PropertySystem:__init()
## PropertySystem:_updateProperty()
## PropertySystem:observe()

22
render.md Normal file
View File

@@ -0,0 +1,22 @@
## Render.new()
## Render:bg()
## Render:blit()
## Render:clear()
## Render:clearArea()
## Render:fg()
## Render:getSize()
## Render:multiBlit()
## Render:render()
## Render:text()
## Render:textFg()

4
utils.md Normal file
View File

@@ -0,0 +1,4 @@
## utils.deepCopy()
## utils.getCenteredPosition()