Accidentally uploaded outdated 1.6 docs
This commit is contained in:
Robert Jelic
2023-05-01 16:28:46 +02:00
parent 92b93a3862
commit d4c72514ef
265 changed files with 25608 additions and 3867 deletions

View File

@@ -0,0 +1,7 @@
# Object
## disable
Disables the object's event listeners
This will disable the object. Which means it doesn't listen to any events anymore.

View File

@@ -0,0 +1,7 @@
# Object
## enable
Enables the object's event listeners
If the object's is disabled, it will stop listening to incoming events, this will reenable it.

View File

@@ -0,0 +1,24 @@
# Object
## getAbsolutePosition
Converts the relative coordinates into absolute coordinates
### Parameters
1. `number|nil` x
2. `number|nil` y
### Returns
1. `object` The object in use
### Usage
* Creates a frame and a button and prints the button's absolute position to the debug console
```lua
local mainFrame = basalt.createFrame():setPosition(3,3)
local aButton = mainFrame:addButton():setSize(8,1):setPosition(4,2)
basalt.debug(aButton:getAbsolutePosition()) -- returns 7,5 (frame coords + own coords) instead of 4,2
```

View File

@@ -0,0 +1,28 @@
# Object
## getAnchorPosition
Converts the x and y coordinates into the anchor coordinates of the object
### Parameters
1. `number|nil` x
2. `number|nil` y, if nothing it uses the object's x, y
#### Returns
1. `number` x
2. `number` y
#### Usage
* Prints the anchor position to the debug console
```lua
local mainFrame = basalt.createFrame():setSize(15,15)
local aButton = mainFrame:addButton()
:setAnchor("bottomRight")
:setSize(8,1)
:setPosition(1,1)
basalt.debug(aButton:getAnchorPosition()) -- returns 7,14 (framesize - own size) instead of 1,1
```

View File

@@ -0,0 +1,9 @@
# Object
## getBackground
Returns the current background color
### Returns
1. `number` color

View File

@@ -0,0 +1,9 @@
# Object
## getForeground
Returns the current foreground color
### Returns
1. `number` color

View File

@@ -0,0 +1,23 @@
# Object
## getName
Returns the given name of the object
### Returns
1. `string` name
#### Usage
* Prints name of object to debug window
```lua
local main = basalt.createFrame()
basalt.debug(main:getName()) -- returns the uuid
```
```lua
local main = basalt.createFrame("myFirstMainFrame")
basalt.debug(main:getName()) -- returns myFirstMainFrame
```

View File

@@ -0,0 +1,10 @@
# Object
## getPosition
Returns the object's position
### Returns
1. `number` x
2. `number` y

View File

@@ -0,0 +1,10 @@
# Object
## getSize
Returns the object's size
### Returns
1. `number` w
2. `number` h

View File

@@ -0,0 +1,19 @@
# Object
## getValue
Returns the currently saved value
### Returns
1. `any` Object's value
### Usage
* Prints the value of the checkbox to the debug console
```lua
local mainFrame = basalt.createFrame()
local aCheckbox = mainFrame:addCheckbox():setValue(true)
basalt.debug(aCheckbox:getValue()) -- returns true
```

View File

@@ -0,0 +1,22 @@
# Object
## hide
Hides the object
### Returns
1. `object` The object in use
#### Usage
* Hides a frame
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton():setText("Close"):onClick(function() mainFrame:hide() end)
```
```xml
<button visible="false" />
```

View File

@@ -0,0 +1,19 @@
# Object
## isFocused
Returns if the object is currently the focused object of the parent frame
### Returns
1. `boolean` Whether the object is focused
#### Usage
* Prints whether the button is focused to the debug console
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton()
basalt.debug(aButton:isFocused()) -- shows true or false as a debug message
```

View File

@@ -0,0 +1,19 @@
# Object
## isVisible
Returns if the object is currently visible
### Returns
1. `boolean`
#### Usage
* Prints boolean visibility of object to debug console
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setSize(5,8)
basalt.debug(aButton:isVisible()) -- returns true
```

View File

@@ -0,0 +1,32 @@
# Object - Event
## onChange
`onChange(self)`
This is a custom event which gets triggered as soon as the function :setValue() is called. This function is also called by basalt, for example if you change the input, textfield or checkbox (or all the different types of lists) objects.
Here is a example on how to add a onChange event to your input, and also another example for your checkbox:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local aInput = main:addInput():setPosition(3,3)
local aCheckbox = main:addCheckbox():setPosition(3,5)
local function checkInput(input)
if(string.lower(input:getValue())=="hello")then
basalt.debug("Hello back!")
end
end
local function checkCheckbox(checkbox)
if(checkbox:getValue()==true)then -- or if(checkbox:getValue())then
basalt.debug("Checkbox is active, let's do something!")
end
end
aInput:onChange(checkInput)
aCheckbox:onChange(checkCheckbox)
```

