updated the example

people are still using :show() and supply a id but never use them, probably because the example was not up2date
This commit is contained in:
Robert Jelic
2022-08-12 19:03:13 +02:00
committed by GitHub
parent fb227445df
commit b64f3ef87c

View File

@@ -45,14 +45,11 @@ Here is a fully functioning example of Basalt code
```lua ```lua
local basalt = require("basalt") --> Load the Basalt framework local basalt = require("basalt") --> Load the Basalt framework
--> Create the first frame. Please note that Basalt needs at least one active "non-parent" frame to properly supply events --> Create a base frame. Please note that Basalt needs at least one active base frame to properly supply events
--> When Basalt#createFrame makes use of unique identifiers (commonly referred to as UIDs), meaning that the supplied value must be UNIQUE local mainFrame = basalt.createFrame()
local mainFrame = basalt.createFrame("mainFrame")
--> Show the frame to the user
mainFrame:show()
local button = mainFrame:addButton("clickableButton") --> Add a button to the mainFrame (With a unique identifier) local button = mainFrame:addButton() --> Add a button to the mainFrame
--> Set the position of the button, Button#setPosition follows an x, y pattern. --> Set the position of the button, Button#setPosition follows an x, y pattern.
--> The x value is how far right the object should be from its anchor (negative values from an anchor will travel left) --> The x value is how far right the object should be from its anchor (negative values from an anchor will travel left)
@@ -69,24 +66,21 @@ end
--> Make sure the button knows which function to call when it's clicked --> Make sure the button knows which function to call when it's clicked
button:onClick(buttonClick) button:onClick(buttonClick)
button:show() --> Make the button visible, so the user can click it
basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect user input basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect user input
``` ```
If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above: If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above:
```lua ```lua
local basalt = require("basalt") local basalt = require("basalt")
local mainFrame = basalt.createFrame("mainFrame"):show() local mainFrame = basalt.createFrame()
local button = mainFrame --> Basalt returns an instance of the object on most methods, to make use of "call-chaining" local button = mainFrame --> Basalt returns an instance of the object on most methods, to make use of "call-chaining"
:addButton("clickableButton") --> This is an example of call chaining :addButton() --> This is an example of call chaining
:setPosition(4,4) :setPosition(4,4)
:setText("Click me!") :setText("Click me!")
:onClick( :onClick(
function() function()
basalt.debug("I got clicked!") basalt.debug("I got clicked!")
end) end)
:show()
basalt.autoUpdate() basalt.autoUpdate()
``` ```