6.2 KiB
6.2 KiB
Radios are objects which you can freely place, and the user is then able to select a single item.
If you want to access values inside items this is how the table for single items is made (just a example):
item = {
text="1. Entry",
bgCol=colors.black,
fgCol=colors.white
args = {}
}
Remember Radios also inherits from Object
addItem
Adds a item to the radio
Parameters:
stringThe entry namenumberx positionnumbery positionnumber|colorunique default background color - optionalnumber|colorunique default text color - optionalanyany value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
Returns:
objectThe object in use
Usage:
- Creates a default radio with 3 entries
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
<radio>
<item><text>1. Entry</text><x>5</x><y>2</y></item>
<item><text>2. Entry</text><x>5</x><y>4</y><bg>yellow</bg></item>
<item><text>3. Entry</text><x>5</x><y>6</y><bg>yellow</bg><fg>green</fg></item>
</radio>
removeItem
Removes a item from the radio
Parameters:
numberThe index which should get removed
Returns:
objectThe object in use
Usage:
- Creates a default radio with 3 entries and removes the second one.
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:removeItem(2)
editItem
Edits a item from the radio
Parameters:
numberThe index which should be editedstringThe new item namenumberthe new x positionnumberthe new y positionnumber|colorthe new item background color - optionalnumber|colorThe new item text color - optionalanyNew additional information - optional
Returns:
objectThe object in use
Usage:
- Creates a default radio with 3 entries and changes the second one.
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:editItem(2, "Still 2. Entry", 5, 4, colors.red)
getItem
Returns a item by index
Parameters:
numberThe index which should be returned
Returns:
tableThe item table example: {text="1. Entry", bgCol=colors.black, fgCol=colors.white}
Usage:
- Creates a default radio with 3 entries and edits the second one.
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
basalt.debug(aRadio:getItem(2).text)
getItemCount
Returns the current item count
Returns:
numberThe item radio count
Usage:
- Creates a default radio with 3 entries and prints the current item count.
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
basalt.debug(aRadio:getItemCount())
getAll
Returns all items as table
Returns:
tableAll items
Usage:
- Creates a default menubar with 3 entries and prints a table.
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
basalt.debug(aRadio:getAll())
selectItem
selects a item in the radio (same as a player would click on a item)
Parameters:
numberThe index which should get selected
Returns:
objectThe object in use
Usage:
- Creates a default radio with 3 entries and selects the second entry.
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:selectItem(2)
clear
Removes all items.
Returns:
objectThe object in use
Usage:
- Creates a default radio with 3 entries and removes them immediatley. Which makes no sense.
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:clear()
getItemIndex
returns the item index of the currently selected item
Returns:
numberThe current index
Usage:
- Creates a default radio with 3 entries selects the second entry and prints the currently selected index.
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:selectItem(2)
basalt.debug(aRadio:getItemIndex())
setSelectedItem
Sets the background and the foreground of the item which is currently selected
Parameters:
number|colorThe background color which should be usednumber|colorThe text color which should be used
Returns:
objectThe object in use
Usage:
- Creates a default radio with 4 entries and sets the selection background color to green.
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:addItem("4. Entry",5,8)
aRadio:setSelectedItem(colors.green, colors.red)
<radio selectionBG="green" selectionFG="red">
<item><text>1. Entry</text><x>5</x><y>2</y></item>
<item><text>2. Entry</text><x>5</x><y>4</y><bg>yellow</bg></item>
<item><text>3. Entry</text><x>5</x><y>6</y><bg>yellow</bg><fg>green</fg></item>
</radio>