1 -- Widget is based on the AceGUIWidget-DropDown.lua supplied with AceGUI-3.0
2 -- Widget created by Yssaril
4 local AceGUI = LibStub("AceGUI-3.0")
5 local Media = LibStub("LibSharedMedia-3.0")
7 local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0")
10 local widgetType = "LSM30_Font"
11 local widgetVersion = 9
13 local contentFrameCache = {}
14 local function ReturnSelf(self)
18 table.insert(contentFrameCache, self)
21 local function ContentOnClick(this, button)
23 self:Fire("OnValueChanged", this.text:GetText())
25 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
29 local function GetContentLine()
31 if next(contentFrameCache) then
32 frame = table.remove(contentFrameCache)
34 frame = CreateFrame("Button", nil, UIParent)
37 frame:SetHighlightTexture([[Interface\QuestFrame\UI-QuestTitleHighlight]], "ADD")
38 frame:SetScript("OnClick", ContentOnClick)
39 local check = frame:CreateTexture("OVERLAY")
42 check:SetPoint("LEFT",frame,"LEFT",1,-1)
43 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
46 local text = frame:CreateFontString(nil,"OVERLAY","GameFontWhite")
47 text:SetPoint("LEFT", check, "RIGHT", 1, 0)
48 text:SetPoint("RIGHT", frame, "RIGHT", -2, 0)
49 text:SetJustifyH("LEFT")
50 text:SetText("Test Test Test Test Test Test Test")
52 frame.ReturnSelf = ReturnSelf
58 local function OnAcquire(self)
63 local function OnRelease(self)
66 self:SetDisabled(false)
73 self.frame:ClearAllPoints()
77 local function SetValue(self, value) -- Set the value to an item in the List.
79 self:SetText(value or "")
84 local function GetValue(self)
88 local function SetList(self, list) -- Set the list of values for the dropdown (key => value pairs)
89 self.list = list or Media:HashTable("font")
92 local function SetText(self, text) -- Set the text displayed in the box.
93 self.frame.text:SetText(text or "")
94 local font = self.list[text] ~= text and self.list[text] or Media:Fetch('font',text)
95 local _, size, outline= self.frame.text:GetFont()
96 self.frame.text:SetFont(font,size,outline)
99 local function SetLabel(self, text) -- Set the text for the label.
100 self.frame.label:SetText(text or "")
103 local function AddItem(self, key, value) -- Add an item to the list.
104 self.list = self.list or {}
105 self.list[key] = value
107 local SetItemValue = AddItem -- Set the value of a item in the list. <<same as adding a new item>>
109 local function SetMultiselect(self, flag) end -- Toggle multi-selecting. <<Dummy function to stay inline with the dropdown API>>
110 local function GetMultiselect() return false end-- Query the multi-select flag. <<Dummy function to stay inline with the dropdown API>>
111 local function SetItemDisabled(self, key) end-- Disable one item in the list. <<Dummy function to stay inline with the dropdown API>>
113 local function SetDisabled(self, disabled) -- Disable the widget.
114 self.disabled = disabled
122 local function textSort(a,b)
123 return string.upper(a) < string.upper(b)
126 local sortedlist = {}
127 local function ToggleDrop(this)
128 local self = this.obj
129 if self.dropdown then
130 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
133 AceGUI:SetFocus(self)
134 self.dropdown = AGSMW:GetDropDownFrame()
135 self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
136 for k, v in pairs(self.list) do
137 sortedlist[#sortedlist+1] = k
139 table.sort(sortedlist, textSort)
140 for i, k in ipairs(sortedlist) do
141 local f = GetContentLine()
142 local _, size, outline= f.text:GetFont()
143 local font = self.list[k] ~= k and self.list[k] or Media:Fetch('font',k)
144 f.text:SetFont(font,size,outline)
146 if k == self.value then
150 self.dropdown:AddFrame(f)
156 local function ClearFocus(self)
157 if self.dropdown then
158 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
162 local function OnHide(this)
163 local self = this.obj
164 if self.dropdown then
165 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
169 local function Drop_OnEnter(this)
170 this.obj:Fire("OnEnter")
173 local function Drop_OnLeave(this)
174 this.obj:Fire("OnLeave")
177 local function Constructor()
178 local frame = AGSMW:GetBaseFrame()
181 self.type = widgetType
184 frame.dropButton.obj = self
185 frame.dropButton:SetScript("OnEnter", Drop_OnEnter)
186 frame.dropButton:SetScript("OnLeave", Drop_OnLeave)
187 frame.dropButton:SetScript("OnClick",ToggleDrop)
188 frame:SetScript("OnHide", OnHide)
190 self.alignoffset = 31
192 self.OnRelease = OnRelease
193 self.OnAcquire = OnAcquire
194 self.ClearFocus = ClearFocus
195 self.SetText = SetText
196 self.SetValue = SetValue
197 self.GetValue = GetValue
198 self.SetList = SetList
199 self.SetLabel = SetLabel
200 self.SetDisabled = SetDisabled
201 self.AddItem = AddItem
202 self.SetMultiselect = SetMultiselect
203 self.GetMultiselect = GetMultiselect
204 self.SetItemValue = SetItemValue
205 self.SetItemDisabled = SetItemDisabled
206 self.ToggleDrop = ToggleDrop
208 AceGUI:RegisterAsWidget(self)
212 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)