Some updates
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
`onDrag(self, event, button, x, y, xOffset, yOffset)`<br>
|
||||
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
|
||||
local basalt = require("basalt")
|
||||
|
||||
@@ -14,7 +13,31 @@ local button = main:addButton()
|
||||
:setText("Click")
|
||||
|
||||
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
|
||||
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()
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user