This class has been updated making it easier to use, with more polished looking dropdowns that closer resemble those used in-game.
Note: There have been a number of changes made to the constructor and calls, if you upgrade an existing plugin using version 1.x of this class, you will have a bit of recoding to do (sorry).
Usage
someDropDown = DropDown(list,default) -- list is the table of strings to include, default [optional] is the string to display on creation.
Methods
DropDown:Close(); -- Forces the dropdown list to close, needed for customised lists
DropDown:GetAlignment(); -- Gets the alignment of the text
DropDown:GetListBox(); -- Returns the ListBox used in the dropdown for customised lists
DropDown:GetMaxItems(); -- Gets the number of items displayed in the dropdown before a scrollbar is used
DropDown:GetText(); -- Gets the text in the dropdown
DropDown:IsEnabled();
DropDown:Reset(); -- Scrolls back to the top item in the list
DropDown:SetAlignment(ContentAlignment); -- Sets the text alignment for the labels in the dropdown
DropDown:SetEnabled(value);
DropDown:SetParent(control);
DropDown:SetPosition(left,top);
DropDown:SetMaxItems(value); -- Sets the number of items displayed in the dropdown before a scrollbar is used
DropDown:SetText(string); -- Sets the text of the dropdown
DropDown:SetVisible(value);
DropDown:SetWidth(value);
Disabled Methods
SetHeight(), SetSize() -- Only width can be set using SetWidth(value)
Events
DropDown.ItemChanged(Sender,Args) -- Event Sender, Event Args (Args.Index,Args.Text)
Example
local listTable = {"First Label","Second Label","Third Label"}; -- table of strings used to create the dropdown
someDropDown = DropDown(listTable);
someDropDown:SetParent(control);
someDropDown:SetPosition(20,50);
someDropDown.ItemChanged = function (Sender,Args)
Turbine.Shell.WriteLine("Index: "..Args.Index..", Text: "..Args.Text);
end
The class comes with a fully functioning example which can be loaded in-game for demonstration purposes.
|