View File

@@ -0,0 +1,28 @@
# Object - Event
## onChar
`onChar(self, event, char)`
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,50 @@
# onClick
`onClick(self, event, button, x, y)`
The computercraft event which triggers this method is `mouse_click` and `monitor_touch`.
Here is a example on how to add a onClick 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()
basalt.debug("Button got clicked!")
end
button:onClick(buttonOnClick)
```
Here is also a example on how you could create double clicks:
```lua
local basalt = require("basalt")
local doubleClickMaxTime = 0.25 -- in seconds
local main = basalt.createFrame()
local button = main:addButton()
local function createDoubleClick(btn, func) -- here we create a function where we can pass buttons (or other object if you'd like to) and a function which will get called by double clicking.
local doubleClick = 0
btn:onClick(function()
if(os.epoch("local")-doubleClickMaxTime*1000<=doubleClick)then
func()
end
doubleClick = os.epoch("local")
end)
end
local function debugSomething()
basalt.debug("hello")
end
createDoubleClick(button, debugSomething) -- this is how you will create a double click.
basalt.autoUpdate()
```

View File

@@ -0,0 +1,29 @@
# Object - Event
## onClickUp
`onClickUp(self, event, button, x, y)`
The computercraft event which triggers this method is `mouse_up`.
Here is a example on how to add a onClickUp 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:onClickUp(buttonOnRelease)
```

View File

@@ -0,0 +1,71 @@
# Object - Event
## onDrag
`onDrag(self, event, button, x, y, xOffset, yOffset)`
The computercraft event which triggers this method is `mouse_drag`.
This is a example on how you would create a movable button:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local button = main:addButton()
:setPosition(3,3)
:setSize(12,3)
:setText("Click")
function buttonOnDrag(self, button, x, y, xOffset, yOffset)
self:setPosition(-xOffset, -yOffset, true) -- we need to reverse the offset and true means to add the offset instead of changing it.
end
button:onDrag(buttonOnDrag)
basalt.autoUpdate()
```
Another example on how you could change the frame's offset by dragging around.
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
:onDrag(function(self, button, x, y, xOffset, yOffset)
local xO, yO = self:getOffset()
self:setOffset(xO-xOffset, yO-yOffset, true) -- we need to reverse the offset and true means to add the offset instead of changing it.
end)
local button = main:addButton()
:setPosition(3,3)
:setSize(12,3)
:setText("Click")
local button2 = main:addButton()
:setPosition(16,3)
:setSize(12,3)
:setText("Click")
basalt.autoUpdate()
```
Also very interesting is a button where you are able to resize the frame just by dragging the button.
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local sub = main:addFrame():setSize(30,12):setMovable()
sub:addLabel():setText("Example Frame"):setSize("parent.w", 1):setBackground(colors.black):setForeground(colors.lightGray)
local dragButton = sub:addButton()
:setAnchor("bottomRight")
:setPosition(1,1)
:setSize(1,1)
:setText("/")
:onDrag(function(self, button, x, y, xOffset, yOffset)
sub:setSize(-xOffset, -yOffset, true)
end)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,22 @@
# Object - Event
## 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

@@ -0,0 +1,20 @@
# Object - Event
## onGetFocus
`onGetFocus(self)`
This event gets triggered as soon as the object is the currently focused object.
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local aButton = main:addButton()
:setPosition(3,3)
:onGetFocus(
function(self)
basalt.debug("Welcome back!")
end
)
```

View File

@@ -0,0 +1,24 @@
# Object - Event
## onHover
`onHover(self, event, button, x, y)`
The computercraft event which triggers this method is `mouse_move` - only available in [CraftOS-PC](https://www.craftos-pc.cc).
Here is a example on how to add a onHover event to your button:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local button = main:addButton()
:setPosition(3,3)
:setSize(12,3)
:setText("Hover")
function buttonOnHover()
basalt.debug("The mouse hovers over the button!")
end
button:onHover(buttonOnHover)
```

View File

@@ -0,0 +1,26 @@
# Object - Event
## onKey
`onKey(self, event, key)`
The computercraft event which triggers this method is `key` and `char`.
Here is a example on how to add a onKey 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, key)
if(key==keys.c)then
subFrame:show()
end
end
main:onKey(openSubFrame)
```

View File

@@ -0,0 +1,25 @@
# Object - Event
## onKeyUp
`onKeyUp(self, event, key)`
The computercraft event which triggers this method is `key_up`.
Here is a example on how to add a onKeyUp event to your frame:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local subFrame = main:addFrame()
:setPosition(3,3)
:setSize(18,6)
function openSubFrame(self, event, key)
if(key==keys.c)then
subFrame:show()
end
end
main:onKeyUp(openSubFrame)
```

