annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-TreeGroup.lua @ 5:c31ee4251181

Libs Update
author tercio
date Tue, 25 Nov 2014 21:15:10 -0200
parents fc346da3afd9
children 371e14cd2feb
rev   line source
tercio@0 1 --[[-----------------------------------------------------------------------------
tercio@0 2 TreeGroup Container
tercio@0 3 Container that uses a tree control to switch between groups.
tercio@0 4 -------------------------------------------------------------------------------]]
tercio@5 5 local Type, Version = "TreeGroup", 37
tercio@0 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
tercio@0 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
tercio@0 8
tercio@0 9 -- Lua APIs
tercio@0 10 local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type
tercio@0 11 local math_min, math_max, floor = math.min, math.max, floor
tercio@0 12 local select, tremove, unpack, tconcat = select, table.remove, unpack, table.concat
tercio@0 13
tercio@0 14 -- WoW APIs
tercio@0 15 local CreateFrame, UIParent = CreateFrame, UIParent
tercio@0 16
tercio@0 17 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
tercio@0 18 -- List them here for Mikk's FindGlobals script
tercio@0 19 -- GLOBALS: GameTooltip, FONT_COLOR_CODE_CLOSE
tercio@0 20
tercio@0 21 -- Recycling functions
tercio@0 22 local new, del
tercio@0 23 do
tercio@0 24 local pool = setmetatable({},{__mode='k'})
tercio@0 25 function new()
tercio@0 26 local t = next(pool)
tercio@0 27 if t then
tercio@0 28 pool[t] = nil
tercio@0 29 return t
tercio@0 30 else
tercio@0 31 return {}
tercio@0 32 end
tercio@0 33 end
tercio@0 34 function del(t)
tercio@0 35 for k in pairs(t) do
tercio@0 36 t[k] = nil
tercio@0 37 end
tercio@0 38 pool[t] = true
tercio@0 39 end
tercio@0 40 end
tercio@0 41
tercio@0 42 local DEFAULT_TREE_WIDTH = 175
tercio@0 43 local DEFAULT_TREE_SIZABLE = true
tercio@0 44
tercio@0 45 --[[-----------------------------------------------------------------------------
tercio@0 46 Support functions
tercio@0 47 -------------------------------------------------------------------------------]]
tercio@0 48 local function GetButtonUniqueValue(line)
tercio@0 49 local parent = line.parent
tercio@0 50 if parent and parent.value then
tercio@0 51 return GetButtonUniqueValue(parent).."\001"..line.value
tercio@0 52 else
tercio@0 53 return line.value
tercio@0 54 end
tercio@0 55 end
tercio@0 56
tercio@0 57 local function UpdateButton(button, treeline, selected, canExpand, isExpanded)
tercio@0 58 local self = button.obj
tercio@0 59 local toggle = button.toggle
tercio@0 60 local frame = self.frame
tercio@0 61 local text = treeline.text or ""
tercio@0 62 local icon = treeline.icon
tercio@0 63 local iconCoords = treeline.iconCoords
tercio@0 64 local level = treeline.level
tercio@0 65 local value = treeline.value
tercio@0 66 local uniquevalue = treeline.uniquevalue
tercio@0 67 local disabled = treeline.disabled
tercio@0 68
tercio@0 69 button.treeline = treeline
tercio@0 70 button.value = value
tercio@0 71 button.uniquevalue = uniquevalue
tercio@0 72 if selected then
tercio@0 73 button:LockHighlight()
tercio@0 74 button.selected = true
tercio@0 75 else
tercio@0 76 button:UnlockHighlight()
tercio@0 77 button.selected = false
tercio@0 78 end
tercio@0 79 local normalTexture = button:GetNormalTexture()
tercio@0 80 local line = button.line
tercio@0 81 button.level = level
tercio@0 82 if ( level == 1 ) then
tercio@0 83 button:SetNormalFontObject("GameFontNormal")
tercio@0 84 button:SetHighlightFontObject("GameFontHighlight")
tercio@0 85 button.text:SetPoint("LEFT", (icon and 16 or 0) + 8, 2)
tercio@0 86 else
tercio@0 87 button:SetNormalFontObject("GameFontHighlightSmall")
tercio@0 88 button:SetHighlightFontObject("GameFontHighlightSmall")
tercio@0 89 button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2)
tercio@0 90 end
tercio@0 91
tercio@0 92 if disabled then
tercio@0 93 button:EnableMouse(false)
tercio@0 94 button.text:SetText("|cff808080"..text..FONT_COLOR_CODE_CLOSE)
tercio@0 95 else
tercio@0 96 button.text:SetText(text)
tercio@0 97 button:EnableMouse(true)
tercio@0 98 end
tercio@0 99
tercio@0 100 if icon then
tercio@0 101 button.icon:SetTexture(icon)
tercio@0 102 button.icon:SetPoint("LEFT", 8 * level, (level == 1) and 0 or 1)
tercio@0 103 else
tercio@0 104 button.icon:SetTexture(nil)
tercio@0 105 end
tercio@0 106
tercio@0 107 if iconCoords then
tercio@0 108 button.icon:SetTexCoord(unpack(iconCoords))
tercio@0 109 else
tercio@0 110 button.icon:SetTexCoord(0, 1, 0, 1)
tercio@0 111 end
tercio@0 112
tercio@0 113 if canExpand then
tercio@0 114 if not isExpanded then
tercio@0 115 toggle:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-UP")
tercio@0 116 toggle:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-DOWN")
tercio@0 117 else
tercio@0 118 toggle:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP")
tercio@0 119 toggle:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN")
tercio@0 120 end
tercio@0 121 toggle:Show()
tercio@0 122 else
tercio@0 123 toggle:Hide()
tercio@0 124 end
tercio@0 125 end
tercio@0 126
tercio@0 127 local function ShouldDisplayLevel(tree)
tercio@0 128 local result = false
tercio@0 129 for k, v in ipairs(tree) do
tercio@0 130 if v.children == nil and v.visible ~= false then
tercio@0 131 result = true
tercio@0 132 elseif v.children then
tercio@0 133 result = result or ShouldDisplayLevel(v.children)
tercio@0 134 end
tercio@0 135 if result then return result end
tercio@0 136 end
tercio@0 137 return false
tercio@0 138 end
tercio@0 139
tercio@0 140 local function addLine(self, v, tree, level, parent)
tercio@0 141 local line = new()
tercio@0 142 line.value = v.value
tercio@0 143 line.text = v.text
tercio@0 144 line.icon = v.icon
tercio@0 145 line.iconCoords = v.iconCoords
tercio@0 146 line.disabled = v.disabled
tercio@0 147 line.tree = tree
tercio@0 148 line.level = level
tercio@0 149 line.parent = parent
tercio@0 150 line.visible = v.visible
tercio@0 151 line.uniquevalue = GetButtonUniqueValue(line)
tercio@0 152 if v.children then
tercio@0 153 line.hasChildren = true
tercio@0 154 else
tercio@0 155 line.hasChildren = nil
tercio@0 156 end
tercio@0 157 self.lines[#self.lines+1] = line
tercio@0 158 return line
tercio@0 159 end
tercio@0 160
tercio@0 161 --fire an update after one frame to catch the treeframes height
tercio@0 162 local function FirstFrameUpdate(frame)
tercio@0 163 local self = frame.obj
tercio@0 164 frame:SetScript("OnUpdate", nil)
tercio@0 165 self:RefreshTree()
tercio@0 166 end
tercio@0 167
tercio@0 168 local function BuildUniqueValue(...)
tercio@0 169 local n = select('#', ...)
tercio@0 170 if n == 1 then
tercio@0 171 return ...
tercio@0 172 else
tercio@0 173 return (...).."\001"..BuildUniqueValue(select(2,...))
tercio@0 174 end
tercio@0 175 end
tercio@0 176
tercio@0 177 --[[-----------------------------------------------------------------------------
tercio@0 178 Scripts
tercio@0 179 -------------------------------------------------------------------------------]]
tercio@0 180 local function Expand_OnClick(frame)
tercio@0 181 local button = frame.button
tercio@0 182 local self = button.obj
tercio@0 183 local status = (self.status or self.localstatus).groups
tercio@0 184 status[button.uniquevalue] = not status[button.uniquevalue]
tercio@0 185 self:RefreshTree()
tercio@0 186 end
tercio@0 187
tercio@0 188 local function Button_OnClick(frame)
tercio@0 189 local self = frame.obj
tercio@0 190 self:Fire("OnClick", frame.uniquevalue, frame.selected)
tercio@0 191 if not frame.selected then
tercio@0 192 self:SetSelected(frame.uniquevalue)
tercio@0 193 frame.selected = true
tercio@0 194 frame:LockHighlight()
tercio@0 195 self:RefreshTree()
tercio@0 196 end
tercio@0 197 AceGUI:ClearFocus()
tercio@0 198 end
tercio@0 199
tercio@0 200 local function Button_OnDoubleClick(button)
tercio@0 201 local self = button.obj
tercio@0 202 local status = self.status or self.localstatus
tercio@0 203 local status = (self.status or self.localstatus).groups
tercio@0 204 status[button.uniquevalue] = not status[button.uniquevalue]
tercio@0 205 self:RefreshTree()
tercio@0 206 end
tercio@0 207
tercio@0 208 local function Button_OnEnter(frame)
tercio@0 209 local self = frame.obj
tercio@0 210 self:Fire("OnButtonEnter", frame.uniquevalue, frame)
tercio@0 211
tercio@0 212 if self.enabletooltips then
tercio@0 213 GameTooltip:SetOwner(frame, "ANCHOR_NONE")
tercio@0 214 GameTooltip:SetPoint("LEFT",frame,"RIGHT")
tercio@5 215 GameTooltip:SetText(frame.text:GetText() or "", 1, .82, 0, true)
tercio@0 216
tercio@0 217 GameTooltip:Show()
tercio@0 218 end
tercio@0 219 end
tercio@0 220
tercio@0 221 local function Button_OnLeave(frame)
tercio@0 222 local self = frame.obj
tercio@0 223 self:Fire("OnButtonLeave", frame.uniquevalue, frame)
tercio@0 224
tercio@0 225 if self.enabletooltips then
tercio@0 226 GameTooltip:Hide()
tercio@0 227 end
tercio@0 228 end
tercio@0 229
tercio@0 230 local function OnScrollValueChanged(frame, value)
tercio@0 231 if frame.obj.noupdate then return end
tercio@0 232 local self = frame.obj
tercio@0 233 local status = self.status or self.localstatus
tercio@0 234 status.scrollvalue = floor(value + 0.5)
tercio@0 235 self:RefreshTree()
tercio@0 236 AceGUI:ClearFocus()
tercio@0 237 end
tercio@0 238
tercio@0 239 local function Tree_OnSizeChanged(frame)
tercio@0 240 frame.obj:RefreshTree()
tercio@0 241 end
tercio@0 242
tercio@0 243 local function Tree_OnMouseWheel(frame, delta)
tercio@0 244 local self = frame.obj
tercio@0 245 if self.showscroll then
tercio@0 246 local scrollbar = self.scrollbar
tercio@0 247 local min, max = scrollbar:GetMinMaxValues()
tercio@0 248 local value = scrollbar:GetValue()
tercio@0 249 local newvalue = math_min(max,math_max(min,value - delta))
tercio@0 250 if value ~= newvalue then
tercio@0 251 scrollbar:SetValue(newvalue)
tercio@0 252 end
tercio@0 253 end
tercio@0 254 end
tercio@0 255
tercio@0 256 local function Dragger_OnLeave(frame)
tercio@0 257 frame:SetBackdropColor(1, 1, 1, 0)
tercio@0 258 end
tercio@0 259
tercio@0 260 local function Dragger_OnEnter(frame)
tercio@0 261 frame:SetBackdropColor(1, 1, 1, 0.8)
tercio@0 262 end
tercio@0 263
tercio@0 264 local function Dragger_OnMouseDown(frame)
tercio@0 265 local treeframe = frame:GetParent()
tercio@0 266 treeframe:StartSizing("RIGHT")
tercio@0 267 end
tercio@0 268
tercio@0 269 local function Dragger_OnMouseUp(frame)
tercio@0 270 local treeframe = frame:GetParent()
tercio@0 271 local self = treeframe.obj
tercio@0 272 local frame = treeframe:GetParent()
tercio@0 273 treeframe:StopMovingOrSizing()
tercio@0 274 --treeframe:SetScript("OnUpdate", nil)
tercio@0 275 treeframe:SetUserPlaced(false)
tercio@0 276 --Without this :GetHeight will get stuck on the current height, causing the tree contents to not resize
tercio@0 277 treeframe:SetHeight(0)
tercio@0 278 treeframe:SetPoint("TOPLEFT", frame, "TOPLEFT",0,0)
tercio@0 279 treeframe:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT",0,0)
tercio@0 280
tercio@0 281 local status = self.status or self.localstatus
tercio@0 282 status.treewidth = treeframe:GetWidth()
tercio@0 283
tercio@0 284 treeframe.obj:Fire("OnTreeResize",treeframe:GetWidth())
tercio@0 285 -- recalculate the content width
tercio@0 286 treeframe.obj:OnWidthSet(status.fullwidth)
tercio@0 287 -- update the layout of the content
tercio@0 288 treeframe.obj:DoLayout()
tercio@0 289 end
tercio@0 290
tercio@0 291 --[[-----------------------------------------------------------------------------
tercio@0 292 Methods
tercio@0 293 -------------------------------------------------------------------------------]]
tercio@0 294 local methods = {
tercio@0 295 ["OnAcquire"] = function(self)
tercio@0 296 self:SetTreeWidth(DEFAULT_TREE_WIDTH, DEFAULT_TREE_SIZABLE)
tercio@0 297 self:EnableButtonTooltips(true)
tercio@0 298 end,
tercio@0 299
tercio@0 300 ["OnRelease"] = function(self)
tercio@0 301 self.status = nil
tercio@0 302 for k, v in pairs(self.localstatus) do
tercio@0 303 if k == "groups" then
tercio@0 304 for k2 in pairs(v) do
tercio@0 305 v[k2] = nil
tercio@0 306 end
tercio@0 307 else
tercio@0 308 self.localstatus[k] = nil
tercio@0 309 end
tercio@0 310 end
tercio@0 311 self.localstatus.scrollvalue = 0
tercio@0 312 self.localstatus.treewidth = DEFAULT_TREE_WIDTH
tercio@0 313 self.localstatus.treesizable = DEFAULT_TREE_SIZABLE
tercio@0 314 end,
tercio@0 315
tercio@0 316 ["EnableButtonTooltips"] = function(self, enable)
tercio@0 317 self.enabletooltips = enable
tercio@0 318 end,
tercio@0 319
tercio@0 320 ["CreateButton"] = function(self)
tercio@0 321 local num = AceGUI:GetNextWidgetNum("TreeGroupButton")
tercio@0 322 local button = CreateFrame("Button", ("AceGUI30TreeButton%d"):format(num), self.treeframe, "OptionsListButtonTemplate")
tercio@0 323 button.obj = self
tercio@0 324
tercio@0 325 local icon = button:CreateTexture(nil, "OVERLAY")
tercio@0 326 icon:SetWidth(14)
tercio@0 327 icon:SetHeight(14)
tercio@0 328 button.icon = icon
tercio@0 329
tercio@0 330 button:SetScript("OnClick",Button_OnClick)
tercio@0 331 button:SetScript("OnDoubleClick", Button_OnDoubleClick)
tercio@0 332 button:SetScript("OnEnter",Button_OnEnter)
tercio@0 333 button:SetScript("OnLeave",Button_OnLeave)
tercio@0 334
tercio@0 335 button.toggle.button = button
tercio@0 336 button.toggle:SetScript("OnClick",Expand_OnClick)
tercio@0 337
tercio@0 338 return button
tercio@0 339 end,
tercio@0 340
tercio@0 341 ["SetStatusTable"] = function(self, status)
tercio@0 342 assert(type(status) == "table")
tercio@0 343 self.status = status
tercio@0 344 if not status.groups then
tercio@0 345 status.groups = {}
tercio@0 346 end
tercio@0 347 if not status.scrollvalue then
tercio@0 348 status.scrollvalue = 0
tercio@0 349 end
tercio@0 350 if not status.treewidth then
tercio@0 351 status.treewidth = DEFAULT_TREE_WIDTH
tercio@0 352 end
tercio@0 353 if status.treesizable == nil then
tercio@0 354 status.treesizable = DEFAULT_TREE_SIZABLE
tercio@0 355 end
tercio@0 356 self:SetTreeWidth(status.treewidth,status.treesizable)
tercio@0 357 self:RefreshTree()
tercio@0 358 end,
tercio@0 359
tercio@0 360 --sets the tree to be displayed
tercio@0 361 ["SetTree"] = function(self, tree, filter)
tercio@0 362 self.filter = filter
tercio@0 363 if tree then
tercio@0 364 assert(type(tree) == "table")
tercio@0 365 end
tercio@0 366 self.tree = tree
tercio@0 367 self:RefreshTree()
tercio@0 368 end,
tercio@0 369
tercio@0 370 ["BuildLevel"] = function(self, tree, level, parent)
tercio@0 371 local groups = (self.status or self.localstatus).groups
tercio@0 372 local hasChildren = self.hasChildren
tercio@0 373
tercio@0 374 for i, v in ipairs(tree) do
tercio@0 375 if v.children then
tercio@0 376 if not self.filter or ShouldDisplayLevel(v.children) then
tercio@0 377 local line = addLine(self, v, tree, level, parent)
tercio@0 378 if groups[line.uniquevalue] then
tercio@0 379 self:BuildLevel(v.children, level+1, line)
tercio@0 380 end
tercio@0 381 end
tercio@0 382 elseif v.visible ~= false or not self.filter then
tercio@0 383 addLine(self, v, tree, level, parent)
tercio@0 384 end
tercio@0 385 end
tercio@0 386 end,
tercio@0 387
tercio@0 388 ["RefreshTree"] = function(self,scrollToSelection)
tercio@0 389 local buttons = self.buttons
tercio@0 390 local lines = self.lines
tercio@0 391
tercio@0 392 for i, v in ipairs(buttons) do
tercio@0 393 v:Hide()
tercio@0 394 end
tercio@0 395 while lines[1] do
tercio@0 396 local t = tremove(lines)
tercio@0 397 for k in pairs(t) do
tercio@0 398 t[k] = nil
tercio@0 399 end
tercio@0 400 del(t)
tercio@0 401 end
tercio@0 402
tercio@0 403 if not self.tree then return end
tercio@0 404 --Build the list of visible entries from the tree and status tables
tercio@0 405 local status = self.status or self.localstatus
tercio@0 406 local groupstatus = status.groups
tercio@0 407 local tree = self.tree
tercio@0 408
tercio@0 409 local treeframe = self.treeframe
tercio@0 410
tercio@0 411 status.scrollToSelection = status.scrollToSelection or scrollToSelection -- needs to be cached in case the control hasn't been drawn yet (code bails out below)
tercio@0 412
tercio@0 413 self:BuildLevel(tree, 1)
tercio@0 414
tercio@0 415 local numlines = #lines
tercio@0 416
tercio@0 417 local maxlines = (floor(((self.treeframe:GetHeight()or 0) - 20 ) / 18))
tercio@0 418 if maxlines <= 0 then return end
tercio@0 419
tercio@0 420 local first, last
tercio@0 421
tercio@0 422 scrollToSelection = status.scrollToSelection
tercio@0 423 status.scrollToSelection = nil
tercio@0 424
tercio@0 425 if numlines <= maxlines then
tercio@0 426 --the whole tree fits in the frame
tercio@0 427 status.scrollvalue = 0
tercio@0 428 self:ShowScroll(false)
tercio@0 429 first, last = 1, numlines
tercio@0 430 else
tercio@0 431 self:ShowScroll(true)
tercio@0 432 --scrolling will be needed
tercio@0 433 self.noupdate = true
tercio@0 434 self.scrollbar:SetMinMaxValues(0, numlines - maxlines)
tercio@0 435 --check if we are scrolled down too far
tercio@0 436 if numlines - status.scrollvalue < maxlines then
tercio@0 437 status.scrollvalue = numlines - maxlines
tercio@0 438 end
tercio@0 439 self.noupdate = nil
tercio@0 440 first, last = status.scrollvalue+1, status.scrollvalue + maxlines
tercio@0 441 --show selection?
tercio@0 442 if scrollToSelection and status.selected then
tercio@0 443 local show
tercio@0 444 for i,line in ipairs(lines) do -- find the line number
tercio@0 445 if line.uniquevalue==status.selected then
tercio@0 446 show=i
tercio@0 447 end
tercio@0 448 end
tercio@0 449 if not show then
tercio@0 450 -- selection was deleted or something?
tercio@0 451 elseif show>=first and show<=last then
tercio@0 452 -- all good
tercio@0 453 else
tercio@0 454 -- scrolling needed!
tercio@0 455 if show<first then
tercio@0 456 status.scrollvalue = show-1
tercio@0 457 else
tercio@0 458 status.scrollvalue = show-maxlines
tercio@0 459 end
tercio@0 460 first, last = status.scrollvalue+1, status.scrollvalue + maxlines
tercio@0 461 end
tercio@0 462 end
tercio@0 463 if self.scrollbar:GetValue() ~= status.scrollvalue then
tercio@0 464 self.scrollbar:SetValue(status.scrollvalue)
tercio@0 465 end
tercio@0 466 end
tercio@0 467
tercio@0 468 local buttonnum = 1
tercio@0 469 for i = first, last do
tercio@0 470 local line = lines[i]
tercio@0 471 local button = buttons[buttonnum]
tercio@0 472 if not button then
tercio@0 473 button = self:CreateButton()
tercio@0 474
tercio@0 475 buttons[buttonnum] = button
tercio@0 476 button:SetParent(treeframe)
tercio@0 477 button:SetFrameLevel(treeframe:GetFrameLevel()+1)
tercio@0 478 button:ClearAllPoints()
tercio@0 479 if buttonnum == 1 then
tercio@0 480 if self.showscroll then
tercio@0 481 button:SetPoint("TOPRIGHT", -22, -10)
tercio@0 482 button:SetPoint("TOPLEFT", 0, -10)
tercio@0 483 else
tercio@0 484 button:SetPoint("TOPRIGHT", 0, -10)
tercio@0 485 button:SetPoint("TOPLEFT", 0, -10)
tercio@0 486 end
tercio@0 487 else
tercio@0 488 button:SetPoint("TOPRIGHT", buttons[buttonnum-1], "BOTTOMRIGHT",0,0)
tercio@0 489 button:SetPoint("TOPLEFT", buttons[buttonnum-1], "BOTTOMLEFT",0,0)
tercio@0 490 end
tercio@0 491 end
tercio@0 492
tercio@0 493 UpdateButton(button, line, status.selected == line.uniquevalue, line.hasChildren, groupstatus[line.uniquevalue] )
tercio@0 494 button:Show()
tercio@0 495 buttonnum = buttonnum + 1
tercio@0 496 end
tercio@0 497
tercio@0 498 end,
tercio@0 499
tercio@0 500 ["SetSelected"] = function(self, value)
tercio@0 501 local status = self.status or self.localstatus
tercio@0 502 if status.selected ~= value then
tercio@0 503 status.selected = value
tercio@0 504 self:Fire("OnGroupSelected", value)
tercio@0 505 end
tercio@0 506 end,
tercio@0 507
tercio@0 508 ["Select"] = function(self, uniquevalue, ...)
tercio@0 509 self.filter = false
tercio@0 510 local status = self.status or self.localstatus
tercio@0 511 local groups = status.groups
tercio@0 512 local path = {...}
tercio@0 513 for i = 1, #path do
tercio@0 514 groups[tconcat(path, "\001", 1, i)] = true
tercio@0 515 end
tercio@0 516 status.selected = uniquevalue
tercio@0 517 self:RefreshTree(true)
tercio@0 518 self:Fire("OnGroupSelected", uniquevalue)
tercio@0 519 end,
tercio@0 520
tercio@0 521 ["SelectByPath"] = function(self, ...)
tercio@0 522 self:Select(BuildUniqueValue(...), ...)
tercio@0 523 end,
tercio@0 524
tercio@0 525 ["SelectByValue"] = function(self, uniquevalue)
tercio@0 526 self:Select(uniquevalue, ("\001"):split(uniquevalue))
tercio@0 527 end,
tercio@0 528
tercio@0 529 ["ShowScroll"] = function(self, show)
tercio@0 530 self.showscroll = show
tercio@0 531 if show then
tercio@0 532 self.scrollbar:Show()
tercio@0 533 if self.buttons[1] then
tercio@0 534 self.buttons[1]:SetPoint("TOPRIGHT", self.treeframe,"TOPRIGHT",-22,-10)
tercio@0 535 end
tercio@0 536 else
tercio@0 537 self.scrollbar:Hide()
tercio@0 538 if self.buttons[1] then
tercio@0 539 self.buttons[1]:SetPoint("TOPRIGHT", self.treeframe,"TOPRIGHT",0,-10)
tercio@0 540 end
tercio@0 541 end
tercio@0 542 end,
tercio@0 543
tercio@0 544 ["OnWidthSet"] = function(self, width)
tercio@0 545 local content = self.content
tercio@0 546 local treeframe = self.treeframe
tercio@0 547 local status = self.status or self.localstatus
tercio@0 548 status.fullwidth = width
tercio@0 549
tercio@0 550 local contentwidth = width - status.treewidth - 20
tercio@0 551 if contentwidth < 0 then
tercio@0 552 contentwidth = 0
tercio@0 553 end
tercio@0 554 content:SetWidth(contentwidth)
tercio@0 555 content.width = contentwidth
tercio@0 556
tercio@0 557 local maxtreewidth = math_min(400, width - 50)
tercio@0 558
tercio@0 559 if maxtreewidth > 100 and status.treewidth > maxtreewidth then
tercio@0 560 self:SetTreeWidth(maxtreewidth, status.treesizable)
tercio@0 561 end
tercio@0 562 treeframe:SetMaxResize(maxtreewidth, 1600)
tercio@0 563 end,
tercio@0 564
tercio@0 565 ["OnHeightSet"] = function(self, height)
tercio@0 566 local content = self.content
tercio@0 567 local contentheight = height - 20
tercio@0 568 if contentheight < 0 then
tercio@0 569 contentheight = 0
tercio@0 570 end
tercio@0 571 content:SetHeight(contentheight)
tercio@0 572 content.height = contentheight
tercio@0 573 end,
tercio@0 574
tercio@0 575 ["SetTreeWidth"] = function(self, treewidth, resizable)
tercio@0 576 if not resizable then
tercio@0 577 if type(treewidth) == 'number' then
tercio@0 578 resizable = false
tercio@0 579 elseif type(treewidth) == 'boolean' then
tercio@0 580 resizable = treewidth
tercio@0 581 treewidth = DEFAULT_TREE_WIDTH
tercio@0 582 else
tercio@0 583 resizable = false
tercio@0 584 treewidth = DEFAULT_TREE_WIDTH
tercio@0 585 end
tercio@0 586 end
tercio@0 587 self.treeframe:SetWidth(treewidth)
tercio@0 588 self.dragger:EnableMouse(resizable)
tercio@0 589
tercio@0 590 local status = self.status or self.localstatus
tercio@0 591 status.treewidth = treewidth
tercio@0 592 status.treesizable = resizable
tercio@0 593
tercio@0 594 -- recalculate the content width
tercio@0 595 if status.fullwidth then
tercio@0 596 self:OnWidthSet(status.fullwidth)
tercio@0 597 end
tercio@0 598 end,
tercio@0 599
tercio@0 600 ["GetTreeWidth"] = function(self)
tercio@0 601 local status = self.status or self.localstatus
tercio@0 602 return status.treewidth or DEFAULT_TREE_WIDTH
tercio@0 603 end,
tercio@0 604
tercio@0 605 ["LayoutFinished"] = function(self, width, height)
tercio@0 606 if self.noAutoHeight then return end
tercio@0 607 self:SetHeight((height or 0) + 20)
tercio@0 608 end
tercio@0 609 }
tercio@0 610
tercio@0 611 --[[-----------------------------------------------------------------------------
tercio@0 612 Constructor
tercio@0 613 -------------------------------------------------------------------------------]]
tercio@0 614 local PaneBackdrop = {
tercio@0 615 bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
tercio@0 616 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tercio@0 617 tile = true, tileSize = 16, edgeSize = 16,
tercio@0 618 insets = { left = 3, right = 3, top = 5, bottom = 3 }
tercio@0 619 }
tercio@0 620
tercio@0 621 local DraggerBackdrop = {
tercio@0 622 bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
tercio@0 623 edgeFile = nil,
tercio@0 624 tile = true, tileSize = 16, edgeSize = 0,
tercio@0 625 insets = { left = 3, right = 3, top = 7, bottom = 7 }
tercio@0 626 }
tercio@0 627
tercio@0 628 local function Constructor()
tercio@0 629 local num = AceGUI:GetNextWidgetNum(Type)
tercio@0 630 local frame = CreateFrame("Frame", nil, UIParent)
tercio@0 631
tercio@0 632 local treeframe = CreateFrame("Frame", nil, frame)
tercio@0 633 treeframe:SetPoint("TOPLEFT")
tercio@0 634 treeframe:SetPoint("BOTTOMLEFT")
tercio@0 635 treeframe:SetWidth(DEFAULT_TREE_WIDTH)
tercio@0 636 treeframe:EnableMouseWheel(true)
tercio@0 637 treeframe:SetBackdrop(PaneBackdrop)
tercio@0 638 treeframe:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
tercio@0 639 treeframe:SetBackdropBorderColor(0.4, 0.4, 0.4)
tercio@0 640 treeframe:SetResizable(true)
tercio@0 641 treeframe:SetMinResize(100, 1)
tercio@0 642 treeframe:SetMaxResize(400, 1600)
tercio@0 643 treeframe:SetScript("OnUpdate", FirstFrameUpdate)
tercio@0 644 treeframe:SetScript("OnSizeChanged", Tree_OnSizeChanged)
tercio@0 645 treeframe:SetScript("OnMouseWheel", Tree_OnMouseWheel)
tercio@0 646
tercio@0 647 local dragger = CreateFrame("Frame", nil, treeframe)
tercio@0 648 dragger:SetWidth(8)
tercio@0 649 dragger:SetPoint("TOP", treeframe, "TOPRIGHT")
tercio@0 650 dragger:SetPoint("BOTTOM", treeframe, "BOTTOMRIGHT")
tercio@0 651 dragger:SetBackdrop(DraggerBackdrop)
tercio@0 652 dragger:SetBackdropColor(1, 1, 1, 0)
tercio@0 653 dragger:SetScript("OnEnter", Dragger_OnEnter)
tercio@0 654 dragger:SetScript("OnLeave", Dragger_OnLeave)
tercio@0 655 dragger:SetScript("OnMouseDown", Dragger_OnMouseDown)
tercio@0 656 dragger:SetScript("OnMouseUp", Dragger_OnMouseUp)
tercio@0 657
tercio@0 658 local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), treeframe, "UIPanelScrollBarTemplate")
tercio@0 659 scrollbar:SetScript("OnValueChanged", nil)
tercio@0 660 scrollbar:SetPoint("TOPRIGHT", -10, -26)
tercio@0 661 scrollbar:SetPoint("BOTTOMRIGHT", -10, 26)
tercio@0 662 scrollbar:SetMinMaxValues(0,0)
tercio@0 663 scrollbar:SetValueStep(1)
tercio@0 664 scrollbar:SetValue(0)
tercio@0 665 scrollbar:SetWidth(16)
tercio@0 666 scrollbar:SetScript("OnValueChanged", OnScrollValueChanged)
tercio@0 667
tercio@0 668 local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND")
tercio@0 669 scrollbg:SetAllPoints(scrollbar)
tercio@0 670 scrollbg:SetTexture(0,0,0,0.4)
tercio@0 671
tercio@0 672 local border = CreateFrame("Frame",nil,frame)
tercio@0 673 border:SetPoint("TOPLEFT", treeframe, "TOPRIGHT")
tercio@0 674 border:SetPoint("BOTTOMRIGHT")
tercio@0 675 border:SetBackdrop(PaneBackdrop)
tercio@0 676 border:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
tercio@0 677 border:SetBackdropBorderColor(0.4, 0.4, 0.4)
tercio@0 678
tercio@0 679 --Container Support
tercio@0 680 local content = CreateFrame("Frame", nil, border)
tercio@0 681 content:SetPoint("TOPLEFT", 10, -10)
tercio@0 682 content:SetPoint("BOTTOMRIGHT", -10, 10)
tercio@0 683
tercio@0 684 local widget = {
tercio@0 685 frame = frame,
tercio@0 686 lines = {},
tercio@0 687 levels = {},
tercio@0 688 buttons = {},
tercio@0 689 hasChildren = {},
tercio@0 690 localstatus = { groups = {}, scrollvalue = 0 },
tercio@0 691 filter = false,
tercio@0 692 treeframe = treeframe,
tercio@0 693 dragger = dragger,
tercio@0 694 scrollbar = scrollbar,
tercio@0 695 border = border,
tercio@0 696 content = content,
tercio@0 697 type = Type
tercio@0 698 }
tercio@0 699 for method, func in pairs(methods) do
tercio@0 700 widget[method] = func
tercio@0 701 end
tercio@0 702 treeframe.obj, dragger.obj, scrollbar.obj = widget, widget, widget
tercio@0 703
tercio@0 704 return AceGUI:RegisterAsContainer(widget)
tercio@0 705 end
tercio@0 706
tercio@0 707 AceGUI:RegisterWidgetType(Type, Constructor, Version)