8.4 KiB
Menubars are like lists but instead of being vertical, they are horizontal. Imagine you are creating a Operating System and you would like to add a taskbar, menubars would be exactly what you need, because they are also scrollable, which means they have endless entry possibility.
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 = {}
}
Here are all possible functions available for menubars. Remember menubar inherits from Object
addItem
Adds a item into the menubar
Parameters:
stringThe entry namenumber|colorunique default background colornumber|colorunique default text coloranyany value - you could access this later in a :onChange() event (you need to use :getValue()).
Returns:
objectThe object in use
Usage:
- Creates a default menubar with 3 entries
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
removeItem
Removes a item from the menubar
Parameters:
numberThe index which should get removed
Returns:
objectThe object in use
Usage:
- Creates a default menubar with 3 entries and removes the second one.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:removeItem(2)
editItem
Edits item from the menubar
Parameters:
numberThe index which should be editedstringThe new item namenumberthe new item background colornumberThe new item text coloranyNew additional information
Returns:
objectThe object in use
Usage:
- Creates a default menubar with 3 entries and edits the second one.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:editItem(2, "Still 2. Entry", 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 menubar with 3 entries and edits the second one.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:editItem(2, "Still 2. Entry", colors.red)
getItemCount
Returns the current item count
Returns:
numberThe item list count
Usage:
- Creates a default menubar with 3 entries and prints the current item count.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aMenubar: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("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aMenubar:getAll())
setSpace
Sets the space between entries
Parameters:
numberThe space between each entry
Returns:
objectThe object in use
Usage:
- Creates a default menubar with 3 entries and changes the space to 3.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:setSpace(3)
setScrollable
Makes the menubar scrollable. The menubar will be scrollable as soon as the menubar is to small for all the entries.
Parameters:
booleanif this menubar should be scrollable or not
Returns:
objectThe object in use
Usage:
- Creates a default menubar with 3 entries and makes it scrollable.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:setScrollable(true)
selectItem
selects a item in the list (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 menubar with 3 entries and selects the second entry.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:selectItem(2)
clear
Removes all items.
Returns:
objectThe object in use
Usage:
- Creates a default menubar with 3 entries and removes them immediatley. Which makes no sense.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:clear()
getItemIndex
returns the item index of the currently selected item
Returns:
numberThe current index
Usage:
- Creates a default menubar with 3 entries selects the second entry and prints the currently selected index.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:selectItem(2)
basalt.debug(aMenubar: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 menubar with 4 entries and sets the selection background color to green.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry")
aMenubar:addItem("3. Entry")
aMenubar:addItem("4. Entry")
aMenubar:setSelectedItem(colors.green)
setPositionOffset
Sets the offset of the menubar (the same as you would scroll) - default is 0
Parameters:
numberThe offset value
Returns:
objectThe object in use
Usage:
- Creates a default menubar with 6 entries and sets the offset to 3.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry")
aMenubar:addItem("3. Entry")
aMenubar:addItem("4. Entry")
aMenubar:addItem("5. Entry")
aMenubar:addItem("6. Entry")
aMenubar:setPositionOffset(3)
getPositionOffset
returns the current offset
Returns:
numberCurrent offset
Usage:
- Creates a default menubar with 6 entries and sets the offset to 3.
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry")
aMenubar:addItem("3. Entry")
aMenubar:addItem("4. Entry")
aMenubar:addItem("5. Entry")
aMenubar:addItem("6. Entry")
aMenubar:setPositionOffset(3)
basalt.debug(aMenubar:getPositionOffset())