annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-TreeGroup.lua @ 51:dbf04157d63e v7.3.0.051

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