From 8157c025ea670d3e4ac6d1462a8efa1a29422b50 Mon Sep 17 00:00:00 2001
From: Robert Jelic <36573031+NoryiE@users.noreply.github.com>
Date: Mon, 18 Jul 2022 13:58:43 +0200
Subject: [PATCH] docs again
---
Basalt/main.lua | 34 +++-
Basalt/objects/Program.lua | 4 +-
Basalt/objects/Progressbar.lua | 3 -
Basalt/objects/example.lua | 47 ------
docs/objects/Basalt.md | 91 +++++++++--
docs/objects/Button.md | 3 -
docs/objects/Input.md | 1 -
docs/objects/List.md | 276 ++++++++++++++++++++++++---------
docs/objects/Object.md | 35 ++---
docs/objects/Program.md | 48 +++---
docs/objects/Radio.md | 251 +++++++++++++++++++++---------
docs/objects/Thread.md | 2 +-
12 files changed, 535 insertions(+), 260 deletions(-)
delete mode 100644 Basalt/objects/example.lua
diff --git a/Basalt/main.lua b/Basalt/main.lua
index 7d3d554..cf1cefe 100644
--- a/Basalt/main.lua
+++ b/Basalt/main.lua
@@ -9,7 +9,7 @@ local debugger = true
local projectDirectory = fs.getDir(table.pack(...)[2] or "")
-local activeKey, frames, monFrames, variables = {}, {}, {}, {}
+local activeKey, frames, monFrames, variables, shedules = {}, {}, {}, {}, {}
local mainFrame, activeFrame, focusedObject, updaterActive
if not term.isColor or not term.isColor() then
@@ -85,6 +85,27 @@ local bInstance = {
end
}
+local function handleShedules(event, p1, p2, p3, p4)
+ if(#shedules>0)then
+ local finished = {}
+ for n=1,#shedules do
+ if(shedules[n]~=nil)then
+ if (coroutine.status(shedules[n]) == "suspended")then
+ local ok, result = coroutine.resume(shedules[n], event, p1, p2, p3, p4)
+ if not(ok)then
+ table.insert(finished, n)
+ end
+ else
+ table.insert(finished, n)
+ end
+ end
+ end
+ for n=1,#finished do
+ table.remove(shedules, finished[n]-(n-1))
+ end
+ end
+end
+
local function drawFrames()
if(updaterActive)then
if(mainFrame~=nil)then
@@ -139,6 +160,7 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
for _, v in pairs(frames) do
v:eventHandler(event, p1, p2, p3, p4)
end
+ handleShedules(event, p1, p2, p3, p4)
drawFrames()
end
@@ -207,6 +229,16 @@ basalt = {
end
end
end,
+
+ shedule = function(f)
+ assert(f~="function", "Shedule needs a function in order to work!")
+ local co = coroutine.create(f)
+ local ok, result = coroutine.resume(co)
+ if(ok)then
+ table.insert(shedules, co)
+ end
+ return co
+ end,
createFrame = function(name)
name = name or uuid()
diff --git a/Basalt/objects/Program.lua b/Basalt/objects/Program.lua
index 1d51370..d7569cd 100644
--- a/Basalt/objects/Program.lua
+++ b/Basalt/objects/Program.lua
@@ -473,8 +473,8 @@ return function(name, parent)
end;
execute = function(self, path, ...)
- cachedPath = path
- curProcess = process:new(path, pWindow, ...)
+ cachedPath = path or cachedPath
+ curProcess = process:new(cachedPath, pWindow, ...)
pWindow.setBackgroundColor(colors.black)
pWindow.setTextColor(colors.white)
pWindow.clear()
diff --git a/Basalt/objects/Progressbar.lua b/Basalt/objects/Progressbar.lua
index 35f010f..13b4177 100644
--- a/Basalt/objects/Progressbar.lua
+++ b/Basalt/objects/Progressbar.lua
@@ -36,9 +36,6 @@ return function(name)
if(xmlValue("progressSymbol", data)~=nil)then activeBarSymbol = xmlValue("progressSymbol", data) end
if(xmlValue("backgroundSymbol", data)~=nil)then bgBarSymbol = xmlValue("backgroundSymbol", data) end
if(xmlValue("progressSymbolColor", data)~=nil)then activeBarSymbolCol = colors[xmlValue("progressSymbolColor", data)] end
- if(xmlValue("scrollable", data)~=nil)then if(xmlValue("scrollable", data))then self:setScrollable(true) else self:setScrollable(false) end end
- if(xmlValue("offset", data)~=nil)then self:setOffset(xmlValue("offset", data)) end
- if(xmlValue("space", data)~=nil)then space = xmlValue("space", data) end
if(xmlValue("onDone", data)~=nil)then self:onProgressDone(baseFrame:getVariable(xmlValue("onDone", data))) end
return self
end,
diff --git a/Basalt/objects/example.lua b/Basalt/objects/example.lua
deleted file mode 100644
index 0717d05..0000000
--- a/Basalt/objects/example.lua
+++ /dev/null
@@ -1,47 +0,0 @@
-local Object = require("Object")
-
-return function(name)
- local base = Object(name) -- this will load the base object class, it is necessary if you want to make a visual object, otherwise you dont need that.
- local objectType = "Example" -- here is the object type, make sure it is the same as the file name - this way you can also make sure its unique
-
- -- here you could set some default values, but its not necessary, it doesn't matter if you call the functions or change the values directly, maybe i should change that
- --i guess its better if you call functions base:setBackground, base:setSize and so on.
- base.width = 12
- base.height = 1
- base.bgColor = colors.lightGray
- base.fgColor = colors.gray
- base:setValue(false)
- base:setZIndex(5) -- if you want to change the zIndex always use the function
-
- local object = { -- here you start your unique object class, please always make sure a getType exists!
- getType = function(self)
- return objectType
- end;
-
-
- mouseClickHandler = function(self, event, button, x, y) -- this is your extended mouseClickHandler, if you want something to happen if the user clicks on that
- if (base.mouseClickHandler(self, event, button, x, y)) then -- here you access the base class mouseClickHandler it will return true if the user really clicks on the object
- local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) --getAnchorPosition is obviously for returning the x and y coords changed by the anchor system, absolute position explains itself i guess
- if ((event == "mouse_click") or (event == "mouse_drag")) and (button == 1) then
- --here you can create your logic
- end
- return true -- please always return true if base.mouseClickHandler also returns true, otherwise your object wont get focused.
- end
- end;
-
- draw = function(self) -- if your object is visual, you will need a draw function
- if (base.draw(self)) then
- if (self.parent ~= nil) then
- local obx, oby = self:getAnchorPosition()
- --self.parent:drawBackgroundbox(obx, oby, self.width, self.height, self.bgColor) -- changes the background color of that object
- --self.parent:drawForegroundbox(obx, oby, self.width, self.height, self.fgColor) -- changes the foreground (textcolor) color of that object
- --self.parent:writeText(obx, oby, "Some Text", self.bgColor, self.fgColor) -- writes something on the screen, also able to change its bgcolor and fgcolor
-
- --the draw functions always gets called after something got visually changed. I am always redrawing the entire screen, but only if something has changed.
- end
- end
- end;
- }
-
- return setmetatable(object, base) -- required
-end
\ No newline at end of file
diff --git a/docs/objects/Basalt.md b/docs/objects/Basalt.md
index abaf32f..bd7ab63 100644
--- a/docs/objects/Basalt.md
+++ b/docs/objects/Basalt.md
@@ -15,7 +15,7 @@ Create a base-frame (main frame)
#### Usage:
* Create and show a frame with id "myFirstFrame"
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame("myFirstFrame")
```
## basalt.removeFrame
@@ -27,7 +27,7 @@ Removes a base frame
#### Usage:
* Removes the previously created frame with id "myFirstFrame"
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame("myFirstFrame")
basalt.removeFrame("myFirstFrame")
```
@@ -42,7 +42,7 @@ Returns a base frame with the given name
#### Usage:
* Creates, fetches and shows the "myFirstFrame" object
```lua
-basalt.createFrame("myFirstFrame")
+basalt.createFrame("myFirstFrame"):hide()
basalt.getFrame("myFirstFrame"):show()
```
@@ -56,8 +56,8 @@ Returns the currently active base frame
#### Usage:
* Displays the active frame name in the debug console
```lua
-basalt.createFrame("myFirstFrame"):show()
-basalt.debug(basalt.getActiveFrame():getName()) -- returns myFirstFrame
+basalt.createFrame()
+basalt.debug(basalt.getActiveFrame():getName()) -- returns the uuid
```
## basalt.autoUpdate
@@ -66,7 +66,7 @@ Starts the draw and event handler until basalt.stopUpdate() is called
#### Usage:
* Enable the basalt updates, otherwise the screen will not continue to update
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame()
basalt.autoUpdate()
```
@@ -81,8 +81,8 @@ Calls the draw and event handler once - this gives more flexibility about which
#### Usage:
* Creates and starts a custom update cycle
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aButton = mainFrame:addButton("myButton"):setPosition(2,2):show()
+local mainFrame = basalt.createFrame()
+local aButton = mainFrame:addButton():setPosition(2,2)
while true do
basalt.update(os.pullEventRaw())
@@ -95,8 +95,8 @@ Stops the automatic draw and event handler which got started by basalt.autoUpdat
#### Usage:
* When the quit button is clicked, the button stops basalt auto updates
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aButton = mainFrame:addButton("myButton"):setPosition(2,2):setText("Stop Basalt!"):show()
+local mainFrame = basalt.createFrame()
+local aButton = mainFrame:addButton():setPosition(2,2):setText("Stop Basalt!")
aButton:onClick(function()
basalt.stopUpdate()
@@ -117,8 +117,8 @@ Checks if the user is currently holding a key
#### Usage:
* Shows a debug message with true or false if the left ctrl key is down, as soon as you click on the button.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aButton = mainFrame:addButton("myButton"):setPosition(2,2):setText("Check Ctrl"):show()
+local mainFrame = basalt.createFrame()
+local aButton = mainFrame:addButton():setPosition(2,2):setText("Check Ctrl")
aButton:onClick(function()
basalt.debug(basalt.isKeyDown(keys.leftCtrl) )
@@ -136,10 +136,75 @@ which returns the debug Label.
Also basalt.debugFrame and basalt.debugList are available.
#### Parameters:
-1. `...` (multiple parameters are possible, like print does)
+1. `...` (multiple parameters are possible, like print does)
#### Usage:
* Prints "Hello! ^-^" to the debug console
```lua
basalt.debug("Hello! ", "^-^")
```
+
+## setTheme
+Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua)
+
+#### Parameters:
+1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
+
+#### Usage:
+* Creates a new base frame and adds a new theme which only changes the default color of buttons.
+```lua
+basalt.setTheme({
+ ButtonBG = colors.yellow,
+ ButtonText = colors.red,
+ ...,
+})
+```
+
+## setVariable
+This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML.
+
+#### Parameters:
+1. `string` a key name
+1. `any` any variable
+
+#### Usage:
+* Adds a function to basalt.
+```lua
+basalt.setVariable("clickMe", function()
+ basalt.debug("I got clicked")
+end)
+```
+```xml
+
+```
+
+## shedule
+Shedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
+
+#### Parameters:
+1. `function` a function which should get executed
+
+#### Returns:
+1. `coroutine` it returns the coroutine which got created to execute the function
+
+#### Usage:
+* Creates a shedule which switches the color between red and gray
+```lua
+local mainFrame = basalt.createFrame()
+local aButton = mainFrame:addButton():setText("Click me")
+aButton:onClick(function()
+ basalt.shedule(function()
+ aButton:setBackground(colors.red)
+ os.sleep(0.1)
+ aButton:setBackground(colors.gray)
+ os.sleep(0.1)
+ aButton:setBackground(colors.red)
+ os.sleep(0.1)
+ aButton:setBackground(colors.gray)
+ os.sleep(0.1)
+ aButton:setBackground(colors.red)
+ os.sleep(0.1)
+ aButton:setBackground(colors.gray)
+ end)
+end)
+```
\ No newline at end of file
diff --git a/docs/objects/Button.md b/docs/objects/Button.md
index d00ab3c..425981a 100644
--- a/docs/objects/Button.md
+++ b/docs/objects/Button.md
@@ -16,7 +16,6 @@ Sets the displayed button text
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton():setText("Click me!")
```
-
```xml
```
@@ -38,7 +37,6 @@ local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
```
-
```xml
```
@@ -88,7 +86,6 @@ basalt.setVariable("buttonClick", function(self,event,button,x,y)
end
end)
```
-
```xml
```
\ No newline at end of file
diff --git a/docs/objects/Input.md b/docs/objects/Input.md
index 09ba0e9..a89eedd 100644
--- a/docs/objects/Input.md
+++ b/docs/objects/Input.md
@@ -18,7 +18,6 @@ Changes the input type. default: text
local mainFrame = basalt.createFrame()
local aInput = mainFrame:addInput():setInputType("number")
```
-
```xml
```
diff --git a/docs/objects/List.md b/docs/objects/List.md
index 4774494..c9dfb8c 100644
--- a/docs/objects/List.md
+++ b/docs/objects/List.md
@@ -1,151 +1,279 @@
-Lists are objects where you can create endless entrys and the user can choose one of them
+Lists are objects where you can create endless entries, and the user is able to select one of them
-Here is a example of how to create a standard list:
+If you want to access values inside items this is how the table for single items is made (just a example):
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aList = mainFrame:addList("myFirstList"):show()
+item = {
+ text="1. Entry",
+ bgCol=colors.black,
+ fgCol=colors.white
+ args = {}
+}
```
-This will create a default list with the size 8 width and 5 height on position 1 1 (relative to its parent frame), the default background is colors.lightGray, the default text color is colors.black and the default zIndex is 5. The default horizontal text align is "center", default symbol is ">"
-
-Here are all possible functions available for lists. Remember List inherits from [Object](objects/Object.md)
+Remember Lists also inherits from [Object](objects/Object.md)
## addItem
Adds a item into the list
+#### Parameters:
+1. `string` The entry name
+2. `number|color` unique default background color - optional
+3. `number|color` unique default text color - optional
+4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default list with 3 entries
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aList = mainFrame:addList("myFirstList"):show()
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
```
-#### Parameters: string text, number bgcolor, number fgcolor, any ... - (text is the displayed text, bgcolor and fgcolors the colors of background/text and args (...) is something dynamic, you wont see them but if you require some more information per item you can use that)
-#### Returns: self
+```xml
+
+ 1. Entry
+ 2. Entryyellow
+ 3. Entryyellowgreen
+
+```
## removeItem
Removes a item from the list
+#### Parameters:
+1. `number` The index which should get removed
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default list with 3 entries and removes the second one.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aList = mainFrame:addList("myFirstList"):show()
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:removeItem(2)
```
-#### Parameters: number index
-#### Returns: self
## editItem
-Edits a item on the list
+Edits a item from the list
+#### Parameters:
+1. `number` The index which should be edited
+2. `string` The new item name
+3. `number` the new item background color - optional
+4. `number` The new item text color - optional
+5. `any` New additional information - optional
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default list with 3 entries and changes the second one.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aList = mainFrame:addList("myFirstList"):show()
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
-aList:editItem(3,"3. Edited Entry",colors.yellow,colors.green)
+aList:editItem(2, "Still 2. Entry", colors.red)
```
-#### Parameters: number index, string text, number bgcolor, number fgcolor, any ...
-#### Returns: self
-## setScrollable
-Makes the list scrollable
+## getItem
+Returns a item by index
+#### Parameters:
+1. `number` The index which should be returned
+
+#### Returns:
+1. `table` The item table example: {text="1. Entry", bgCol=colors.black, fgCol=colors.white}
+
+#### Usage:
+* Creates a default list with 3 entries and edits the second one.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aList = mainFrame:addList("myFirstList"):show()
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
-aList:setScrollable(true)
+basalt.debug(aList:getItem(2).text)
+```
+
+## getItemCount
+Returns the current item count
+
+#### Returns:
+1. `number` The item list count
+
+#### Usage:
+* Creates a default list with 3 entries and prints the current item count.
+```lua
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
+aList:addItem("1. Entry")
+aList:addItem("2. Entry",colors.yellow)
+aList:addItem("3. Entry",colors.yellow,colors.green)
+basalt.debug(aList:getItemCount())
+```
+
+## getAll
+Returns all items as table
+
+#### Returns:
+1. `table` All items
+
+#### Usage:
+* Creates a default menubar with 3 entries and prints a table.
+```lua
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
+aList:addItem("1. Entry")
+aList:addItem("2. Entry",colors.yellow)
+aList:addItem("3. Entry",colors.yellow,colors.green)
+basalt.debug(aList:getAll())
```
-#### Parameters: boolean isScrollable
-#### Returns: self
## selectItem
selects a item in the list (same as a player would click on a item)
+#### Parameters:
+1. `number` The index which should get selected
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default list with 3 entries and selects the second entry.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aList = mainFrame:addList("myFirstList"):show()
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
-aList:selectItem(1)
+aList:selectItem(2)
```
-#### Parameters: number index
-#### Returns: self
## clear
-clears the entire list
+Removes all items.
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default list with 3 entries and removes them immediatley. Which makes no sense.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
-aDropdown:addItem("1. Entry")
-aDropdown:addItem("2. Entry",colors.yellow)
-aDropdown:addItem("3. Entry",colors.yellow,colors.green)
-aDropdown:clear()
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
+aList:addItem("1. Entry")
+aList:addItem("2. Entry",colors.yellow)
+aList:addItem("3. Entry",colors.yellow,colors.green)
+aList:clear()
```
-#### Parameters: -
-#### Returns: self
## getItemIndex
returns the item index of the currently selected item
+#### Returns:
+1. `number` The current index
+
+#### Usage:
+* Creates a default list with 3 entries selects the second entry and prints the currently selected index.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
-aDropdown:addItem("1. Entry")
-aDropdown:addItem("2. Entry",colors.yellow)
-aDropdown:addItem("3. Entry",colors.yellow,colors.green)
-aDropdown:getItemIndex()
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
+aList:addItem("1. Entry")
+aList:addItem("2. Entry",colors.yellow)
+aList:addItem("3. Entry",colors.yellow,colors.green)
+aList:selectItem(2)
+basalt.debug(aList:getItemIndex())
```
-#### Parameters: -
-#### Returns: number index
## setSelectedItem
-Sets the background of the item which is currently selected
+Sets the background and the foreground of the item which is currently selected
+#### Parameters:
+1. `number|color` The background color which should be used
+2. `number|color` The text color which should be used
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default list with 4 entries and sets the selection background color to green.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aList = mainFrame:addList("myFirstList"):show()
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
-aList:setSelectedItem(colors.green, colors.blue)
+aList:addItem("4. Entry")
+aList:setSelectedItem(colors.green, colors.red)
+```
+```xml
+
+ 1. Entry
+ 2. Entryyellow
+ 2. Entryyellowgreen
+
```
-#### Parameters: number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)
-#### Returns: self
## setOffset
-sets the list offset (will automatically change if scrolling is active)
+Sets the offset of the list (the same as you would scroll) - default is 0
+#### Parameters:
+1. `number` The offset value
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default list with 6 entries and sets the offset to 3.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aList = mainFrame:addList("myFirstList"):show()
-aList:addItem("1. Entry")
-aList:addItem("2. Entry",colors.yellow)
-aList:addItem("3. Entry",colors.yellow,colors.green)
-aList:setOffset(3)
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
+ :addItem("1. Entry")
+ :addItem("2. Entry")
+ :addItem("3. Entry")
+ :addItem("4. Entry")
+ :addItem("5. Entry")
+ :addItem("6. Entry")
+ :setOffset(3)
+```
+```xml
+
+ 1. Entry
+ 2. Entry
+ 3. Entry
+ 4. Entry
+ 5. Entry
+ 6. Entry
+
```
-#### Parameters: number offsetValue
-#### Returns: self
## getOffset
-returns the current offset
+Returns the current index offset
+#### Returns:
+1. `number` offset value
+
+#### Usage:
+* Creates a default list with 6 entries and sets the offset to 3, also prints the current offset.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aList = mainFrame:addList("myFirstList"):show()
-aList:addItem("1. Entry")
-aList:addItem("2. Entry",colors.yellow)
-aList:addItem("3. Entry",colors.yellow,colors.green)
-aList:getOffset()
+local mainFrame = basalt.createFrame()
+local aList = mainFrame:addList()
+ :addItem("1. Entry")
+ :addItem("2. Entry")
+ :addItem("3. Entry")
+ :addItem("4. Entry")
+ :addItem("5. Entry")
+ :addItem("6. Entry")
+ :setOffset(3)
+basalt.debug(aList:getOffset())
```
-#### Parameters: -
-#### Returns: number offsetValue
\ No newline at end of file
diff --git a/docs/objects/Object.md b/docs/objects/Object.md
index fbb5eec..86bb4f0 100644
--- a/docs/objects/Object.md
+++ b/docs/objects/Object.md
@@ -1,4 +1,4 @@
-This is the base class of all visual objects. This means, if you create a button, label, frame or something else visual (no timers, threads or animations) the following methods apply:
+This is the base class for all visual objects. Which means, if you create a button, label, frame or something else (no timers, threads or animations) the following methods apply:
## show
Shows the object (only if the parent frame is already visible)
@@ -8,12 +8,12 @@ Shows the object (only if the parent frame is already visible)
#### Usage:
* Shows a frame
```lua
-local mainFrame = basalt.createFrame():show()
+local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
button:show()
```
```xml
-
+
```
## hide
@@ -27,10 +27,9 @@ Hides the object
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton():setText("Close"):onClick(function() mainFrame:hide() end)
-button
```
```xml
-
+
```
## setPosition
@@ -50,7 +49,7 @@ local mainFrame = basalt.createFrame()
mainFrame:addButton():setPosition(2,3)
```
```xml
-
+
```
## setBackground
@@ -67,7 +66,7 @@ Changes the object background color, if you set the value to false the backgroun
local mainFrame = basalt.createFrame():setBackground(colors.gray)
```
```xml
-
+
```
## setForeground
@@ -84,7 +83,7 @@ Changes the object text color
local mainFrame = basalt.createFrame():setForeground(colors.green)
```
```xml
-
+
```
## setSize
@@ -103,7 +102,7 @@ local mainFrame = basalt.createFrame()
local subFrame = mainFrame:addFrame():setSize(15,12)
```
```xml
-
+
```
## setFocus
@@ -136,8 +135,8 @@ local aButton = mainFrame:addButton():setZIndex(1):setPosition(2,2)
local aLabel = mainFrame:addButton():setZIndex(2):setPosition(2,2):setText("I am a label!")
```
```xml
-
-
+
+
```
## setParent
@@ -214,10 +213,8 @@ local aButton = mainFrame:addButton()
:setSize(8,1)
:setPosition(-8,1)
```
-
-#### XML:
```xml
-
+
```
## getAbsolutePosition
@@ -252,7 +249,7 @@ local mainFrame = basalt.createFrame()
local aCheckbox = mainFrame:addCheckbox():setValue(true)
```
```xml
-
+
```
## getValue
@@ -327,7 +324,7 @@ local subFrame = mainFrame:addFrame()
:showShadow(true)
```
```xml
-
+
```
## showShadow
@@ -349,7 +346,7 @@ local subFrame = mainFrame:addFrame()
:showShadow(true)
```
```xml
-
+
```
## setBorder
@@ -372,7 +369,7 @@ local subFrame = mainFrame:addFrame()
:showBorder("left", "top", "right", "bottom")
```
```xml
-
+
```
## showBorder
@@ -394,5 +391,5 @@ local subFrame = mainFrame:addFrame()
:showBorder("left", "top", "bottom")
```
```xml
-
+
```
\ No newline at end of file
diff --git a/docs/objects/Program.md b/docs/objects/Program.md
index 595750c..3bc2ba2 100644
--- a/docs/objects/Program.md
+++ b/docs/objects/Program.md
@@ -13,8 +13,8 @@ returns the current process status
#### Usage:
* Prints current status
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aProgram = mainFrame:addProgram("myFirstProgram"):show()
+local mainFrame = basalt.createFrame()
+local aProgram = mainFrame:addProgram()
basalt.debug(aProgram:getStatus())
```
@@ -30,8 +30,8 @@ Executes the given path or program
#### Usage:
* Executes worm
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aProgram = mainFrame:addProgram("myFirstProgram"):show()
+local mainFrame = basalt.createFrame()
+local aProgram = mainFrame:addProgram()
aProgram:execute("rom/programs/fun/worm.lua") -- executes worm
```
```xml
@@ -47,10 +47,10 @@ Stops a currently running program
#### Usage:
* Stops worm by clicking a button
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aProgram = mainFrame:addProgram("myFirstProgram"):show()
+local mainFrame = basalt.createFrame()
+local aProgram = mainFrame:addProgram()
aProgram:execute("rom/programs/fun/worm.lua") -- executes worm
-mainFrame:addButton("myFirstButton"):setText("Pause"):onClick(function() aProgram:stop() end):show()
+mainFrame:addButton():setText("Pause"):onClick(function() aProgram:stop() end):show()
```
## pause
@@ -65,9 +65,9 @@ pauses the current program (prevents the program from receiving events)
#### Usage:
* Pauses worm by clicking a button
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show()
-mainFrame:addButton("myFirstButton"):setText("Pause"):onClick(function() aProgram:pause(true) end):show()
+local mainFrame = basalt.createFrame():show()
+local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
+mainFrame:addButton():setText("Pause"):onClick(function() aProgram:pause(true) end):show()
```
## isPaused
@@ -79,8 +79,8 @@ returns if the program is paused
#### Usage:
* Prints the pause status of the program
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show()
+local mainFrame = basalt.createFrame():show()
+local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
basalt.debug(aProgram:isPaused())
```
@@ -101,9 +101,9 @@ injects a event into the program manually. For example you could inject w a s an
#### Usage:
* injects a event by clicking a button
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show()
-mainFrame:addButton("myFirstButton"):setText("inject"):onClick(function() aProgram:injectEvent("char", "w") end):show()
+local mainFrame = basalt.createFrame():show()
+local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
+mainFrame:addButton():setText("inject"):onClick(function() aProgram:injectEvent("char", "w") end):show()
```
## injectEvents
@@ -119,15 +119,15 @@ Injects multiple events
* injects a multiple char events by clicking a button
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show()
+local mainFrame = basalt.createFrame():show()
+local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
local events = {
{event="char", args={"h"}},
{event="char", args={"e"}},
{event="char", args={"y"}}
}
-mainFrame:addButton("myFirstButton"):setText("inject"):onClick(function() aProgram:injectEvents(events) end):show()
+mainFrame:addButton():setText("inject"):onClick(function() aProgram:injectEvents(events) end):show()
```
@@ -140,9 +140,9 @@ If the program is paused, incomming events will be inserted into a queued events
#### Usage:
* prints the queued events table
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show()
-mainFrame:addButton("myFirstButton"):setText("inject"):onClick(function() basalt.debug(aProgram:getQueuedEvents()) end):show()
+local mainFrame = basalt.createFrame():show()
+local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
+mainFrame:addButton():setText("inject"):onClick(function() basalt.debug(aProgram:getQueuedEvents()) end):show()
```
## updateQueuedEvents
@@ -155,10 +155,10 @@ Here you can manipulate the queued events table
1. `object` The object in use
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show()
+local mainFrame = basalt.createFrame():show()
+local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
-mainFrame:addButton("myFirstButton"):setText("inject"):onClick(function()
+mainFrame:addButton():setText("inject"):onClick(function()
local events = aProgram:getQueuedEvents()
table.insert(events,1,{event="char", args={"w"}}
aProgram:updateQueuedEvents(events)
diff --git a/docs/objects/Radio.md b/docs/objects/Radio.md
index d95063b..41f1079 100644
--- a/docs/objects/Radio.md
+++ b/docs/objects/Radio.md
@@ -1,122 +1,229 @@
-Radios are objects where you can create endless entrys the user can click on a button and it opens a "list" where the user can choose a entry
+Radios are objects which you can freely place, and the user is then able to select a single item.
-Here is an example of how to create a standard radio:
+If you want to access values inside items this is how the table for single items is made (just a example):
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aRadio = mainFrame:addRadio("myFirstRadio"):show()
+item = {
+ text="1. Entry",
+ bgCol=colors.black,
+ fgCol=colors.white
+ args = {}
+}
```
-Here are all possible functions available for radios:
-Remember Radio inherits from [Object](objects/Object.md)
+Remember Radios also inherits from [Object](objects/Object.md)
## addItem
Adds a item to the radio
+#### Parameters:
+1. `string` The entry name
+2. `number` x position
+3. `number` y position
+2. `number|color` unique default background color - optional
+3. `number|color` unique default text color - optional
+4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default radio with 3 entries
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aRadio = mainFrame:addRadio("myFirstRadio"):show()
-aRadio:addItem("1. Entry",3,4)
-aRadio:addItem("2. Entry",3,5,colors.yellow)
-aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
+local mainFrame = basalt.createFrame()
+local aRadio = mainFrame:addRadio()
+aRadio:addItem("1. Entry",5,2)
+aRadio:addItem("2. Entry",5,4,colors.yellow)
+aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
+```
+```xml
+
+ 1. Entry52
+ 2. Entry54yellow
+ 3. Entry56yellowgreen
+
```
-#### Parameters: string text, number x, number y, number bgcolor, number fgcolor, any ... - (text is the displayed text, bgcolor and fgcolors the colors of background/text and args (...) is something dynamic, you wont see them but if you require some more information per item you can use that)
-#### Returns: self
## removeItem
Removes a item from the radio
+#### Parameters:
+1. `number` The index which should get removed
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default radio with 3 entries and removes the second one.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aRadio = mainFrame:addRadio("myFirstRadio"):show()
-aRadio:addItem("1. Entry",3,4)
-aRadio:addItem("2. Entry",3,5,colors.yellow)
-aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
+local mainFrame = basalt.createFrame()
+local aRadio = mainFrame:addRadio()
+aRadio:addItem("1. Entry",5,2)
+aRadio:addItem("2. Entry",5,4,colors.yellow)
+aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:removeItem(2)
```
-#### Parameters: number index
-#### Returns: self
## editItem
-Edits a item on the radio
+Edits a item from the radio
+#### Parameters:
+1. `number` The index which should be edited
+2. `string` The new item name
+3. `number` the new x position
+4. `number` the new y position
+3. `number|color` the new item background color - optional
+4. `number|color` The new item text color - optional
+5. `any` New additional information - optional
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default radio with 3 entries and changes the second one.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aRadio = mainFrame:addRadio("myFirstRadio"):show()
-aRadio:addItem("1. Entry",3,4)
-aRadio:addItem("2. Entry",3,5,colors.yellow)
-aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
-aRadio:editItem(3,"3. Edited Entry",3,6,colors.yellow,colors.green)
+local mainFrame = basalt.createFrame()
+local aRadio = mainFrame:addRadio()
+aRadio:addItem("1. Entry",5,2)
+aRadio:addItem("2. Entry",5,4,colors.yellow)
+aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
+aRadio:editItem(2, "Still 2. Entry", 5, 4, colors.red)
```
-#### Parameters: number index, string text, number x, number y, number bgcolor, number fgcolor, any ...
-#### Returns: self
-## setScrollable
-Makes the radio scrollable
+## getItem
+Returns a item by index
+#### Parameters:
+1. `number` The index which should be returned
+
+#### Returns:
+1. `table` The item table example: {text="1. Entry", bgCol=colors.black, fgCol=colors.white}
+
+#### Usage:
+* Creates a default radio with 3 entries and edits the second one.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aRadio = mainFrame:addRadio("myFirstRadio"):show()
-aRadio:addItem("1. Entry",3,4)
-aRadio:addItem("2. Entry",3,5,colors.yellow)
-aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
-aRadio:setScrollable(true)
+local mainFrame = basalt.createFrame()
+local aRadio = mainFrame:addRadio()
+aRadio:addItem("1. Entry",5,2)
+aRadio:addItem("2. Entry",5,4,colors.yellow)
+aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
+basalt.debug(aRadio:getItem(2).text)
+```
+
+## getItemCount
+Returns the current item count
+
+#### Returns:
+1. `number` The item radio count
+
+#### Usage:
+* Creates a default radio with 3 entries and prints the current item count.
+```lua
+local mainFrame = basalt.createFrame()
+local aRadio = mainFrame:addRadio()
+aRadio:addItem("1. Entry",5,2)
+aRadio:addItem("2. Entry",5,4,colors.yellow)
+aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
+basalt.debug(aRadio:getItemCount())
+```
+
+## getAll
+Returns all items as table
+
+#### Returns:
+1. `table` All items
+
+#### Usage:
+* Creates a default menubar with 3 entries and prints a table.
+```lua
+local mainFrame = basalt.createFrame()
+local aRadio = mainFrame:addRadio()
+aRadio:addItem("1. Entry",5,2)
+aRadio:addItem("2. Entry",5,4,colors.yellow)
+aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
+basalt.debug(aRadio:getAll())
```
-#### Parameters: boolean isScrollable
-#### Returns: self
## selectItem
selects a item in the radio (same as a player would click on a item)
+#### Parameters:
+1. `number` The index which should get selected
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default radio with 3 entries and selects the second entry.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aRadio = mainFrame:addRadio("myFirstRadio"):show()
-aRadio:addItem("1. Entry",3,4)
-aRadio:addItem("2. Entry",3,5,colors.yellow)
-aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
-aRadio:selectItem(1)
+local mainFrame = basalt.createFrame()
+local aRadio = mainFrame:addRadio()
+aRadio:addItem("1. Entry",5,2)
+aRadio:addItem("2. Entry",5,4,colors.yellow)
+aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
+aRadio:selectItem(2)
```
-#### Parameters: number index
-#### Returns: self
## clear
-clears the entire list (radio)
+Removes all items.
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default radio with 3 entries and removes them immediatley. Which makes no sense.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aRadio = mainFrame:addRadio("myFirstRadio"):show()
-aRadio:addItem("1. Entry",3,4)
-aRadio:addItem("2. Entry",3,5,colors.yellow)
-aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
+local mainFrame = basalt.createFrame()
+local aRadio = mainFrame:addRadio()
+aRadio:addItem("1. Entry",5,2)
+aRadio:addItem("2. Entry",5,4,colors.yellow)
+aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:clear()
```
-#### Parameters: -
-#### Returns: self
## getItemIndex
returns the item index of the currently selected item
+#### Returns:
+1. `number` The current index
+
+#### Usage:
+* Creates a default radio with 3 entries selects the second entry and prints the currently selected index.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aRadio = mainFrame:addRadio("myFirstRadio"):show()
-aRadio:addItem("1. Entry",3,4)
-aRadio:addItem("2. Entry",3,5,colors.yellow)
-aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
-aRadio:getItemIndex()
+local mainFrame = basalt.createFrame()
+local aRadio = mainFrame:addRadio()
+aRadio:addItem("1. Entry",5,2)
+aRadio:addItem("2. Entry",5,4,colors.yellow)
+aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
+aRadio:selectItem(2)
+basalt.debug(aRadio:getItemIndex())
```
-#### Parameters: -
-#### Returns: number index
## setSelectedItem
-Sets the background of the item which is currently selected
+Sets the background and the foreground of the item which is currently selected
+#### Parameters:
+1. `number|color` The background color which should be used
+2. `number|color` The text color which should be used
+
+#### Returns:
+1. `object` The object in use
+
+#### Usage:
+* Creates a default radio with 4 entries and sets the selection background color to green.
```lua
-local mainFrame = basalt.createFrame("myFirstFrame"):show()
-local aRadio = mainFrame:addRadio("myFirstRadio"):show()
-aRadio:addItem("1. Entry",3,4)
-aRadio:addItem("2. Entry",3,5,colors.yellow)
-aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
-aRadio:setSelectedItem(colors.green, colors.blue)
+local mainFrame = basalt.createFrame()
+local aRadio = mainFrame:addRadio()
+aRadio:addItem("1. Entry",5,2)
+aRadio:addItem("2. Entry",5,4,colors.yellow)
+aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
+aRadio:addItem("4. Entry",5,8)
+aRadio:setSelectedItem(colors.green, colors.red)
```
-#### Parameters: number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)
-#### Returns: self
\ No newline at end of file
+```xml
+
+ 1. Entry52
+ 2. Entry54yellow
+ 3. Entry56yellowgreen
+
+```
\ No newline at end of file
diff --git a/docs/objects/Thread.md b/docs/objects/Thread.md
index f3851e9..080a07e 100644
--- a/docs/objects/Thread.md
+++ b/docs/objects/Thread.md
@@ -22,9 +22,9 @@ local function randomThreadFunction()
end
aThread:start(randomThreadfunction)
```
+you are also able to start threads via xml:
```lua
basalt.setVariable("myThread", function() while true do os.sleep(1) end end)
-
```
```xml