Skip to content

Commit 51f6ebe

Browse files
committed
docs updates
1 parent 4d227af commit 51f6ebe

15 files changed

+630
-22
lines changed

docs/_sidebar.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@
2929
- [Button coloring](tips/buttonColoring.md)
3030
- [Designing/Animating](tips/design.md)
3131
- [Dynamic Values](tips/dynamicvalues.md)
32+
- [XML](tips/xml.md)

docs/installer.lua

+487
Large diffs are not rendered by default.

docs/objects/Animation/changeBackground.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Changes the background color while the animation is running
1414
```lua
1515
local mainFrame = basalt.createFrame()
1616
local testButton = mainFrame:addButton("buttonToAnimate")
17-
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeBackground({colors.red, colors.yellow, colors.green}, 2):play()
17+
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor(2, 0, colors.red, colors.yellow, colors.green):play()
1818
```
1919
```xml
2020
<animation object="buttonToAnimate" play="true">
@@ -25,4 +25,4 @@ local aAnimation = mainFrame:addAnimation():setObject(testButton):changeBackgrou
2525
<duration>2</duration>
2626
</background>
2727
</animation>
28-
```
28+
```

docs/objects/Animation/changeText.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Changes the text while animation is running
1414
```lua
1515
local mainFrame = basalt.createFrame()
1616
local testButton = mainFrame:addButton("buttonToAnimate")
17-
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeText({"i", "am", "groot"}, 2):play()
17+
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeText(2, 0, "i", "am", "groot"):play()
1818
```
1919
```xml
2020
<animation object="buttonToAnimate" play="true">

docs/objects/Animation/changeTextColor.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Changes the text color while the animation is running
1414
```lua
1515
local mainFrame = basalt.createFrame()
1616
local testButton = mainFrame:addButton("buttonToAnimate")
17-
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
17+
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor(2, 0, colors.red, colors.yellow, colors.green):play()
1818
```
1919
```xml
2020
<animation object="buttonToAnimate" play="true">

docs/objects/Button.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ end)
2424

2525
and this would be the xml way:
2626
```lua
27-
local main = basalt.createFrame():addLayout("example.xml")
28-
2927
basalt.setVariable("buttonClick", function(self,event,button,x,y)
3028
if(event=="mouse_click")and(button==1)then
3129
basalt.debug("Left mousebutton got clicked!")
3230
end
3331
end)
32+
33+
local main = basalt.createFrame():addLayout("example.xml")
3434
```
3535
```xml
3636
<button onClick="buttonClick" text="Click" />

docs/objects/Checkbox/setSymbol.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## setSymbol
2+
Changes the checkbox symbol, default is "\42"
3+
4+
#### Parameters:
5+
1. `string` symbol
6+
7+
#### Returns:
8+
1. `object` The object in use
9+
10+
#### Usage:
11+
* Creates a new checkbox and changes the symbol to o
12+
```lua
13+
local main = basalt.createFrame()
14+
local checkbox = main:addCheckbox():setSymbol("o")
15+
```
16+
```xml
17+
<checkbox symbol="o" />
18+
```
+5-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
## removeFocusedObject
2-
Removes the focus of the supplied object
3-
4-
#### Parameters:
5-
1. `object` The child object to remove focus from
2+
Removes the currently focused object of that frame
63

74
#### Returns:
85
1. `frame` The frame being used
96

107
#### Usage:
118
* Creates a new button then removes the focus from that button when clicking on it
129
```lua
13-
local aButton = myFrame:addButton():setFocus():onClick(function()
14-
myFrame:removeFocusedObject(aButton)
10+
local main = basalt.createFrame()
11+
local input = main:addInput():setFocus()
12+
local aButton = main:addButton():onClick(function()
13+
main:removeFocusedObject()
1514
end)
1615
```

docs/objects/Frame/removeObject.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
Removes a child object from the frame
33

44
#### Parameters:
5-
1. `string` The name of the child object
5+
1. `string|object` The name of the child object or the object itself
66

77
#### Returns:
88
1. `boolean` Whether the object with the given name was properly removed
99

1010
#### Usage:
1111
* Adds a button with the id "myFirstButton", then removes it with the aforementioned id
1212
```lua
13-
myFrame:addButton("myFirstButton")
14-
myFrame:removeObject("myFirstButton")
13+
local main = basalt.createFrame()
14+
main:addButton("myFirstButton"):setText("Close")
15+
:onClick(function(self)
16+
main:removeObject("myFirstButton") -- or main:removeObject(self)
17+
end)
1518
```

