comparison SelectorList.lua @ 52:7c7e80f63b51

First pass. Taking stuff from TreeGroup that I like/need/want in order to make a standalone selection list
author John@Yosemite-PC
date Sat, 24 Mar 2012 13:37:29 -0400
parents
children 708d8a423b4c
comparison
equal deleted inserted replaced
51:11f18e279229 52:7c7e80f63b51
1 -- no bsk namespace here - we're hooking into AceGUI
2
3 local Type, Version = "SelectorList", 34
4 local AceGUI = LibStub and LibStub("AceGUI-3.0",true)
5 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
6
7 local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type
8 local math_min, math_max, floor = math.min, math.max, floor
9 local select, tremove, unpack, tconcat = select, table.remove, unpack, table.concat
10
11 local CreateFrame, UIParent = CreateFrame, UIParent
12
13 local new, del
14 do
15 local pool = setmetatable({},{__mode='k'})
16 function new()
17 local t = next(pool)
18 if t then
19 pool[t] = nil
20 return t
21 else
22 return {}
23 end
24 end
25 function del(t)
26 for k in pairs(t) do
27 t[k] = nil
28 end
29 pool[t] = true
30 end
31 end
32
33 local DEFAULT_SL_WIDTH = 175
34 --local DEFAULT_TREE_SIZABLE = true
35
36
37 local function Layout(self)
38 self:SetHeight(self.numlines * 18 + 20)
39
40 end
41
42 local function CreateButton(widget)
43 local num = AceGUI:GetNextWidgetNum("TreeGroupButton")
44 local button = CreateFrame("Button", ("AceGUI30TreeButton%d"):format(num), widget.slframe, "OptionsListButtonTemplate")
45 button.obj = widget
46
47 local icon = button:CreateTexture(nil, "OVERLAY")
48 icon:SetWidth(14)
49 icon:SetHeight(14)
50 button.icon = icon
51
52 button:SetScript("OnClick",Button_OnClick)
53 button:SetScript("OnDoubleClick", Button_OnDoubleClick)
54 button:SetScript("OnEnter",Button_OnEnter)
55 button:SetScript("OnLeave",Button_OnLeave)
56
57 return button
58 end
59
60 local function UpdateButton(button, line, selected)
61 local self = button.obj
62 local frame = self.frame
63 local text = line.text or ""
64 local icon = line.icon
65 local iconCoords = line.iconCoords
66 local level = line.level or 1
67 local value = line.value
68 local uniquevalue = line.uniquevalue
69 local disabled = line.disabled
70
71 button.line = line
72 button.value = value
73 button.uniquevalue = uniquevalue
74 if selected then
75 button:LockHighlight()
76 button.selected = true
77 else
78 button:UnlockHighlight()
79 button.selected = false
80 end
81 local normalTexture = button:GetNormalTexture()
82 local line = button.line
83 button.level = level
84 if ( level == 1 ) then
85 button:SetNormalFontObject("GameFontNormal")
86 button:SetHighlightFontObject("GameFontHighlight")
87 button.text:SetPoint("LEFT", (icon and 16 or 0) + 8, 2)
88 else
89 button:SetNormalFontObject("GameFontHighlightSmall")
90 button:SetHighlightFontObject("GameFontHighlightSmall")
91 button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2)
92 end
93
94 if disabled then
95 button:EnableMouse(false)
96 button.text:SetText("|cff808080"..text..FONT_COLOR_CODE_CLOSE)
97 else
98 button.text:SetText(text)
99 button:EnableMouse(true)
100 end
101
102 if icon then
103 button.icon:SetTexture(icon)
104 button.icon:SetPoint("LEFT", 8 * level, (level == 1) and 0 or 1)
105 else
106 button.icon:SetTexture(nil)
107 end
108
109 if iconCoords then
110 button.icon:SetTexCoord(unpack(iconCoords))
111 else
112 button.icon:SetTexCoord(0, 1, 0, 1)
113 end
114 end
115
116
117 local methods = {
118
119 ["OnAcquire"] = function(self)
120 self:SetWidth(DEFAULT_SL_WIDTH)
121 self:SetNumLines()
122 --self:EnableButtonTooltips(true)
123 end,
124 --["SetWidth"] = function(self, width)
125 -- self.slframe:SetWidth(width)
126
127 -- local status = self.status or self.localstatus
128 -- status.width = width
129 -- status.treesizable = resizable
130
131 --end,
132 ["SetNumLines"] = function(self,value)
133 if not value or value < 4 then
134 value = 4
135 end
136 self.numlines = value
137 Layout(self)
138 end,
139 ["SetList"] = function(self, list)
140 for i,v in ipairs(list) do
141 self.lines[i] = v
142 end
143 self:Refresh()
144 end,
145 ["Refresh"] = function(self)
146 local f = self.slframe
147 local buttons = self.buttons
148 local lines = self.lines
149
150 local bnum = 1
151 for i=1,self.numlines do
152 local l = lines[i]
153 if not l then
154 break
155 end
156 local b = buttons[bnum]
157 if not b then
158 b = CreateButton(self)
159 buttons[bnum] = b
160 b:SetParent(f)
161 b:SetFrameLevel(f:GetFrameLevel()+1)
162 b:ClearAllPoints()
163 if bnum == 1 then
164 -- todo: if scroll ...
165 b:SetPoint("TOPLEFT",0,-10)
166 b:SetPoint("TOPRIGHT",0,-10)
167 else
168 b:SetPoint("TOPRIGHT", buttons[bnum-1], "BOTTOMRIGHT", 0, 0)
169 b:SetPoint("TOPLEFT", buttons[bnum-1], "BOTTOMLEFT", 0, 0)
170 end
171 end
172 UpdateButton(b, l)
173 b:Show()
174 bnum = bnum + 1
175 end
176 end,
177 }
178
179
180
181
182
183
184
185
186
187 local PaneBackdrop = {
188 bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
189 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
190 tile = true, tileSize = 16, edgeSize = 16,
191 insets = { left = 3, right = 3, top = 5, bottom = 3 }
192 }
193
194 local function Constructor()
195 local num = AceGUI:GetNextWidgetNum(Type)
196 local frame = CreateFrame("Frame", nil, UIParent)
197
198 local slframe = CreateFrame("Frame", nil, frame)
199 slframe:SetAllPoints()
200 --slframe:SetPoint("TOPLEFT")
201 --slframe:SetPoint("BOTTOMLEFT")
202 --slframe:SetWidth(DEFAULT_SL_WIDTH)
203 --slframe:SetHeight(DEFAULT_SL_WIDTH) -- todo
204 slframe:EnableMouseWheel(true)
205 slframe:SetBackdrop(PaneBackdrop)
206 slframe:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
207 slframe:SetBackdropBorderColor(0.4, 0.4, 0.4)
208 --slframe:SetResizable(true)
209 --slframe:SetMinResize(100, 1)
210 --slframe:SetMaxResize(400, 1600)
211 --slframe:SetScript("OnUpdate", FirstFrameUpdate)
212 --slframe:SetScript("OnSizeChanged", Tree_OnSizeChanged)
213 --slframe:SetScript("OnMouseWheel", Tree_OnMouseWheel)
214
215 --local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), slframe, "UIPanelScrollBarTemplate")
216 --scrollbar:SetScript("OnValueChanged", nil)
217 --scrollbar:SetPoint("TOPRIGHT", -10, -26)
218 --scrollbar:SetPoint("BOTTOMRIGHT", -10, 26)
219 --scrollbar:SetMinMaxValues(0,0)
220 --scrollbar:SetValueStep(1)
221 --scrollbar:SetValue(0)
222 --scrollbar:SetWidth(16)
223 --scrollbar:SetScript("OnValueChanged", OnScrollValueChanged)
224
225 --local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND")
226 --scrollbg:SetAllPoints(scrollbar)
227 --scrollbg:SetTexture(0,0,0,0.4)
228
229 --local border = CreateFrame("Frame",nil,frame)
230 --border:SetPoint("TOPLEFT", slframe, "TOPRIGHT")
231 --border:SetPoint("BOTTOMRIGHT")
232 --border:SetBackdrop(PaneBackdrop)
233 --border:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
234 --border:SetBackdropBorderColor(0.4, 0.4, 0.4)
235
236 ----Container Support
237 --local content = CreateFrame("Frame", nil, border)
238 --content:SetPoint("TOPLEFT", 10, -10)
239 --content:SetPoint("BOTTOMRIGHT", -10, 10)
240
241 local widget = {
242 frame = frame,
243 lines = {},
244 --levels = {},
245 buttons = {},
246 --hasChildren = {},
247 localstatus = {
248 --groups = {},
249 scrollvalue = 0 },
250 filter = false,
251 slframe = slframe,
252 --dragger = dragger,
253 --scrollbar = scrollbar,
254 --border = border,
255 --content = slframe, -- content is for containers
256 type = Type
257 }
258 if methods then
259 for method, func in pairs(methods) do
260 widget[method] = func
261 end
262 end
263 slframe.obj = widget
264 --dragger.obj = widget
265 --scrollbar.obj = widget
266
267 return AceGUI:RegisterAsWidget(widget)
268 end
269
270 AceGUI:RegisterWidgetType(Type, Constructor, Version)
271
272
273
274