diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 488f803..f7a3d5d 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -28,3 +28,4 @@ - [Your Logic](tips/logic.md) - [Button coloring](tips/buttonColoring.md) - [Designing/Animating](tips/design.md) + - [Dynamic Values](tips/dynamicvalues.md) diff --git a/docs/objects/Basalt/autoUpdate.md b/docs/objects/Basalt/autoUpdate.md index e7697cb..9038719 100644 --- a/docs/objects/Basalt/autoUpdate.md +++ b/docs/objects/Basalt/autoUpdate.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 ```lua local main = basalt.createFrame() - basalt.autoUpdate() ``` \ No newline at end of file diff --git a/docs/objects/Object/disable.md b/docs/objects/Object/disable.md index e69de29..6c97de3 100644 --- a/docs/objects/Object/disable.md +++ b/docs/objects/Object/disable.md @@ -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. \ No newline at end of file diff --git a/docs/objects/Object/enable.md b/docs/objects/Object/enable.md index e69de29..f277cb8 100644 --- a/docs/objects/Object/enable.md +++ b/docs/objects/Object/enable.md @@ -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. \ No newline at end of file diff --git a/docs/objects/Object/getPosition.md b/docs/objects/Object/getPosition.md index e69de29..b4e35e5 100644 --- a/docs/objects/Object/getPosition.md +++ b/docs/objects/Object/getPosition.md @@ -0,0 +1,6 @@ +## getPosition +Returns the object's position + +#### Returns: +1. `number` x +2. `number` y diff --git a/docs/objects/Object/getSize.md b/docs/objects/Object/getSize.md index e69de29..70ca747 100644 --- a/docs/objects/Object/getSize.md +++ b/docs/objects/Object/getSize.md @@ -0,0 +1,6 @@ +## getSize +Returns the object's size + +#### Returns: +1. `number` w +2. `number` h diff --git a/docs/objects/Object/onClick.md b/docs/objects/Object/onClick.md index 1ccbbe4..31f1d4d 100644 --- a/docs/objects/Object/onClick.md +++ b/docs/objects/Object/onClick.md @@ -17,4 +17,31 @@ 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() ``` \ No newline at end of file diff --git a/docs/objects/Object/onDrag.md b/docs/objects/Object/onDrag.md index 9589cd7..0fe014d 100644 --- a/docs/objects/Object/onDrag.md +++ b/docs/objects/Object/onDrag.md @@ -2,8 +2,7 @@ `onDrag(self, event, button, x, y, xOffset, yOffset)`
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() ``` diff --git a/docs/objects/Object/setPosition.md b/docs/objects/Object/setPosition.md index 26e3ecd..4ba0413 100644 --- a/docs/objects/Object/setPosition.md +++ b/docs/objects/Object/setPosition.md @@ -1,8 +1,8 @@ ## setPosition Changes the position relative to its parent frame #### Parameters: -1. `number` x coordinate -2. `number` y coordinate +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: @@ -16,4 +16,13 @@ mainFrame:addButton():setPosition(2,3) ``` ```xml