API Documentation

The MultiSelect inherits all of the general widget API found at the top of the AceGUI Widget page. Widget specific documentations found below:

Documentation:

APIs
  • SetLabel(string) - Sets the text label for the widget. Takes a string as a parameter.
  • SetMultiSelect(boolean) - Sets the multi-select behavior of the widget. Takes a boolean value as a parameter. If true, multiple items can be selected simultaneously; if false, only one item can be selected. Default is true.
  • AddItem(string) - Creates a new item in the widget. Takes a string as a parameter.
  • GetItem(string) - Returns the first item object with a value matching the input string. Takes a string as a parameter.
  • GetText(item) - Returns the text of the given item object. Takes an item object as a parameter.
  • SetText(item, string) - Sets the text of the given item object. Takes an item object and a string (the new text) as parameters.
  • IsSelected(item) - Returns if the given item object is currently selected. Takes an item object as a parameter.
  • GetSelected() - Returns a table of all the currently selected items in the widget. No parameters.
  • SetSelected(item) - Sets the given item to selected. Takes an item object as a parameter.
  • SetItemList(table) - Sets the items of the widget to the values of the given table. Any current items will be lost. Takes a table of strings as a parameter.
  • RemoveItem(item) - Removes the first instance of the matching item from the widget. Takes an item object as a parameter.
Callbacks
  • OnLabelClick(item) - Fires when an item is clicked on in the widget. Returns the clicked item object.
  • OnLabelEnter(item) - Fires when the cursor enters the frame of an item in the widget. Returns the given item object.
  • OnLabelLeave(item) - Fires when the cursor leaves the frame of an item in the widget. Returns the given item object.


Code Examples:

All of the examples will assume that AceGUI-3.0 has been added to the project as defined on the AceGUI page, and is named "AceGUI".

Embed the MultiSelect widget for use:

First place the MultiSelect folder in your addon directory, then embed it in your XML file as follows:

<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
    <Include file="Libs\AceAddon-3.0\AceAddon-3.0.xml"/>
    <Include file="Libs\AceEvent-3.0\AceEvent-3.0.xml" />
    <Include file="Libs\AceGUI-3.0\AceGUI-3.0.xml"/>

    <!--If you are not placing the widget files in the root directory of your addon, 
        change the path to match the location of the MultiSelect Files-->
    <Include file="MultiSelect\MultiSelect.xml" />  

</Ui>

Create a new MultiSelect widget:

local itemList = {"Item1", "Item2", "Item3", "Item4"}

local myMultiSelect = AceGUI:Create("MultiSelect")
    myMultiSelect:SetLabel("My Multi Select")
    myMultiSelect:SetWidth(200)
    myMultiSelect:SetHeight(300)
    myMultiSelect:SetItemList(itemList)

Set the text of an existing item using the current text to find the item object:

Code continues from above example.

myMultiSelect:SetText(myMultiSelect:GetItem("Item1"), "NewItem")

Handling the "OnLabelClick" event:

Code continues from above example.

myMultiSelect:SetCallback("OnLabelClick", function(widget, event, value)
    if myMultiSelect:IsSelected(value) then
        if myMultiSelect:GetText(value) == "NewItem" then
            print ("You clicked on the item "..myMultiSelect:GetText(value))
        end
    end
end)

Interacting with other widgets:

Code continues from above example.

local myButton = AceGUI:Create("Button")
myButton:SetText("Click Me!")
myButton:SetCallback("OnClick", function ()
    local selectedItems = myMultiSelect:GetSelected()
    for _, item in pairs(selectedItems) do
        if myMultiSelect:GetText(item) == "NewItem" then
            print ("The item "..myMultiSelect:GetText(item).." is currently selected.")
        end
    end
end)

Comments

Posts Quoted:
Reply
Clear All Quotes