|
| 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