annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-TreeGroup.lua @ 25:ac501d71c890 tip

Added tag v8.2.0.024 for changeset 389dcaeebc47
author Tercioo
date Fri, 28 Jun 2019 20:07:27 -0300
parents 3000eccbf1a0
children
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@11 5 local Type, Version = "TreeGroup", 40
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@11 298 self.frame:SetScript("OnUpdate", FirstFrameUpdate)
tercio@0 299 end,
tercio@0 300
tercio@0 301 ["OnRelease"] = function(self)
tercio@0 302 self.status = nil
tercio@0 303 for k, v in pairs(self.localstatus) do
tercio@0 304 if k == "groups" then
tercio@0 305 for k2 in pairs(v) do
tercio@0 306 v[k2] = nil
tercio@0 307 end
tercio@0 308 else
tercio@0 309 self.localstatus[k] = nil
tercio@0 310 end
tercio@0 311 end
tercio@0 312 self.localstatus.scrollvalue = 0
tercio@0 313 self.localstatus.treewidth = DEFAULT_TREE_WIDTH
tercio@0 314 self.localstatus.treesizable = DEFAULT_TREE_SIZABLE
tercio@0 315 end,
tercio@0 316
tercio@0 317 ["EnableButtonTooltips"] = function(self, enable)
tercio@0 318 self.enabletooltips = enable
tercio@0 319 end,
tercio@0 320
tercio@0 321 ["CreateButton"] = function(self)
tercio@0 322 local num = AceGUI:GetNextWidgetNum("TreeGroupButton")
tercio@0 323 local button = CreateFrame("Button", ("AceGUI30TreeButton%d"):format(num), self.treeframe, "OptionsListButtonTemplate")
tercio@0 324 button.obj = self
tercio@0 325
tercio@0 326 local icon = button:CreateTexture(nil, "OVERLAY")
tercio@0 327 icon:SetWidth(14)
tercio@0 328 icon:SetHeight(14)
tercio@0 329 button.icon = icon
tercio@0 330
tercio@0 331 button:SetScript("OnClick",Button_OnClick)
tercio@0 332 button:SetScript("OnDoubleClick", Button_OnDoubleClick)
tercio@0 333 button:SetScript("OnEnter",Button_OnEnter)
tercio@0 334 button:SetScript("OnLeave",Button_OnLeave)
tercio@0 335
tercio@0 336 button.toggle.button = button
tercio@0 337 button.toggle:SetScript("OnClick",Expand_OnClick)
tercio@0 338
Tercio@11 339 button.text:SetHeight(14) -- Prevents text wrapping
Tercio@11 340
tercio@0 341 return button
tercio@0 342 end,
tercio@0 343
tercio@0 344 ["SetStatusTable"] = function(self, status)
tercio@0 345 assert(type(status) == "table")
tercio@0 346 self.status = status
tercio@0 347 if not status.groups then
tercio@0 348 status.groups = {}
tercio@0 349 end
tercio@0 350 if not status.scrollvalue then
tercio@0 351 status.scrollvalue = 0
tercio@0 352 end
tercio@0 353 if not status.treewidth then
tercio@0 354 status.treewidth = DEFAULT_TREE_WIDTH
tercio@0 355 end
tercio@0 356 if status.treesizable == nil then
tercio@0 357 status.treesizable = DEFAULT_TREE_SIZABLE
tercio@0 358 end
tercio@0 359 self:SetTreeWidth(status.treewidth,status.treesizable)
tercio@0 360 self:RefreshTree()
tercio@0 361 end,
tercio@0 362
tercio@0 363 --sets the tree to be displayed
tercio@0 364 ["SetTree"] = function(self, tree, filter)
tercio@0 365 self.filter = filter
tercio@0 366 if tree then
tercio@0 367 assert(type(tree) == "table")
tercio@0 368 end
tercio@0 369 self.tree = tree
tercio@0 370 self:RefreshTree()
tercio@0 371 end,
tercio@0 372
tercio@0 373 ["BuildLevel"] = function(self, tree, level, parent)
tercio@0 374 local groups = (self.status or self.localstatus).groups
tercio@0 375 local hasChildren = self.hasChildren
tercio@0 376
tercio@0 377 for i, v in ipairs(tree) do
tercio@0 378 if v.children then
tercio@0 379 if not self.filter or ShouldDisplayLevel(v.children) then
tercio@0 380 local line = addLine(self, v, tree, level, parent)
tercio@0 381 if groups[line.uniquevalue] then
tercio@0 382 self:BuildLevel(v.children, level+1, line)
tercio@0 383 end
tercio@0 384 end
tercio@0 385 elseif v.visible ~= false or not self.filter then
tercio@0 386 addLine(self, v, tree, level, parent)
tercio@0 387 end
tercio@0 388 end
tercio@0 389 end,
tercio@0 390
tercio@0 391 ["RefreshTree"] = function(self,scrollToSelection)
tercio@0 392 local buttons = self.buttons
tercio@0 393 local lines = self.lines
tercio@0 394
tercio@0 395 for i, v in ipairs(buttons) do
tercio@0 396 v:Hide()
tercio@0 397 end
tercio@0 398 while lines[1] do
tercio@0 399 local t = tremove(lines)
tercio@0 400 for k in pairs(t) do
tercio@0 401 t[k] = nil
tercio@0 402 end
tercio@0 403 del(t)
tercio@0 404 end
tercio@0 405
tercio@0 406 if not self.tree then return end
tercio@0 407 --Build the list of visible entries from the tree and status tables
tercio@0 408 local status = self.status or self.localstatus
tercio@0 409 local groupstatus = status.groups
tercio@0 410 local tree = self.tree
tercio@0 411
tercio@0 412 local treeframe = self.treeframe
tercio@0 413
tercio@0 414 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 415
tercio@0 416 self:BuildLevel(tree, 1)
tercio@0 417
tercio@0 418 local numlines = #lines
tercio@0 419
tercio@0 420 local maxlines = (floor(((self.treeframe:GetHeight()or 0) - 20 ) / 18))
tercio@0 421 if maxlines <= 0 then return end
tercio@0 422
tercio@0 423 local first, last
tercio@0 424
tercio@0 425 scrollToSelection = status.scrollToSelection
tercio@0 426 status.scrollToSelection = nil
tercio@0 427
tercio@0 428 if numlines <= maxlines then
tercio@0 429 --the whole tree fits in the frame
tercio@0 430 status.scrollvalue = 0
tercio@0 431 self:ShowScroll(false)
tercio@0 432 first, last = 1, numlines
tercio@0 433 else
tercio@0 434 self:ShowScroll(true)
tercio@0 435 --scrolling will be needed
tercio@0 436 self.noupdate = true
tercio@0 437 self.scrollbar:SetMinMaxValues(0, numlines - maxlines)
tercio@0 438 --check if we are scrolled down too far
tercio@0 439 if numlines - status.scrollvalue < maxlines then
tercio@0 440 status.scrollvalue = numlines - maxlines
tercio@0 441 end
tercio@0 442 self.noupdate = nil
tercio@0 443 first, last = status.scrollvalue+1, status.scrollvalue + maxlines
tercio@0 444 --show selection?
tercio@0 445 if scrollToSelection and status.selected then
tercio@0 446 local show
tercio@0 447 for i,line in ipairs(lines) do -- find the line number
tercio@0 448 if line.uniquevalue==status.selected then
tercio@0 449 show=i
tercio@0 450 end
tercio@0 451 end
tercio@0 452 if not show then
tercio@0 453 -- selection was deleted or something?
tercio@0 454 elseif show>=first and show<=last then
tercio@0 455 -- all good
tercio@0 456 else
tercio@0 457 -- scrolling needed!
tercio@0 458 if show<first then
tercio@0 459 status.scrollvalue = show-1
tercio@0 460 else
tercio@0 461 status.scrollvalue = show-maxlines
tercio@0 462 end
tercio@0 463 first, last = status.scrollvalue+1, status.scrollvalue + maxlines
tercio@0 464 end
tercio@0 465 end
tercio@0 466 if self.scrollbar:GetValue() ~= status.scrollvalue then
tercio@0 467 self.scrollbar:SetValue(status.scrollvalue)
tercio@0 468 end
tercio@0 469 end
tercio@0 470
tercio@0 471 local buttonnum = 1
tercio@0 472 for i = first, last do
tercio@0 473 local line = lines[i]
tercio@0 474 local button = buttons[buttonnum]
tercio@0 475 if not button then
tercio@0 476 button = self:CreateButton()
tercio@0 477
tercio@0 478 buttons[buttonnum] = button
tercio@0 479 button:SetParent(treeframe)
tercio@0 480 button:SetFrameLevel(treeframe:GetFrameLevel()+1)
tercio@0 481 button:ClearAllPoints()
tercio@0 482 if buttonnum == 1 then
tercio@0 483 if self.showscroll then
tercio@0 484 button:SetPoint("TOPRIGHT", -22, -10)
tercio@0 485 button:SetPoint("TOPLEFT", 0, -10)
tercio@0 486 else
tercio@0 487 button:SetPoint("TOPRIGHT", 0, -10)
tercio@0 488 button:SetPoint("TOPLEFT", 0, -10)
tercio@0 489 end
tercio@0 490 else
tercio@0 491 button:SetPoint("TOPRIGHT", buttons[buttonnum-1], "BOTTOMRIGHT",0,0)
tercio@0 492 button:SetPoint("TOPLEFT", buttons[buttonnum-1], "BOTTOMLEFT",0,0)
tercio@0 493 end
tercio@0 494 end
tercio@0 495
tercio@0 496 UpdateButton(button, line, status.selected == line.uniquevalue, line.hasChildren, groupstatus[line.uniquevalue] )
tercio@0 497 button:Show()
tercio@0 498 buttonnum = buttonnum + 1
tercio@0 499 end
tercio@0 500
tercio@0 501 end,
tercio@0 502
tercio@0 503 ["SetSelected"] = function(self, value)
tercio@0 504 local status = self.status or self.localstatus
tercio@0 505 if status.selected ~= value then
tercio@0 506 status.selected = value
tercio@0 507 self:Fire("OnGroupSelected", value)
tercio@0 508 end
tercio@0 509 end,
tercio@0 510
tercio@0 511 ["Select"] = function(self, uniquevalue, ...)
tercio@0 512 self.filter = false
tercio@0 513 local status = self.status or self.localstatus
tercio@0 514 local groups = status.groups
tercio@0 515 local path = {...}
tercio@0 516 for i = 1, #path do
tercio@0 517 groups[tconcat(path, "\001", 1, i)] = true
tercio@0 518 end
tercio@0 519 status.selected = uniquevalue
tercio@0 520 self:RefreshTree(true)
tercio@0 521 self:Fire("OnGroupSelected", uniquevalue)
tercio@0 522 end,
tercio@0 523
tercio@0 524 ["SelectByPath"] = function(self, ...)
tercio@0 525 self:Select(BuildUniqueValue(...), ...)
tercio@0 526 end,
tercio@0 527
tercio@0 528 ["SelectByValue"] = function(self, uniquevalue)
tercio@0 529 self:Select(uniquevalue, ("\001"):split(uniquevalue))
tercio@0 530 end,
tercio@0 531
tercio@0 532 ["ShowScroll"] = function(self, show)
tercio@0 533 self.showscroll = show
tercio@0 534 if show then
tercio@0 535 self.scrollbar:Show()
tercio@0 536 if self.buttons[1] then
tercio@0 537 self.buttons[1]:SetPoint("TOPRIGHT", self.treeframe,"TOPRIGHT",-22,-10)
tercio@0 538 end
tercio@0 539 else
tercio@0 540 self.scrollbar:Hide()
tercio@0 541 if self.buttons[1] then
tercio@0 542 self.buttons[1]:SetPoint("TOPRIGHT", self.treeframe,"TOPRIGHT",0,-10)
tercio@0 543 end
tercio@0 544 end
tercio@0 545 end,
tercio@0 546
tercio@0 547 ["OnWidthSet"] = function(self, width)
tercio@0 548 local content = self.content
tercio@0 549 local treeframe = self.treeframe
tercio@0 550 local status = self.status or self.localstatus
tercio@0 551 status.fullwidth = width
tercio@0 552
tercio@0 553 local contentwidth = width - status.treewidth - 20
tercio@0 554 if contentwidth < 0 then
tercio@0 555 contentwidth = 0
tercio@0 556 end
tercio@0 557 content:SetWidth(contentwidth)
tercio@0 558 content.width = contentwidth
tercio@0 559
tercio@0 560 local maxtreewidth = math_min(400, width - 50)
tercio@0 561
tercio@0 562 if maxtreewidth > 100 and status.treewidth > maxtreewidth then
tercio@0 563 self:SetTreeWidth(maxtreewidth, status.treesizable)
tercio@0 564 end
tercio@0 565 treeframe:SetMaxResize(maxtreewidth, 1600)
tercio@0 566 end,
tercio@0 567
tercio@0 568 ["OnHeightSet"] = function(self, height)
tercio@0 569 local content = self.content
tercio@0 570 local contentheight = height - 20
tercio@0 571 if contentheight < 0 then
tercio@0 572 contentheight = 0
tercio@0 573 end
tercio@0 574 content:SetHeight(contentheight)
tercio@0 575 content.height = contentheight
tercio@0 576 end,
tercio@0 577
tercio@0 578 ["SetTreeWidth"] = function(self, treewidth, resizable)
tercio@0 579 if not resizable then
tercio@0 580 if type(treewidth) == 'number' then
tercio@0 581 resizable = false
tercio@0 582 elseif type(treewidth) == 'boolean' then
tercio@0 583 resizable = treewidth
tercio@0 584 treewidth = DEFAULT_TREE_WIDTH
tercio@0 585 else
tercio@0 586 resizable = false
tercio@0 587 treewidth = DEFAULT_TREE_WIDTH
tercio@0 588 end
tercio@0 589 end
tercio@0 590 self.treeframe:SetWidth(treewidth)
tercio@0 591 self.dragger:EnableMouse(resizable)
tercio@0 592
tercio@0 593 local status = self.status or self.localstatus
tercio@0 594 status.treewidth = treewidth
tercio@0 595 status.treesizable = resizable
tercio@0 596
tercio@0 597 -- recalculate the content width
tercio@0 598 if status.fullwidth then
tercio@0 599 self:OnWidthSet(status.fullwidth)
tercio@0 600 end
tercio@0 601 end,
tercio@0 602
tercio@0 603 ["GetTreeWidth"] = function(self)
tercio@0 604 local status = self.status or self.localstatus
tercio@0 605 return status.treewidth or DEFAULT_TREE_WIDTH
tercio@0 606 end,
tercio@0 607
tercio@0 608 ["LayoutFinished"] = function(self, width, height)
tercio@0 609 if self.noAutoHeight then return end
tercio@0 610 self:SetHeight((height or 0) + 20)
tercio@0 611 end
tercio@0 612 }
tercio@0 613
tercio@0 614 --[[-----------------------------------------------------------------------------
tercio@0 615 Constructor
tercio@0 616 -------------------------------------------------------------------------------]]
tercio@0 617 local PaneBackdrop = {
tercio@0 618 bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
tercio@0 619 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tercio@0 620 tile = true, tileSize = 16, edgeSize = 16,
tercio@0 621 insets = { left = 3, right = 3, top = 5, bottom = 3 }
tercio@0 622 }
tercio@0 623
tercio@0 624 local DraggerBackdrop = {
tercio@0 625 bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
tercio@0 626 edgeFile = nil,
tercio@0 627 tile = true, tileSize = 16, edgeSize = 0,
tercio@0 628 insets = { left = 3, right = 3, top = 7, bottom = 7 }
tercio@0 629 }
tercio@0 630
tercio@0 631 local function Constructor()
tercio@0 632 local num = AceGUI:GetNextWidgetNum(Type)
tercio@0 633 local frame = CreateFrame("Frame", nil, UIParent)
tercio@0 634
tercio@0 635 local treeframe = CreateFrame("Frame", nil, frame)
tercio@0 636 treeframe:SetPoint("TOPLEFT")
tercio@0 637 treeframe:SetPoint("BOTTOMLEFT")
tercio@0 638 treeframe:SetWidth(DEFAULT_TREE_WIDTH)
tercio@0 639 treeframe:EnableMouseWheel(true)
tercio@0 640 treeframe:SetBackdrop(PaneBackdrop)
tercio@0 641 treeframe:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
tercio@0 642 treeframe:SetBackdropBorderColor(0.4, 0.4, 0.4)
tercio@0 643 treeframe:SetResizable(true)
tercio@0 644 treeframe:SetMinResize(100, 1)
tercio@0 645 treeframe:SetMaxResize(400, 1600)
tercio@0 646 treeframe:SetScript("OnUpdate", FirstFrameUpdate)
tercio@0 647 treeframe:SetScript("OnSizeChanged", Tree_OnSizeChanged)
tercio@0 648 treeframe:SetScript("OnMouseWheel", Tree_OnMouseWheel)
tercio@0 649
tercio@0 650 local dragger = CreateFrame("Frame", nil, treeframe)
tercio@0 651 dragger:SetWidth(8)
tercio@0 652 dragger:SetPoint("TOP", treeframe, "TOPRIGHT")
tercio@0 653 dragger:SetPoint("BOTTOM", treeframe, "BOTTOMRIGHT")
tercio@0 654 dragger:SetBackdrop(DraggerBackdrop)
tercio@0 655 dragger:SetBackdropColor(1, 1, 1, 0)
tercio@0 656 dragger:SetScript("OnEnter", Dragger_OnEnter)
tercio@0 657 dragger:SetScript("OnLeave", Dragger_OnLeave)
tercio@0 658 dragger:SetScript("OnMouseDown", Dragger_OnMouseDown)
tercio@0 659 dragger:SetScript("OnMouseUp", Dragger_OnMouseUp)
tercio@0 660
tercio@0 661 local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), treeframe, "UIPanelScrollBarTemplate")
tercio@0 662 scrollbar:SetScript("OnValueChanged", nil)
tercio@0 663 scrollbar:SetPoint("TOPRIGHT", -10, -26)
tercio@0 664 scrollbar:SetPoint("BOTTOMRIGHT", -10, 26)
tercio@0 665 scrollbar:SetMinMaxValues(0,0)
tercio@0 666 scrollbar:SetValueStep(1)
tercio@0 667 scrollbar:SetValue(0)
tercio@0 668 scrollbar:SetWidth(16)
tercio@0 669 scrollbar:SetScript("OnValueChanged", OnScrollValueChanged)
tercio@0 670
tercio@0 671 local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND")
tercio@0 672 scrollbg:SetAllPoints(scrollbar)
Tercio@17 673 scrollbg:SetColorTexture(0,0,0,0.4)
tercio@0 674
tercio@0 675 local border = CreateFrame("Frame",nil,frame)
tercio@0 676 border:SetPoint("TOPLEFT", treeframe, "TOPRIGHT")
tercio@0 677 border:SetPoint("BOTTOMRIGHT")
tercio@0 678 border:SetBackdrop(PaneBackdrop)
tercio@0 679 border:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
tercio@0 680 border:SetBackdropBorderColor(0.4, 0.4, 0.4)
tercio@0 681
tercio@0 682 --Container Support
tercio@0 683 local content = CreateFrame("Frame", nil, border)
tercio@0 684 content:SetPoint("TOPLEFT", 10, -10)
tercio@0 685 content:SetPoint("BOTTOMRIGHT", -10, 10)
tercio@0 686
tercio@0 687 local widget = {
tercio@0 688 frame = frame,
tercio@0 689 lines = {},
tercio@0 690 levels = {},
tercio@0 691 buttons = {},
tercio@0 692 hasChildren = {},
tercio@0 693 localstatus = { groups = {}, scrollvalue = 0 },
tercio@0 694 filter = false,
tercio@0 695 treeframe = treeframe,
tercio@0 696 dragger = dragger,
tercio@0 697 scrollbar = scrollbar,
tercio@0 698 border = border,
tercio@0 699 content = content,
tercio@0 700 type = Type
tercio@0 701 }
tercio@0 702 for method, func in pairs(methods) do
tercio@0 703 widget[method] = func
tercio@0 704 end
tercio@0 705 treeframe.obj, dragger.obj, scrollbar.obj = widget, widget, widget
tercio@0 706
tercio@0 707 return AceGUI:RegisterAsContainer(widget)
tercio@0 708 end
tercio@0 709
tercio@0 710 AceGUI:RegisterWidgetType(Type, Constructor, Version)