annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-TreeGroup.lua @ 48:a671a2cf52ee

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