Some updates
This commit is contained in:
@@ -28,3 +28,4 @@
|
|||||||
- [Your Logic](tips/logic.md)
|
- [Your Logic](tips/logic.md)
|
||||||
- [Button coloring](tips/buttonColoring.md)
|
- [Button coloring](tips/buttonColoring.md)
|
||||||
- [Designing/Animating](tips/design.md)
|
- [Designing/Animating](tips/design.md)
|
||||||
|
- [Dynamic Values](tips/dynamicvalues.md)
|
||||||
|
|||||||
@@ -8,6 +8,5 @@ This starts the event and draw handler for you. The listeners will run until you
|
|||||||
* Enable the basalt listeners, otherwise the screen will not continue to update
|
* Enable the basalt listeners, otherwise the screen will not continue to update
|
||||||
```lua
|
```lua
|
||||||
local main = basalt.createFrame()
|
local main = basalt.createFrame()
|
||||||
|
|
||||||
basalt.autoUpdate()
|
basalt.autoUpdate()
|
||||||
```
|
```
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
## disable
|
||||||
|
Disables the object's event listeners
|
||||||
|
|
||||||
|
This will disable the object. Which means it doesn't listen to any events anymore.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
## enable
|
||||||
|
Enables the object's event listeners
|
||||||
|
|
||||||
|
If the object's is disabled, it will stop listening to incoming events, this will reenable it.
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
## getPosition
|
||||||
|
Returns the object's position
|
||||||
|
|
||||||
|
#### Returns:
|
||||||
|
1. `number` x
|
||||||
|
2. `number` y
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
## getSize
|
||||||
|
Returns the object's size
|
||||||
|
|
||||||
|
#### Returns:
|
||||||
|
1. `number` w
|
||||||
|
2. `number` h
|
||||||
|
|||||||
@@ -17,4 +17,31 @@ function buttonOnClick()
|
|||||||
basalt.debug("Button got clicked!")
|
basalt.debug("Button got clicked!")
|
||||||
end
|
end
|
||||||
button:onClick(buttonOnClick)
|
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()
|
||||||
```
|
```
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
`onDrag(self, event, button, x, y, xOffset, yOffset)`<br>
|
`onDrag(self, event, button, x, y, xOffset, yOffset)`<br>
|
||||||
The computercraft event which triggers this method is `mouse_drag`.
|
The computercraft event which triggers this method is `mouse_drag`.
|
||||||
|
|
||||||
Here is a example on how to add a onDrag event to your button:
|
This is a example on how you would create a movable button:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local basalt = require("basalt")
|
local basalt = require("basalt")
|
||||||
|
|
||||||
@@ -14,7 +13,31 @@ local button = main:addButton()
|
|||||||
:setText("Click")
|
:setText("Click")
|
||||||
|
|
||||||
function buttonOnDrag(self, button, x, y, xOffset, yOffset)
|
function buttonOnDrag(self, button, x, y, xOffset, yOffset)
|
||||||
basalt.debug("Someone drags me (i know i wont reposition myself)!")
|
self:setPosition(-xOffset, -yOffset, true) -- we need to reverse the offset and true means to add the offset instead of changing it.
|
||||||
end
|
end
|
||||||
button:onDrag(buttonOnDrag)
|
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()
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
## setPosition
|
## setPosition
|
||||||
Changes the position relative to its parent frame
|
Changes the position relative to its parent frame
|
||||||
#### Parameters:
|
#### Parameters:
|
||||||
1. `number` x coordinate
|
1. `number|string` x coordinate as number or dynamicvalue as string
|
||||||
2. `number` y coordinate
|
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
|
3. `boolean` Whether it will add/remove to the current coordinates instead of setting them
|
||||||
|
|
||||||
#### Returns:
|
#### Returns:
|
||||||
@@ -16,4 +16,13 @@ mainFrame:addButton():setPosition(2,3)
|
|||||||
```
|
```
|
||||||
```xml
|
```xml
|
||||||
<button x="2" y="3" />
|
<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" />
|
||||||
```
|
```
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
## setSize
|
## setSize
|
||||||
Changes the object size
|
Changes the object size
|
||||||
#### Parameters:
|
#### Parameters:
|
||||||
1. `number` width
|
1. `number|string` width as number or dynamicvalue as string
|
||||||
2. `number` height
|
2. `number|string` height as number or dynamicvalue as string
|
||||||
|
|
||||||
#### Returns:
|
#### Returns:
|
||||||
1. `object` The object in use
|
1. `object` The object in use
|
||||||
|
|||||||
54
docs/tips/dynamicvalues.md
Normal file
54
docs/tips/dynamicvalues.md
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
Dynamic Values is a way to position or size your object based on the position/size of other objects. This makes it pretty easy to create programs where the terminal size
|
||||||
|
doesn't matter.
|
||||||
|
|
||||||
|
A dynamic value is always a string, and you can add anything you want in there. Here are some examples:<br>
|
||||||
|
"5 + 2"<br>
|
||||||
|
"(5 + 2) * 3"<br>
|
||||||
|
"math.floor(5+2.2)"<br>
|
||||||
|
"objectid.x + objectid.y + objectid.w + objectid+h"<br>
|
||||||
|
"parent.w"<br>
|
||||||
|
"self.w"<br>
|
||||||
|
|
||||||
|
Parent always refers to it's parent object, self always refers to itself.
|
||||||
|
|
||||||
|
## Positioning
|
||||||
|
Here i will show you a example on how to position a button next to another button, doesn't matter which size it has.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local basalt = require("basalt")
|
||||||
|
|
||||||
|
local main = basalt.createFrame()
|
||||||
|
|
||||||
|
local button = main:addButton("firstBtn")
|
||||||
|
:setBackground(colors.black)
|
||||||
|
:setForeground(colors.lightGray)
|
||||||
|
:setPosition(2, 2)
|
||||||
|
local button2 = main:addButton()
|
||||||
|
:setBackground(colors.black)
|
||||||
|
:setForeground(colors.lightGray)
|
||||||
|
:setPosition("firstBtn.w + firstBtn.x + 2", "firstBtn.y")
|
||||||
|
|
||||||
|
basalt.autoUpdate()
|
||||||
|
```
|
||||||
|
Now, you can move the first button and the second button would also move. Doesn't matter how.
|
||||||
|
|
||||||
|
## Sizing
|
||||||
|
This is a example on how you can create buttons where the size is always based on it's parent frame
|
||||||
|
```lua
|
||||||
|
local basalt = require("basalt")
|
||||||
|
|
||||||
|
local main = basalt.createFrame()
|
||||||
|
|
||||||
|
local button = main:addButton("firstBtn")
|
||||||
|
:setBackground(colors.black)
|
||||||
|
:setForeground(colors.lightGray)
|
||||||
|
:setPosition(2, 2)
|
||||||
|
:setSize("parent.w - 2", 3)
|
||||||
|
local button2 = main:addButton()
|
||||||
|
:setBackground(colors.black)
|
||||||
|
:setForeground(colors.lightGray)
|
||||||
|
:setPosition(2, "firstBtn.y + firstBtn.h + 1")
|
||||||
|
:setSize("parent.w - 2", 3)
|
||||||
|
|
||||||
|
basalt.autoUpdate()
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user