docs/objects/Image/loadImage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ loads a default .nfp file into the object.
1010
#### Usage:
1111
* Creates a default image and loads a test.nfp file
1212
```lua
13-
local mainFrame = basalt.createFrame():show()
13+
local mainFrame = basalt.createFrame()
1414
local aImage = mainFrame:addImage():loadImage("test.nfp")
1515
```
1616
```xml

docs/objects/Object/getBackground.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## getBackground
2+
Returns the current background color
3+
4+
#### Returns:
5+
1. `number` color

docs/objects/Object/getForeground.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## getForeground
2+
Returns the current foreground color
3+
4+
#### Returns:
5+
1. `number` color

docs/objects/Object/remove.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## remove
2+
Removes the object from it's parent frame. This won't 'destroy' the object, It will continue to exist as long as you still have pointers to it.
3+
4+
Here is a example on how a button will be fully removed from the memory:
5+
```lua
6+
local main = basalt.createFrame()
7+
local button = main:addButton():setPosition(2,2):setText("Close")
8+
9+
button:remove()
10+
button = nil
11+
```

docs/objects/Scrollbar.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Scrollbars are objects, the user can scroll vertically or horizontally, this wil
44

55
| | |
66
|---|---|
7-
|[setSymbol](objects/Scrollbar/setSymbol.md)|Sets the scrollbar symbol
8-
|[setBackgroundSymbol](objects/Scrollbar/setBackgroundSymbol.md)|Sets the background symbol
9-
|[setBarType](objects/Scrollbar/setBarType.md)|Sets the bar type (vertical or horizontal)
10-
|[setMaxValue](objects/Scrollbar/setMaxValue.md)|Sets the maximum value
11-
|[setIndex](objects/Scrollbar/setIndex.md)|Sets the current index
12-
|[getIndex](objects/Scrollbar/getIndex.md)|Returns the index
7+
|[setSymbol](objects/Slider/setSymbol.md)|Sets the slider symbol
8+
|[setBackgroundSymbol](objects/Slider/setBackgroundSymbol.md)|Sets the background symbol
9+
|[setBarType](objects/Slider/setBarType.md)|Sets the bar type (vertical or horizontal)
10+
|[setMaxValue](objects/Slider/setMaxValue.md)|Sets the maximum value
11+
|[setIndex](objects/Slider/setIndex.md)|Sets the current index
12+
|[getIndex](objects/Slider/getIndex.md)|Returns the index

docs/tips/xml.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
This is a basic guide on how to create a UI with XML.
2+
3+
In XML you are not able to create logic, but you could refer to logic - i will show you how.
4+
But first i will show you how you are able to create some basic XML design.
5+
6+
First we will need a .lua file - we need to process the XML stuff, and this is only possible in lua.
7+
So let's create a lua file:
8+
9+
```lua
10+
local basalt = require("basalt") -- as always we will need basalt
11+
12+
local main = basalt.createFrame() -- and atleast 1 base frame is needed
13+
14+
basalt.autoUpdate() -- starting the event and draw handler is also needed
15+
```
16+
17+
The code above you are just not able to do in XML, you are not able to create base frames and you are also not able to start the event/draw handlers.
18+
This can only be done in Lua.
19+
20+
In Basalt XML Code will always be loaded into frames. Which means all the objects created in XML are always childrens of that particular frame. Here is a example to show what i mean:
21+
22+
Lua:
23+
```lua
24+
local basalt = require("basalt")
25+
local main = basalt.createFrame():addLayout("example.xml")
26+
basalt.autoUpdate()
27+
```
28+
29+
XML:
30+
```xml
31+
<button x="5" y="3" text="Hello" />
32+
```
33+
34+
This would be exactly the same like if you would use the following lua code:
35+
```lua
36+
local basalt = require("basalt")
37+
local main = basalt.createFrame()
38+
main:addButton():setPosition(5, 3):setText("Hello")
39+
basalt.autoUpdate()
40+
```
41+
42+
You can also add a layout multiple times, or create multiple frames and always use the same layout. For example a design layout for more frames and then you could also use
43+
a unique layout for each frame. I wont show you a example, you just have to use :addLayout multiple times on different frames.
44+
45+
Another thing is, you could add/load XML files IN XML:
46+
example.xml:
47+
```xml
48+
<frame layout="anotherExample.xml" />
49+
```
50+
51+
anotherExample.xml:
52+
```xml
53+
<button x="2" y="3" width="parent.w - 2" text="Greetings" />
54+
```
55+
56+
# Events
57+
58+
Using events in XML is also pretty simple. For that basalt has a function called basalt.setVariable. This is to store functions or other things which you can access via
59+
XML. Obviously the logic you want to add has to be done in lua, here:
60+
61+
Lua:
62+
```lua
63+
local basalt = require("basalt")
64+
65+
basalt.setVariable("buttonClick", function()
66+
basalt.debug("i got clicked!")
67+
end)
68+
69+
local main = basalt.createFrame():addLayout("example.xml")
70+
basalt.autoUpdate()
71+
```
72+
73+
And then you just have to link your function in your XML file:
74+
```xml
75+
<button x="2" y="3" width="parent.w - 2" text="Greetings" onClick="buttonClick" />
76+
```
77+
78+
This is pretty simple! BUT there is one thing you shouldn't forget: In Lua you always have to create the function's before you want to access it, which means
79+
always use basalt.setVariable before you use frame:addLayout() - otherwise basalt is not able to find the function

0 commit comments

Comments
 (0)