Skip to content

Commit 18601d5

Browse files
committed
Some updates
1 parent 4d61437 commit 18601d5

11 files changed

+141
-8
lines changed

docs/_sidebar.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
- [Your Logic](tips/logic.md)
2929
- [Button coloring](tips/buttonColoring.md)
3030
- [Designing/Animating](tips/design.md)
31+
- [Dynamic Values](tips/dynamicvalues.md)

docs/objects/Basalt/autoUpdate.md

-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ This starts the event and draw handler for you. The listeners will run until you
88
* Enable the basalt listeners, otherwise the screen will not continue to update
99
```lua
1010
local main = basalt.createFrame()
11-
1211
basalt.autoUpdate()
1312
```

docs/objects/Object/disable.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## disable
2+
Disables the object's event listeners
3+
4+
This will disable the object. Which means it doesn't listen to any events anymore.

docs/objects/Object/enable.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## enable
2+
Enables the object's event listeners
3+
4+
If the object's is disabled, it will stop listening to incoming events, this will reenable it.

docs/objects/Object/getPosition.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## getPosition
2+
Returns the object's position
3+
4+
#### Returns:
5+
1. `number` x
6+
2. `number` y

docs/objects/Object/getSize.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## getSize
2+
Returns the object's size
3+
4+
#### Returns:
5+
1. `number` w
6+
2. `number` h

docs/objects/Object/onClick.md

+27
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,31 @@ function buttonOnClick()
1717
basalt.debug("Button got clicked!")
1818
end
1919
button:onClick(buttonOnClick)
20+
```
21+
22+
Here is also a example on how you could create double clicks:
23+
```lua
24+
local basalt = require("basalt")
25+
local doubleClickMaxTime = 0.25 -- in seconds
26+
27+
local main = basalt.createFrame()
28+
local button = main:addButton()
29+
30+
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.
31+
local doubleClick = 0
32+
btn:onClick(function()
33+
if(os.epoch("local")-doubleClickMaxTime*1000<=doubleClick)then
34+
func()
35+
end
36+
doubleClick = os.epoch("local")
37+
end)
38+
end
39+
40+
local function debugSomething()
41+
basalt.debug("hello")
42+
end
43+
44+
createDoubleClick(button, debugSomething) -- this is how you will create a double click.
45+
46+
basalt.autoUpdate()
2047
```

docs/objects/Object/onDrag.md

+26-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
`onDrag(self, event, button, x, y, xOffset, yOffset)`<br>
33
The computercraft event which triggers this method is `mouse_drag`.
44

5-
Here is a example on how to add a onDrag event to your button:
6-
5+
This is a example on how you would create a movable button:
76
```lua
87
local basalt = require("basalt")
98

@@ -14,7 +13,31 @@ local button = main:addButton()
1413
:setText("Click")
1514

1615
function buttonOnDrag(self, button, x, y, xOffset, yOffset)
17-
basalt.debug("Someone drags me (i know i wont reposition myself)!")
16+
self:setPosition(-xOffset, -yOffset, true) -- we need to reverse the offset and true means to add the offset instead of changing it.
1817
end
1918
button:onDrag(buttonOnDrag)
19+
20+
basalt.autoUpdate()
21+
```
22+
23+
Another example on how you could change the frame's offset by dragging around.
24+
```lua
25+
local basalt = require("basalt")
26+
27+
local main = basalt.createFrame()
28+
:onDrag(function(self, button, x, y, xOffset, yOffset)
29+
local xO, yO = self:getOffset()
30+
self:setOffset(xO-xOffset, yO-yOffset, true) -- we need to reverse the offset and true means to add the offset instead of changing it.
31+
end)
32+
33+
local button = main:addButton()
34+
:setPosition(3,3)
35+
:setSize(12,3)
36+
:setText("Click")
37+
local button2 = main:addButton()
38+
:setPosition(16,3)
39+
:setSize(12,3)
40+
:setText("Click")
41+
42+
basalt.autoUpdate()
2043
```

docs/objects/Object/setPosition.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## setPosition
22
Changes the position relative to its parent frame
33
#### Parameters:
4-
1. `number` x coordinate
5-
2. `number` y coordinate
4+
1. `number|string` x coordinate as number or dynamicvalue as string
5+
2. `number|string` y coordinate as number or dynamicvalue as string
66
3. `boolean` Whether it will add/remove to the current coordinates instead of setting them
77

88
#### Returns:
@@ -16,4 +16,13 @@ mainFrame:addButton():setPosition(2,3)
1616
```
1717
```xml
1818
<button x="2" y="3" />
19+
```
20+
21+
if you prefer to use dynamic values:
22+
```lua
23+
local mainFrame = basalt.createFrame()
24+
mainFrame:addButton():setPosition("parent.w * 0.5", 23)
25+
```
26+
```xml
27+
<button x="parent.w * 0.5" y="3" />
1928
```

docs/objects/Object/setSize.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## setSize
22
Changes the object size
33
#### Parameters:
4-
1. `number` width
5-
2. `number` height
4+
1. `number|string` width as number or dynamicvalue as string
5+
2. `number|string` height as number or dynamicvalue as string
66

77
#### Returns:
88
1. `object` The object in use

docs/tips/dynamicvalues.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
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
2+
doesn't matter.
3+
4+
A dynamic value is always a string, and you can add anything you want in there. Here are some examples:<br>
5+
"5 + 2"<br>
6+
"(5 + 2) * 3"<br>
7+
"math.floor(5+2.2)"<br>
8+
"objectid.x + objectid.y + objectid.w + objectid+h"<br>
9+
"parent.w"<br>
10+
"self.w"<br>
11+
12+
Parent always refers to it's parent object, self always refers to itself.
13+
14+
## Positioning
15+
Here i will show you a example on how to position a button next to another button, doesn't matter which size it has.
16+
17+
```lua
18+
local basalt = require("basalt")
19+
20+
local main = basalt.createFrame()
21+
22+
local button = main:addButton("firstBtn")
23+
:setBackground(colors.black)
24+
:setForeground(colors.lightGray)
25+
:setPosition(2, 2)
26+
local button2 = main:addButton()
27+
:setBackground(colors.black)
28+
:setForeground(colors.lightGray)
29+
:setPosition("firstBtn.w + firstBtn.x + 2", "firstBtn.y")
30+
31+
basalt.autoUpdate()
32+
```
33+
Now, you can move the first button and the second button would also move. Doesn't matter how.
34+
35+
## Sizing
36+
This is a example on how you can create buttons where the size is always based on it's parent frame
37+
```lua
38+
local basalt = require("basalt")
39+
40+
local main = basalt.createFrame()
41+
42+
local button = main:addButton("firstBtn")
43+
:setBackground(colors.black)
44+
:setForeground(colors.lightGray)
45+
:setPosition(2, 2)
46+
:setSize("parent.w - 2", 3)
47+
local button2 = main:addButton()
48+
:setBackground(colors.black)
49+
:setForeground(colors.lightGray)
50+
:setPosition(2, "firstBtn.y + firstBtn.h + 1")
51+
:setSize("parent.w - 2", 3)
52+
53+
basalt.autoUpdate()
54+
```

0 commit comments

Comments
 (0)