View File

@@ -0,0 +1,24 @@
# Object - Event
## onLeave
`onLeave(self, event, button, x, y)`
The computercraft event which triggers this method is `mouse_move` - only available in [CraftOS-PC](https://www.craftos-pc.cc).
Here is a example on how to add a onLeave event to your button:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local button = main:addButton()
:setPosition(3,3)
:setSize(12,3)
:setText("Leave")
function buttonOnLeave()
basalt.debug("The mouse left the button!")
end
button:onLeave(buttonOnLeave)
```

View File

@@ -0,0 +1,20 @@
# Object - Event
## onLoseFocus
`onLoseFocus(self)`
This event gets triggered as soon as the object loses its focus.
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local aButton = main:addButton()
:setPosition(3,3)
:onLoseFocus(
function(self)
basalt.debug("Please come back...")
end
)
```

View File

@@ -0,0 +1,31 @@
# Object - Event
## onRelease
`onRelease(self, event, button, x, y)`
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

@@ -0,0 +1,22 @@
# Object - Event
## onReposition
`onReposition(self)`
This is a custom event which gets triggered as soon as the object gets repositioned (for example by dynamic value).
Here is a example on how to add a onReposition event to your button:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local aButton = main:addButton():setPosition(3,3)
local function onButtonReposition(self)
self:setSize(self:getWidth() - self:getX(), 3)
end
aButton:onReposition(onButtonReposition)
```

View File

@@ -0,0 +1,23 @@
# Object - Event
## onResize
`onResize(self)`
This is a custom event which gets triggered as soon as the parent frame gets resized.
Here is a example on how to add a onResize event to your button:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local aButton = main:addButton():setPosition(3,3)
local function onButtonResize(self)
local width = main:getWidth()
self:setSize(width, 3)
end
aButton:onResize(onButtonResize)
```

View File

@@ -0,0 +1,24 @@
# Object - Event
## onScroll
`onScroll(self, event, direction, x, y)`
The computercraft event which triggers this method is `mouse_scroll`.
Here is a example on how to add a onScroll 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 buttonOnScroll(self, direction, x, y)
basalt.debug("Someone scrolls on me!")
end
button:onScroll(buttonOnScroll)
```

View File

@@ -0,0 +1,15 @@
# Object
## remove
Removes the object from it's parent frame. This won't 'destroy' the object, It will continue to exist as long as you still have pointers to it.
Here is a example on how a button will be fully removed from the memory:
```lua
local main = basalt.createFrame()
local button = main:addButton():setPosition(2,2):setText("Close")
button:remove()
button = nil
```

View File

@@ -0,0 +1,29 @@
# Object
## setAnchor
Sets the anchor of the object
### Parameters
1. `string` Anchor sides `("topLeft" "top", "topRight", "right", "bottomRight", "bottom", "bottomLeft", "left", "center")`
### Returns
1. `object` The object in use
### Usage
* Sets the button to have an anchor of `bottomRight`
```lua
local mainFrame = basalt.createFrame():show()
local aButton = mainFrame:addButton()
:setAnchor("bottomRight")
:setSize(8,1)
:setPosition(-8,1)
```
```xml
<button anchor="bottomRight" />
```

View File

@@ -0,0 +1,27 @@
# Object
## setBackground
Changes the object background color, if you set the value to false the background wont be visible. For example you could see trough a frame.
### Parameters
1. `number|color` Background color
1. `char` background symbol you want to draw (optional)
1. `number|color` Background symbol color (optional)
### Returns
1. `object` The object in use
### Usage
* Creates a frame, and sets its background color to `colors.gray`, also sets a background symbol with color black.
```lua
local mainFrame = basalt.createFrame():setBackground(colors.gray, "#", colors.black)
```
```xml
<button bg="gray" />
```

View File

@@ -0,0 +1,32 @@
# Object
## setBorder
Sets the border of that objects, if false the border will be removed
Default: false
### Parameters
1. `number|color` Border color
2. `string` optional - sides. If you don't set sides, all 4 sides will have a border
### Returns
1. `object` The object in use
### Usage
* Sets the border to green and shows it:
```lua
local mainFrame = basalt.createFrame()
local subFrame = mainFrame:addFrame()
:setMovable()
:setSize(18,6)
:setBorder(colors.green, "left", "right", "bottom")
```
```xml
<frame width="18" height="6" borderColor="green" movable="true" />
```

View File

@@ -0,0 +1,20 @@
# Object
## setFocus
Sets the object to be the focused object.
If you click on an object, it's normally automatically the focused object. For example, if you call :show() on a frame, and you want this particular frame to be in
the foreground, you should also use :setFocus()
### Returns
1. `object` The object in use
### Usage
* Sets the button to the focused object
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setFocus()
```

View File

@@ -0,0 +1,25 @@
# Object
## setForeground
Changes the object text color
### Parameters
1. `number|color` Foreground color
### Returns
1. `object` The object in use
### Usage
* Creates a frame, and sets its foreground color to `colors.green`
```lua
local mainFrame = basalt.createFrame():setForeground(colors.green)
```
```xml
<button fg="green" />
```

View File

@@ -0,0 +1,27 @@
# Object
## setParent
Sets the parent frame of the object
### Parameters
1. `frame` The to-be parent frame
### Returns
1. `object` The object in use
### Usage
* Sets the parent frame of the random frame, adding it to the main frame when the button is clicked"
```lua
local mainFrame = basalt.createFrame()
local aRandomFrame = basalt.createFrame()
local aButton = mainFrame:addButton():onClick(
function()
aRandomFrame:setParent(mainFrame)
end
)
```

View File

@@ -0,0 +1,39 @@
# Object
## setPosition
Changes the position relative to its parent frame
### Parameters
1. `number|string` x coordinate as number or dynamicvalue as string
2. `number|string` y coordinate as number or dynamicvalue as string
3. `boolean` Whether it will add/remove to the current coordinates instead of setting them
### Returns
1. `object` The object in use
### Usage
* Sets the Buttons position to an x coordinate of 2 with a y coordinate of 3
```lua
local mainFrame = basalt.createFrame()
mainFrame:addButton():setPosition(2,3)
```
```xml
<button x="2" y="3" />
```
if you prefer to use dynamic values:
```lua
local mainFrame = basalt.createFrame()
mainFrame:addButton():setPosition("parent.w * 0.5", 23)
```
```xml
<button x="parent.w * 0.5" y="3" />
```

View File

@@ -0,0 +1,31 @@
# Object
## setShadow
Sets the shadow color - default: false
### Parameters
1. `number|color` Shadow color
#### Returns
1. `object` The object in use
#### Usage
* Sets the shadow to green and shows it:
```lua
local mainFrame = basalt.createFrame()
local subFrame = mainFrame:addFrame()
:setMovable()
:setSize(18,6)
:setShadow(colors.green)
```
Or:
```xml
<frame width="18" height="6" shadowColor="green" movable="true" />
```

View File

@@ -0,0 +1,27 @@
# Object
## setSize
Changes the object size
### Parameters
1. `number|string` width as number or dynamicvalue as string
2. `number|string` height as number or dynamicvalue as string
### Returns
1. `object` The object in use
### Usage
* Sets the frame to have a width of 15 and a height of 12
```lua
local mainFrame = basalt.createFrame()
local subFrame = mainFrame:addFrame():setSize(15,12)
```
```xml
<frame width="15" height="12" />
```

View File

@@ -0,0 +1,26 @@
# Object
## setValue
Sets the value of that object (input, label, checkbox, textfield, scrollbar,...)
### Parameters
1. `any` Value to set the object to
### Returns
1. `object` The object in use
### Usage
* Creates a checkbox and ticks it
```lua
local mainFrame = basalt.createFrame()
local aCheckbox = mainFrame:addCheckbox():setValue(true)
```
```xml
<checkbox value="true" />
```

View File

@@ -0,0 +1,28 @@
# Object
## setZIndex
Sets the z-index. Higher value means higher draw/event priority. You can also add multiple objects to the same z-index, if so the last added object will have the highest priority.
### Parameters
1. `number` z-index
### Returns
1. `object` The object in use
### Usage
* Sets the buttons z-index to `1` and the labels z-index to `2`
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setZIndex(1):setPosition(2,2)
local aLabel = mainFrame:addButton():setZIndex(2):setPosition(2,2):setText("I am a label!")
```
```xml
<button x="2" y="2" zIndex="1" />
<label x="2" y="2" text="I am a label!" zIndex="2" />
```

View File

@@ -0,0 +1,23 @@
# Object
## show
Shows the object (only if the parent frame is already visible)
### Returns
1. `object` The object in use
### Usage
* Shows a frame
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
button:show()
```
```xml
<button visible="true" />
```