comparison SelectorList.lua @ 53:708d8a423b4c

Scroller functional
author John@Yosemite-PC
date Sat, 24 Mar 2012 14:22:01 -0400
parents 7c7e80f63b51
children c8c17286af95
comparison
equal deleted inserted replaced
52:7c7e80f63b51 53:708d8a423b4c
30 end 30 end
31 end 31 end
32 32
33 local DEFAULT_SL_WIDTH = 175 33 local DEFAULT_SL_WIDTH = 175
34 --local DEFAULT_TREE_SIZABLE = true 34 --local DEFAULT_TREE_SIZABLE = true
35
36 local function SL_OnMouseWheel(frame, delta)
37 local self = frame.obj
38 if self.showscroll then
39 local scrollbar = self.scrollbar
40 local min, max = scrollbar:GetMinMaxValues()
41 local value = scrollbar:GetValue()
42 local newvalue = math_min(max,math_max(min,value - delta))
43 if value ~= newvalue then
44 scrollbar:SetValue(newvalue)
45 end
46 end
47 end
48
49 local function OnScrollValueChanged(frame, value)
50 if frame.obj.noupdate then return end
51 local self = frame.obj
52 local status = self.status or self.localstatus
53 status.scrollvalue = value
54 self:Refresh()
55 AceGUI:ClearFocus()
56 end
57
35 58
36 59
37 local function Layout(self) 60 local function Layout(self)
38 self:SetHeight(self.numlines * 18 + 20) 61 self:SetHeight(self.numlines * 18 + 20)
39 62
112 button.icon:SetTexCoord(0, 1, 0, 1) 135 button.icon:SetTexCoord(0, 1, 0, 1)
113 end 136 end
114 end 137 end
115 138
116 139
140
117 local methods = { 141 local methods = {
118 142
119 ["OnAcquire"] = function(self) 143 ["OnAcquire"] = function(self)
120 self:SetWidth(DEFAULT_SL_WIDTH) 144 self:SetWidth(DEFAULT_SL_WIDTH)
121 self:SetNumLines() 145 self:SetNumLines()
135 end 159 end
136 self.numlines = value 160 self.numlines = value
137 Layout(self) 161 Layout(self)
138 end, 162 end,
139 ["SetList"] = function(self, list) 163 ["SetList"] = function(self, list)
164 self.lines = {}
140 for i,v in ipairs(list) do 165 for i,v in ipairs(list) do
141 self.lines[i] = v 166 self.lines[i] = v
142 end 167 end
143 self:Refresh() 168 self:Refresh()
144 end, 169 end,
170
171 ["ShowScroll"] = function(self, show)
172 self.showscroll = show
173 if show then
174 self.scrollbar:Show()
175 if self.buttons[1] then
176 self.buttons[1]:SetPoint("TOPRIGHT", self.slframe,"TOPRIGHT",-22,-10)
177 end
178 else
179 self.scrollbar:Hide()
180 if self.buttons[1] then
181 self.buttons[1]:SetPoint("TOPRIGHT", self.slframe,"TOPRIGHT",0,-10)
182 end
183 end
184 end,
185
145 ["Refresh"] = function(self) 186 ["Refresh"] = function(self)
146 local f = self.slframe 187 local f = self.slframe
147 local buttons = self.buttons 188 local buttons = self.buttons
148 local lines = self.lines 189 local lines = self.lines
190 local status = self.status or self.localstatus
191
192 for i, v in ipairs(buttons) do
193 v:Hide()
194 end
195 local numlines = #lines
196 local maxlines = self.numlines
197
198 if numlines <= maxlines then
199 status.scrollvalue = 0
200 self:ShowScroll(false)
201 first, last = 1, numlines
202 else
203 self:ShowScroll(true)
204 self.noupdate = true
205 self.scrollbar:SetMinMaxValues(0, numlines - maxlines)
206 if numlines - status.scrollvalue < maxlines then
207 status.scrollvalue = numlines - maxlines
208 end
209 self.noupdate = nil
210 first, last = status.scrollvalue+1, status.scrollvalue + maxlines
211
212 if self.scrollbar:GetValue() ~= status.scrollvalue then
213 self.scrollbar:SetValue(status.scrollvalue)
214 end
215 end
149 216
150 local bnum = 1 217 local bnum = 1
151 for i=1,self.numlines do 218 for i= first, last do
152 local l = lines[i] 219 local l = lines[i]
153 if not l then
154 break
155 end
156 local b = buttons[bnum] 220 local b = buttons[bnum]
157 if not b then 221 if not b then
158 b = CreateButton(self) 222 b = CreateButton(self)
159 buttons[bnum] = b 223 buttons[bnum] = b
160 b:SetParent(f) 224 b:SetParent(f)
161 b:SetFrameLevel(f:GetFrameLevel()+1) 225 b:SetFrameLevel(f:GetFrameLevel()+1)
162 b:ClearAllPoints() 226 b:ClearAllPoints()
163 if bnum == 1 then 227 if bnum == 1 then
164 -- todo: if scroll ... 228 if self.showscroll then
229 b:SetPoint("TOPRIGHT",-22,-10)
230 else
231 b:SetPoint("TOPRIGHT",0,-10)
232 end
165 b:SetPoint("TOPLEFT",0,-10) 233 b:SetPoint("TOPLEFT",0,-10)
166 b:SetPoint("TOPRIGHT",0,-10)
167 else 234 else
168 b:SetPoint("TOPRIGHT", buttons[bnum-1], "BOTTOMRIGHT", 0, 0) 235 b:SetPoint("TOPRIGHT", buttons[bnum-1], "BOTTOMRIGHT", 0, 0)
169 b:SetPoint("TOPLEFT", buttons[bnum-1], "BOTTOMLEFT", 0, 0) 236 b:SetPoint("TOPLEFT", buttons[bnum-1], "BOTTOMLEFT", 0, 0)
170 end 237 end
171 end 238 end
195 local num = AceGUI:GetNextWidgetNum(Type) 262 local num = AceGUI:GetNextWidgetNum(Type)
196 local frame = CreateFrame("Frame", nil, UIParent) 263 local frame = CreateFrame("Frame", nil, UIParent)
197 264
198 local slframe = CreateFrame("Frame", nil, frame) 265 local slframe = CreateFrame("Frame", nil, frame)
199 slframe:SetAllPoints() 266 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) 267 slframe:EnableMouseWheel(true)
205 slframe:SetBackdrop(PaneBackdrop) 268 slframe:SetBackdrop(PaneBackdrop)
206 slframe:SetBackdropColor(0.1, 0.1, 0.1, 0.5) 269 slframe:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
207 slframe:SetBackdropBorderColor(0.4, 0.4, 0.4) 270 slframe:SetBackdropBorderColor(0.4, 0.4, 0.4)
208 --slframe:SetResizable(true) 271 --slframe:SetResizable(true)
209 --slframe:SetMinResize(100, 1) 272 --slframe:SetMinResize(100, 1)
210 --slframe:SetMaxResize(400, 1600) 273 --slframe:SetMaxResize(400, 1600)
211 --slframe:SetScript("OnUpdate", FirstFrameUpdate) 274 --slframe:SetScript("OnUpdate", FirstFrameUpdate)
212 --slframe:SetScript("OnSizeChanged", Tree_OnSizeChanged) 275 --slframe:SetScript("OnSizeChanged", Tree_OnSizeChanged)
213 --slframe:SetScript("OnMouseWheel", Tree_OnMouseWheel) 276 slframe:SetScript("OnMouseWheel", SL_OnMouseWheel)
214 277
215 --local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), slframe, "UIPanelScrollBarTemplate") 278 local scrollbar = CreateFrame("Slider", ("SelectorList%dScrollBar"):format(num), slframe, "UIPanelScrollBarTemplate")
216 --scrollbar:SetScript("OnValueChanged", nil) 279 scrollbar:SetScript("OnValueChanged", nil)
217 --scrollbar:SetPoint("TOPRIGHT", -10, -26) 280 scrollbar:SetPoint("TOPRIGHT", -10, -26)
218 --scrollbar:SetPoint("BOTTOMRIGHT", -10, 26) 281 scrollbar:SetPoint("BOTTOMRIGHT", -10, 26)
219 --scrollbar:SetMinMaxValues(0,0) 282 scrollbar:SetMinMaxValues(0,0)
220 --scrollbar:SetValueStep(1) 283 scrollbar:SetValueStep(1)
221 --scrollbar:SetValue(0) 284 scrollbar:SetValue(0)
222 --scrollbar:SetWidth(16) 285 scrollbar:SetWidth(16)
223 --scrollbar:SetScript("OnValueChanged", OnScrollValueChanged) 286 scrollbar:SetScript("OnValueChanged", OnScrollValueChanged)
224 287
225 --local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND") 288 local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND")
226 --scrollbg:SetAllPoints(scrollbar) 289 scrollbg:SetAllPoints(scrollbar)
227 --scrollbg:SetTexture(0,0,0,0.4) 290 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 291
241 local widget = { 292 local widget = {
242 frame = frame, 293 frame = frame,
243 lines = {}, 294 lines = {},
244 --levels = {}, 295 --levels = {},
245 buttons = {}, 296 buttons = {},
246 --hasChildren = {},
247 localstatus = { 297 localstatus = {
248 --groups = {}, 298 --groups = {},
249 scrollvalue = 0 }, 299 scrollvalue = 0 },
250 filter = false, 300 filter = false,
251 slframe = slframe, 301 slframe = slframe,
252 --dragger = dragger, 302 scrollbar = scrollbar,
253 --scrollbar = scrollbar,
254 --border = border,
255 --content = slframe, -- content is for containers
256 type = Type 303 type = Type
257 } 304 }
258 if methods then 305 if methods then
259 for method, func in pairs(methods) do 306 for method, func in pairs(methods) do
260 widget[method] = func 307 widget[method] = func
261 end 308 end
262 end 309 end
263 slframe.obj = widget 310 slframe.obj = widget
264 --dragger.obj = widget 311 scrollbar.obj = widget
265 --scrollbar.obj = widget
266 312
267 return AceGUI:RegisterAsWidget(widget) 313 return AceGUI:RegisterAsWidget(widget)
268 end 314 end
269 315
270 AceGUI:RegisterWidgetType(Type, Constructor, Version) 316 AceGUI:RegisterWidgetType(Type, Constructor, Version)