|
| 1 | +After downloading the project you can finally start creating your own program and use basalt. The first thing you want to use in your program is always: |
| 2 | + |
| 3 | +```lua |
| 4 | +local basalt = require("basalt") |
| 5 | +``` |
| 6 | + |
| 7 | +It doesn't matter if you're using the source folder or the minified/packed version of basalt. Both can be found by using require("basalt") without .lua. |
| 8 | + |
| 9 | +Also to really run basalt you should use |
| 10 | + |
| 11 | +```lua |
| 12 | +basalt.autoUpdate() |
| 13 | +``` |
| 14 | + |
| 15 | +somewhere on the bottom of your program. basalt.autoUpdate() starts the event listener and the draw handler. |
| 16 | + |
| 17 | +## Example |
| 18 | + |
| 19 | +Here is a fully working example of how a program could look like: |
| 20 | + |
| 21 | +```lua |
| 22 | +local basalt = require("basalt") --> Load the basalt framework into the variable called "basalt" |
| 23 | + |
| 24 | +--> Now we want to create a base frame, we call the variable "main" - by default everything you create is visible. (you don't need to use :show()) |
| 25 | +local main = basalt.createFrame() |
| 26 | + |
| 27 | +local button = mainFrame:addButton() --> Here we add our first button |
| 28 | +button:setPosition(4, 4) -- of course we want to change the default position of our button |
| 29 | +button:setSize(16, 3) -- and the default size. |
| 30 | +button:setText("Click me!") --> This method displays what the text of our button should look like |
| 31 | + |
| 32 | +local function buttonClick() --> Let us create a function we want to call when the button gets clicked |
| 33 | + basalt.debug("I got clicked!") |
| 34 | +end |
| 35 | + |
| 36 | +-- Now we just need to register the function to the buttons onClick event handlers, this is how we can achieve that: |
| 37 | +button:onClick(buttonClick) |
| 38 | + |
| 39 | + |
| 40 | +basalt.autoUpdate() -- As soon as we call basalt.autoUpdate, the event and draw handlers will listen to any incomming events (and draw if necessary) |
| 41 | +``` |
| 42 | + |
| 43 | +If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above: |
| 44 | + |
| 45 | +```lua |
| 46 | +local basalt = require("basalt") |
| 47 | + |
| 48 | +local main = basalt.createFrame() |
| 49 | +local button = main --> Basalt returns an instance of the object on most methods, to make use of "call-chaining" |
| 50 | + :addButton() --> This is an example of call chaining |
| 51 | + :setPosition(4,4) |
| 52 | + :setText("Click me!") |
| 53 | + :onClick( |
| 54 | + function() |
| 55 | + basalt.debug("I got clicked!") |
| 56 | + end) |
| 57 | + |
| 58 | +basalt.autoUpdate() |
| 59 | +``` |
0 commit comments