docs update

Updated some docs stuff
This commit is contained in:
Robert Jelic
2022-10-09 12:05:30 +02:00
parent 44402b1d26
commit 1d3e2018ef
13 changed files with 228 additions and 7 deletions

View File

@@ -2,10 +2,20 @@
## onEvent ## onEvent
Every event the computer receives, from the bulit-in event "api", will get passed into basalt.onEvent, except for all mouse events, the key events (key and key_up), char and monitor_touch. This is the top-level method to intercept an event before sending it to the object event handlers. If you use return false, the event is not passed to the event handlers.
### Parameters ### Parameters
1. `function` The function which should be called
### Usage ### Usage
TODO ```lua
local basalt = require("basalt")
basalt.onEvent(function(event)
if(event=="terminate")then
return false
end
end)
```

View File

@@ -1,6 +1,6 @@
This is the base class for all visual objects. It covers positioning, sizing, showing/hiding and much more. This is the base class for all visual objects. It covers positioning, sizing, showing/hiding and much more.
By default a freshly created object is visible and automatically listens to all incoming events. By default a freshly created object is visible and doesn't listens to any incoming events.
Its default position is always 1, 1 (based on it's parent frame). The default anchor is also topLeft. Its default position is always 1, 1 (based on it's parent frame). The default anchor is also topLeft.
| | | | | |
@@ -31,16 +31,40 @@ Its default position is always 1, 1 (based on it's parent frame). The default an
# Events # Events
This is a list of all available events for all objects:
| | | | | |
|---|---| |---|---|
|[onClick](objects/Object/onClick.md)|Fires as soon as the object gets clicked |[onClick](objects/Object/onClick.md)|Fires as soon as the object gets clicked
|[onClickUp](objects/Object/onClickUp.md)|Fires as soon as the mouse button gets released on the object |[onClickUp](objects/Object/onClickUp.md)|Fires as soon as the mouse button gets released on the object
|[onScroll](objects/Object/onScroll.md)|Fires as soon as you scroll with the mousewheel |[onRelease](objects/Object/onRelease.md)|Fires as soon as the mouse button gets released
|[onScroll](objects/Object/onScroll.md)|Fires as soon as you scroll with the mousewheel
|[onDrag](objects/Object/onDrag.md)|Fires as soon as the object is beeing dragged |[onDrag](objects/Object/onDrag.md)|Fires as soon as the object is beeing dragged
|[onKey](objects/Object/onKey.md)|Fires when the object is focused and a keyboard key has been clicked |[onKey](objects/Object/onKey.md)|Fires when the object is focused and a keyboard key has been clicked
|[onChar](objects/Object/onChar.md)|Fires when the object is focused and a character has been clicked
|[onKeyUp](objects/Object/onKeyUp.md)|Fires when the object is focused and a keyboard key has been released |[onKeyUp](objects/Object/onKeyUp.md)|Fires when the object is focused and a keyboard key has been released
|[onChange](objects/Object/onChange.md)|Fires when the object value has been changed |[onChange](objects/Object/onChange.md)|Fires when the object value has been changed
|[onResize](objects/Object/onResize.md)|Fires when the object got resized |[onResize](objects/Object/onResize.md)|Fires when the object got resized
|[onReposition](objects/Object/onReposition.md)|Fires when the object has been repositioned |[onReposition](objects/Object/onReposition.md)|Fires when the object has been repositioned
|[onGetFocus](objects/Object/onGetFocus.md)|Fires when the object is focused |[onGetFocus](objects/Object/onGetFocus.md)|Fires when the object is focused
|[onLoseFocus](objects/Object/onLoseFocus.md)|Fires when the object lost it's focus |[onLoseFocus](objects/Object/onLoseFocus.md)|Fires when the object lost it's focus
|[onEvent](objects/Object/onEvent.md)|Fires on any other event
Sidenote: When you use return false this will skip the object's event handler. Here is a example for that.
This code would make it impossible to write a into the input:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local input = main:addInput()
:setPosition(3,3)
function checkInput(self, event, char)
if(char=="a")then
return false
end
end
main:onChar(checkInput)
```

View File

@@ -0,0 +1,25 @@
# onChar
`onChar(self, event, char)`<br>
The computercraft event which triggers this method is `char`.
The char event always happens after the key event (just like in cc:tweaked)
Here is a example on how to add a onChar event to your frame:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local subFrame = main:addFrame()
:setPosition(3,3)
:setSize(18,6)
:hide()
function openSubFrame(self, event, char)
if(char=="a")then
subFrame:show()
end
end
main:onChar(openSubFrame)
```

View File

@@ -0,0 +1,20 @@
# onEvent
`onEvent(self, event, ...)`
This event gets called on any other event. Some examples: http_success, disk, modem_message, paste, peripheral, redstone,...
You can find a full list here: [CC:Tweaked](https://tweaked.cc/) (on the left sidebar)
Here is a example on how to add a onEvent event to your frame:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
main:onEvent(function(event, side, channel, replyChannel, message, distance)
if(event=="modem_message")then
basalt.debug("Mesage received: "..tostring(message))
end
end)
```

View File

@@ -11,6 +11,7 @@ local main = basalt.createFrame()
local subFrame = main:addFrame() local subFrame = main:addFrame()
:setPosition(3,3) :setPosition(3,3)
:setSize(18,6) :setSize(18,6)
:hide()
function openSubFrame(self, event, key) function openSubFrame(self, event, key)
if(key==keys.c)then if(key==keys.c)then

View File

@@ -0,0 +1,27 @@
# onRelease
`onRelease(self, event, button, x, y)`<br>
The computercraft event which triggers this method is `mouse_up`.
The difference between onRelease and :onClickUp is that :onRelease is called even when the mouse is no longer over the object, while :onClickUp is only called when the mouse is over the object.
Here is a example on how to add a onRelease event to your button:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local button = main:addButton()
:setPosition(3,3)
:setSize(12,3)
:setText("Click")
function buttonOnClick(self, button, x, y)
basalt.debug("Button got clicked!")
end
button:onClick(buttonOnClick)
function buttonOnRelease(self, button, x, y)
basalt.debug("Button got released!")
end
button:onRelease(buttonOnRelease)
```

View File

@@ -1,4 +1,5 @@
# onResize # onResize
`onResize(self)`<br> `onResize(self)`<br>
This is a custom event which gets triggered as soon as the parent frame gets resized. This is a custom event which gets triggered as soon as the parent frame gets resized.
@@ -16,4 +17,4 @@ local function onButtonResize(self)
end end
aButton:onResize(onButtonResize) aButton:onResize(onButtonResize)
``` ```

View File

@@ -12,3 +12,12 @@ Program objects are here for opening other executable programs in your main prog
|[injectEvent](objects/Program/injectEvent.md)|Injects a event into the program |[injectEvent](objects/Program/injectEvent.md)|Injects a event into the program
|[injectEvents](objects/Program/injectEvents.md)|Injects a table of events |[injectEvents](objects/Program/injectEvents.md)|Injects a table of events
|[getQueuedEvents](objects/Program/getQueuedEvents.md)|Returns currently queued events |[getQueuedEvents](objects/Program/getQueuedEvents.md)|Returns currently queued events
# Events
This is a list of all available events for programs:
| | |
|---|---|
|[onError](objects/Program/onError.md)|Fires when a program errors
|[onDone](objects/Program/onDone.md)|Fires when a program has finished

View File

@@ -0,0 +1,19 @@
# onDone
`onDone(self, err)`<br>
This is a custom event which gets triggered as soon as the program has finished.
Here is a example on how to add a onDone event to your program:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local aProgram = main:addProgram():execute("rom/programs/shell.lua")
local function onProgramDone()
basalt.debug("Program has finished")
end
aProgram:onDone(onProgramDone)
```

View File

@@ -0,0 +1,34 @@
# onError
`onError(self, err)`<br>
This is a custom event which gets triggered as soon as the program catched a error.
Here is a example on how to add a onError event to your program:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local aProgram = main:addProgram():execute("rom/programs/shell.lua")
local function onProgramError(self, err)
local errFrame = main:addFrame()
:setSize(30, 10)
:setPosition("parent.w / 2 - self.w / 2", "parent.h / 2 - self.h / 2")
errFrame:addLabel()
:setPosition(2, 3)
:setSize("parent.w - 2", "parent.h - 3")
:setText(err)
errFrame:addButton()
:setPosition("parent.w", 1)
:setSize(1, 1)
:setText("X")
:onClick(function()
errFrame:remove()
end)
end
aProgram:onError(onProgramError)
```

View File

@@ -11,3 +11,10 @@ want to add some energy progress you have to do simple maths: currentValue / max
|[setProgressBar](objects/Progressbar/setProgressBar.md)|Changes the progress design |[setProgressBar](objects/Progressbar/setProgressBar.md)|Changes the progress design
|[setBackgroundSymbol](objects/Progressbar/setBackgroundSymbol.md)|Sets the background symbol |[setBackgroundSymbol](objects/Progressbar/setBackgroundSymbol.md)|Sets the background symbol
# Events
This is a list of all available events for progressbars:
| | |
|---|---|
|[onDone](objects/Progressbar/onDone.md)|Fires when a progress has finished

View File

@@ -0,0 +1,19 @@
# onDone
`onDone(self, err)`<br>
This is a custom event which gets triggered as soon as the progress is done.
Here is a example on how to add a onDone event to your progressbar:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local aProgressbar = main:addProgressbar()
local function onProgressDone()
basalt.debug("Progress is done")
end
aProgressbar:onDone(onProgressDone)
```

View File

@@ -1,6 +1,7 @@
You question yourself how you can execute your own logic while basalt is also active? There are multiple ways of doing that: You question yourself how you can execute your own logic while basalt is also active? There are multiple ways of doing that:
## Parallel ## Parallel
Using parallel.waitForAll or parallel.waitForAny Using parallel.waitForAll or parallel.waitForAny
```lua ```lua
@@ -21,9 +22,11 @@ end
parallel.waitForAll(basalt.autoUpdate, yourCustomHandler) -- here it will handle your function (yourCustomHandler) and basalt's handlers at the same time using parallel's API parallel.waitForAll(basalt.autoUpdate, yourCustomHandler) -- here it will handle your function (yourCustomHandler) and basalt's handlers at the same time using parallel's API
``` ```
[Here (tweaked.cc)](https://tweaked.cc/module/parallel.html) you can find out more about the parallel API. [Here (tweaked.cc)](https://tweaked.cc/module/parallel.html) you can find out more about the parallel API.
## Threads ## Threads
Using basalt's thread implementation. Using basalt's thread implementation.
```lua ```lua
@@ -47,6 +50,7 @@ thread:start(yourCustomHandler) -- here we start the thread and pass the functio
``` ```
## Timers ## Timers
Using basalt's implementation of timers. Using basalt's implementation of timers.
Remember, timers don't run asynchronly which means if you're using sleep somewhere this will freeze basalt's event system too. Remember, timers don't run asynchronly which means if you're using sleep somewhere this will freeze basalt's event system too.
@@ -67,4 +71,25 @@ end
timer:onCall(yourCustomHandler) timer:onCall(yourCustomHandler)
:setTime(1, -1) :setTime(1, -1)
:start() -- this will call your function every second until you :cancel() the timer :start() -- this will call your function every second until you :cancel() the timer
``` ```
## Schedule
Using basalt's schedule implementation.
```lua
local basalt = require("basalt")
local main = basalt.createFrame() -- we need a base frame
main:addButton() -- just a button
:onClick(function()
basalt.debug("Button got clicked")
end)
local yourCustomHandler = basalt.schedule(function() -- create a new schedule task
-- add your logic here
end)
yourCustomHandler() -- execute the schedule task
```