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 = 11
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("TOPLEFT", check, "TOPRIGHT", 1, 0)
48 text:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -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 local width = self.frame:GetWidth()
136 self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
137 self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0)
138 for k, v in pairs(self.list) do
139 sortedlist[#sortedlist+1] = k
141 table.sort(sortedlist, textSort)
142 for i, k in ipairs(sortedlist) do
143 local f = GetContentLine()
144 local _, size, outline= f.text:GetFont()
145 local font = self.list[k] ~= k and self.list[k] or Media:Fetch('font',k)
146 f.text:SetFont(font,size,outline)
148 if k == self.value then
152 self.dropdown:AddFrame(f)
158 local function ClearFocus(self)
159 if self.dropdown then
160 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
164 local function OnHide(this)
165 local self = this.obj
166 if self.dropdown then
167 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
171 local function Drop_OnEnter(this)
172 this.obj:Fire("OnEnter")
175 local function Drop_OnLeave(this)
176 this.obj:Fire("OnLeave")
179 local function Constructor()
180 local frame = AGSMW:GetBaseFrame()
183 self.type = widgetType
186 frame.dropButton.obj = self
187 frame.dropButton:SetScript("OnEnter", Drop_OnEnter)
188 frame.dropButton:SetScript("OnLeave", Drop_OnLeave)
189 frame.dropButton:SetScript("OnClick",ToggleDrop)
190 frame:SetScript("OnHide", OnHide)
192 self.alignoffset = 31
194 self.OnRelease = OnRelease
195 self.OnAcquire = OnAcquire
196 self.ClearFocus = ClearFocus
197 self.SetText = SetText
198 self.SetValue = SetValue
199 self.GetValue = GetValue
200 self.SetList = SetList
201 self.SetLabel = SetLabel
202 self.SetDisabled = SetDisabled
203 self.AddItem = AddItem
204 self.SetMultiselect = SetMultiselect
205 self.GetMultiselect = GetMultiselect
206 self.SetItemValue = SetItemValue
207 self.SetItemDisabled = SetItemDisabled
208 self.ToggleDrop = ToggleDrop
210 AceGUI:RegisterAsWidget(self)
214 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)