Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: TreeGroup Container Xiiph@0: Container that uses a tree control to switch between groups. Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local Type, Version = "TreeGroup", 32 Xiiph@0: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) Xiiph@0: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end Xiiph@0: Xiiph@0: -- Lua APIs Xiiph@0: local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type Xiiph@0: local math_min, math_max, floor = math.min, math.max, floor Xiiph@0: local select, tremove, unpack = select, table.remove, unpack Xiiph@0: Xiiph@0: -- WoW APIs Xiiph@0: local CreateFrame, UIParent = CreateFrame, UIParent Xiiph@0: Xiiph@0: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded Xiiph@0: -- List them here for Mikk's FindGlobals script Xiiph@0: -- GLOBALS: GameTooltip, FONT_COLOR_CODE_CLOSE Xiiph@0: Xiiph@0: -- Recycling functions Xiiph@0: local new, del Xiiph@0: do Xiiph@0: local pool = setmetatable({},{__mode='k'}) Xiiph@0: function new() Xiiph@0: local t = next(pool) Xiiph@0: if t then Xiiph@0: pool[t] = nil Xiiph@0: return t Xiiph@0: else Xiiph@0: return {} Xiiph@0: end Xiiph@0: end Xiiph@0: function del(t) Xiiph@0: for k in pairs(t) do Xiiph@0: t[k] = nil Xiiph@0: end Xiiph@0: pool[t] = true Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: local DEFAULT_TREE_WIDTH = 175 Xiiph@0: local DEFAULT_TREE_SIZABLE = true Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Support functions Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local function GetButtonUniqueValue(line) Xiiph@0: local parent = line.parent Xiiph@0: if parent and parent.value then Xiiph@0: return GetButtonUniqueValue(parent).."\001"..line.value Xiiph@0: else Xiiph@0: return line.value Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: local function UpdateButton(button, treeline, selected, canExpand, isExpanded) Xiiph@0: local self = button.obj Xiiph@0: local toggle = button.toggle Xiiph@0: local frame = self.frame Xiiph@0: local text = treeline.text or "" Xiiph@0: local icon = treeline.icon Xiiph@0: local iconCoords = treeline.iconCoords Xiiph@0: local level = treeline.level Xiiph@0: local value = treeline.value Xiiph@0: local uniquevalue = treeline.uniquevalue Xiiph@0: local disabled = treeline.disabled Xiiph@0: Xiiph@0: button.treeline = treeline Xiiph@0: button.value = value Xiiph@0: button.uniquevalue = uniquevalue Xiiph@0: if selected then Xiiph@0: button:LockHighlight() Xiiph@0: button.selected = true Xiiph@0: else Xiiph@0: button:UnlockHighlight() Xiiph@0: button.selected = false Xiiph@0: end Xiiph@0: local normalTexture = button:GetNormalTexture() Xiiph@0: local line = button.line Xiiph@0: button.level = level Xiiph@0: if ( level == 1 ) then Xiiph@0: button:SetNormalFontObject("GameFontNormal") Xiiph@0: button:SetHighlightFontObject("GameFontHighlight") Xiiph@0: button.text:SetPoint("LEFT", (icon and 16 or 0) + 8, 2) Xiiph@0: else Xiiph@0: button:SetNormalFontObject("GameFontHighlightSmall") Xiiph@0: button:SetHighlightFontObject("GameFontHighlightSmall") Xiiph@0: button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2) Xiiph@0: end Xiiph@0: Xiiph@0: if disabled then Xiiph@0: button:EnableMouse(false) Xiiph@0: button.text:SetText("|cff808080"..text..FONT_COLOR_CODE_CLOSE) Xiiph@0: else Xiiph@0: button.text:SetText(text) Xiiph@0: button:EnableMouse(true) Xiiph@0: end Xiiph@0: Xiiph@0: if icon then Xiiph@0: button.icon:SetTexture(icon) Xiiph@0: button.icon:SetPoint("LEFT", 8 * level, (level == 1) and 0 or 1) Xiiph@0: else Xiiph@0: button.icon:SetTexture(nil) Xiiph@0: end Xiiph@0: Xiiph@0: if iconCoords then Xiiph@0: button.icon:SetTexCoord(unpack(iconCoords)) Xiiph@0: else Xiiph@0: button.icon:SetTexCoord(0, 1, 0, 1) Xiiph@0: end Xiiph@0: Xiiph@0: if canExpand then Xiiph@0: if not isExpanded then Xiiph@0: toggle:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-UP") Xiiph@0: toggle:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-DOWN") Xiiph@0: else Xiiph@0: toggle:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP") Xiiph@0: toggle:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN") Xiiph@0: end Xiiph@0: toggle:Show() Xiiph@0: else Xiiph@0: toggle:Hide() Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: local function ShouldDisplayLevel(tree) Xiiph@0: local result = false Xiiph@0: for k, v in ipairs(tree) do Xiiph@0: if v.children == nil and v.visible ~= false then Xiiph@0: result = true Xiiph@0: elseif v.children then Xiiph@0: result = result or ShouldDisplayLevel(v.children) Xiiph@0: end Xiiph@0: if result then return result end Xiiph@0: end Xiiph@0: return false Xiiph@0: end Xiiph@0: Xiiph@0: local function addLine(self, v, tree, level, parent) Xiiph@0: local line = new() Xiiph@0: line.value = v.value Xiiph@0: line.text = v.text Xiiph@0: line.icon = v.icon Xiiph@0: line.iconCoords = v.iconCoords Xiiph@0: line.disabled = v.disabled Xiiph@0: line.tree = tree Xiiph@0: line.level = level Xiiph@0: line.parent = parent Xiiph@0: line.visible = v.visible Xiiph@0: line.uniquevalue = GetButtonUniqueValue(line) Xiiph@0: if v.children then Xiiph@0: line.hasChildren = true Xiiph@0: else Xiiph@0: line.hasChildren = nil Xiiph@0: end Xiiph@0: self.lines[#self.lines+1] = line Xiiph@0: return line Xiiph@0: end Xiiph@0: Xiiph@0: --fire an update after one frame to catch the treeframes height Xiiph@0: local function FirstFrameUpdate(frame) Xiiph@0: local self = frame.obj Xiiph@0: frame:SetScript("OnUpdate", nil) Xiiph@0: self:RefreshTree() Xiiph@0: end Xiiph@0: Xiiph@0: local function BuildUniqueValue(...) Xiiph@0: local n = select('#', ...) Xiiph@0: if n == 1 then Xiiph@0: return ... Xiiph@0: else Xiiph@0: return (...).."\001"..BuildUniqueValue(select(2,...)) Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Scripts Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local function Expand_OnClick(frame) Xiiph@0: local button = frame.button Xiiph@0: local self = button.obj Xiiph@0: local status = (self.status or self.localstatus).groups Xiiph@0: status[button.uniquevalue] = not status[button.uniquevalue] Xiiph@0: self:RefreshTree() Xiiph@0: end Xiiph@0: Xiiph@0: local function Button_OnClick(frame) Xiiph@0: local self = frame.obj Xiiph@0: self:Fire("OnClick", frame.uniquevalue, frame.selected) Xiiph@0: if not frame.selected then Xiiph@0: self:SetSelected(frame.uniquevalue) Xiiph@0: frame.selected = true Xiiph@0: frame:LockHighlight() Xiiph@0: self:RefreshTree() Xiiph@0: end Xiiph@0: AceGUI:ClearFocus() Xiiph@0: end Xiiph@0: Xiiph@0: local function Button_OnDoubleClick(button) Xiiph@0: local self = button.obj Xiiph@0: local status = self.status or self.localstatus Xiiph@0: local status = (self.status or self.localstatus).groups Xiiph@0: status[button.uniquevalue] = not status[button.uniquevalue] Xiiph@0: self:RefreshTree() Xiiph@0: end Xiiph@0: Xiiph@0: local function Button_OnEnter(frame) Xiiph@0: local self = frame.obj Xiiph@0: self:Fire("OnButtonEnter", frame.uniquevalue, frame) Xiiph@0: Xiiph@0: if self.enabletooltips then Xiiph@0: GameTooltip:SetOwner(frame, "ANCHOR_NONE") Xiiph@0: GameTooltip:SetPoint("LEFT",frame,"RIGHT") Xiiph@0: GameTooltip:SetText(frame.text:GetText() or "", 1, .82, 0, 1) Xiiph@0: Xiiph@0: GameTooltip:Show() Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: local function Button_OnLeave(frame) Xiiph@0: local self = frame.obj Xiiph@0: self:Fire("OnButtonLeave", frame.uniquevalue, frame) Xiiph@0: Xiiph@0: if self.enabletooltips then Xiiph@0: GameTooltip:Hide() Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: local function OnScrollValueChanged(frame, value) Xiiph@0: if frame.obj.noupdate then return end Xiiph@0: local self = frame.obj Xiiph@0: local status = self.status or self.localstatus Xiiph@0: status.scrollvalue = value Xiiph@0: self:RefreshTree() Xiiph@0: AceGUI:ClearFocus() Xiiph@0: end Xiiph@0: Xiiph@0: local function Tree_OnSizeChanged(frame) Xiiph@0: frame.obj:RefreshTree() Xiiph@0: end Xiiph@0: Xiiph@0: local function Tree_OnMouseWheel(frame, delta) Xiiph@0: local self = frame.obj Xiiph@0: if self.showscroll then Xiiph@0: local scrollbar = self.scrollbar Xiiph@0: local min, max = scrollbar:GetMinMaxValues() Xiiph@0: local value = scrollbar:GetValue() Xiiph@0: local newvalue = math_min(max,math_max(min,value - delta)) Xiiph@0: if value ~= newvalue then Xiiph@0: scrollbar:SetValue(newvalue) Xiiph@0: end Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: local function Dragger_OnLeave(frame) Xiiph@0: frame:SetBackdropColor(1, 1, 1, 0) Xiiph@0: end Xiiph@0: Xiiph@0: local function Dragger_OnEnter(frame) Xiiph@0: frame:SetBackdropColor(1, 1, 1, 0.8) Xiiph@0: end Xiiph@0: Xiiph@0: local function Dragger_OnMouseDown(frame) Xiiph@0: local treeframe = frame:GetParent() Xiiph@0: treeframe:StartSizing("RIGHT") Xiiph@0: end Xiiph@0: Xiiph@0: local function Dragger_OnMouseUp(frame) Xiiph@0: local treeframe = frame:GetParent() Xiiph@0: local self = treeframe.obj Xiiph@0: local frame = treeframe:GetParent() Xiiph@0: treeframe:StopMovingOrSizing() Xiiph@0: --treeframe:SetScript("OnUpdate", nil) Xiiph@0: treeframe:SetUserPlaced(false) Xiiph@0: --Without this :GetHeight will get stuck on the current height, causing the tree contents to not resize Xiiph@0: treeframe:SetHeight(0) Xiiph@0: treeframe:SetPoint("TOPLEFT", frame, "TOPLEFT",0,0) Xiiph@0: treeframe:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT",0,0) Xiiph@0: Xiiph@0: local status = self.status or self.localstatus Xiiph@0: status.treewidth = treeframe:GetWidth() Xiiph@0: Xiiph@0: treeframe.obj:Fire("OnTreeResize",treeframe:GetWidth()) Xiiph@0: -- recalculate the content width Xiiph@0: treeframe.obj:OnWidthSet(status.fullwidth) Xiiph@0: -- update the layout of the content Xiiph@0: treeframe.obj:DoLayout() Xiiph@0: end Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Methods Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local methods = { Xiiph@0: ["OnAcquire"] = function(self) Xiiph@0: self:SetTreeWidth(DEFAULT_TREE_WIDTH, DEFAULT_TREE_SIZABLE) Xiiph@0: self:EnableButtonTooltips(true) Xiiph@0: end, Xiiph@0: Xiiph@0: ["OnRelease"] = function(self) Xiiph@0: self.status = nil Xiiph@0: for k, v in pairs(self.localstatus) do Xiiph@0: if k == "groups" then Xiiph@0: for k2 in pairs(v) do Xiiph@0: v[k2] = nil Xiiph@0: end Xiiph@0: else Xiiph@0: self.localstatus[k] = nil Xiiph@0: end Xiiph@0: end Xiiph@0: self.localstatus.scrollvalue = 0 Xiiph@0: self.localstatus.treewidth = DEFAULT_TREE_WIDTH Xiiph@0: self.localstatus.treesizable = DEFAULT_TREE_SIZABLE Xiiph@0: end, Xiiph@0: Xiiph@0: ["EnableButtonTooltips"] = function(self, enable) Xiiph@0: self.enabletooltips = enable Xiiph@0: end, Xiiph@0: Xiiph@0: ["CreateButton"] = function(self) Xiiph@0: local num = AceGUI:GetNextWidgetNum("TreeGroupButton") Xiiph@0: local button = CreateFrame("Button", ("AceGUI30TreeButton%d"):format(num), self.treeframe, "OptionsListButtonTemplate") Xiiph@0: button.obj = self Xiiph@0: Xiiph@0: local icon = button:CreateTexture(nil, "OVERLAY") Xiiph@0: icon:SetWidth(14) Xiiph@0: icon:SetHeight(14) Xiiph@0: button.icon = icon Xiiph@0: Xiiph@0: button:SetScript("OnClick",Button_OnClick) Xiiph@0: button:SetScript("OnDoubleClick", Button_OnDoubleClick) Xiiph@0: button:SetScript("OnEnter",Button_OnEnter) Xiiph@0: button:SetScript("OnLeave",Button_OnLeave) Xiiph@0: Xiiph@0: button.toggle.button = button Xiiph@0: button.toggle:SetScript("OnClick",Expand_OnClick) Xiiph@0: Xiiph@0: return button Xiiph@0: end, Xiiph@0: Xiiph@0: ["SetStatusTable"] = function(self, status) Xiiph@0: assert(type(status) == "table") Xiiph@0: self.status = status Xiiph@0: if not status.groups then Xiiph@0: status.groups = {} Xiiph@0: end Xiiph@0: if not status.scrollvalue then Xiiph@0: status.scrollvalue = 0 Xiiph@0: end Xiiph@0: if not status.treewidth then Xiiph@0: status.treewidth = DEFAULT_TREE_WIDTH Xiiph@0: end Xiiph@0: if status.treesizable == nil then Xiiph@0: status.treesizable = DEFAULT_TREE_SIZABLE Xiiph@0: end Xiiph@0: self:SetTreeWidth(status.treewidth,status.treesizable) Xiiph@0: self:RefreshTree() Xiiph@0: end, Xiiph@0: Xiiph@0: --sets the tree to be displayed Xiiph@0: ["SetTree"] = function(self, tree, filter) Xiiph@0: self.filter = filter Xiiph@0: if tree then Xiiph@0: assert(type(tree) == "table") Xiiph@0: end Xiiph@0: self.tree = tree Xiiph@0: self:RefreshTree() Xiiph@0: end, Xiiph@0: Xiiph@0: ["BuildLevel"] = function(self, tree, level, parent) Xiiph@0: local groups = (self.status or self.localstatus).groups Xiiph@0: local hasChildren = self.hasChildren Xiiph@0: Xiiph@0: for i, v in ipairs(tree) do Xiiph@0: if v.children then Xiiph@0: if not self.filter or ShouldDisplayLevel(v.children) then Xiiph@0: local line = addLine(self, v, tree, level, parent) Xiiph@0: if groups[line.uniquevalue] then Xiiph@0: self:BuildLevel(v.children, level+1, line) Xiiph@0: end Xiiph@0: end Xiiph@0: elseif v.visible ~= false or not self.filter then Xiiph@0: addLine(self, v, tree, level, parent) Xiiph@0: end Xiiph@0: end Xiiph@0: end, Xiiph@0: Xiiph@0: ["RefreshTree"] = function(self) Xiiph@0: local buttons = self.buttons Xiiph@0: local lines = self.lines Xiiph@0: Xiiph@0: for i, v in ipairs(buttons) do Xiiph@0: v:Hide() Xiiph@0: end Xiiph@0: while lines[1] do Xiiph@0: local t = tremove(lines) Xiiph@0: for k in pairs(t) do Xiiph@0: t[k] = nil Xiiph@0: end Xiiph@0: del(t) Xiiph@0: end Xiiph@0: Xiiph@0: if not self.tree then return end Xiiph@0: --Build the list of visible entries from the tree and status tables Xiiph@0: local status = self.status or self.localstatus Xiiph@0: local groupstatus = status.groups Xiiph@0: local tree = self.tree Xiiph@0: Xiiph@0: local treeframe = self.treeframe Xiiph@0: Xiiph@0: self:BuildLevel(tree, 1) Xiiph@0: Xiiph@0: local numlines = #lines Xiiph@0: Xiiph@0: local maxlines = (floor(((self.treeframe:GetHeight()or 0) - 20 ) / 18)) Xiiph@0: if maxlines <= 0 then return end Xiiph@0: Xiiph@0: local first, last Xiiph@0: Xiiph@0: if numlines <= maxlines then Xiiph@0: --the whole tree fits in the frame Xiiph@0: status.scrollvalue = 0 Xiiph@0: self:ShowScroll(false) Xiiph@0: first, last = 1, numlines Xiiph@0: else Xiiph@0: self:ShowScroll(true) Xiiph@0: --scrolling will be needed Xiiph@0: self.noupdate = true Xiiph@0: self.scrollbar:SetMinMaxValues(0, numlines - maxlines) Xiiph@0: --check if we are scrolled down too far Xiiph@0: if numlines - status.scrollvalue < maxlines then Xiiph@0: status.scrollvalue = numlines - maxlines Xiiph@0: end Xiiph@0: if self.scrollbar:GetValue() ~= status.scrollvalue then Xiiph@0: self.scrollbar:SetValue(status.scrollvalue) Xiiph@0: end Xiiph@0: self.noupdate = nil Xiiph@0: first, last = status.scrollvalue+1, status.scrollvalue + maxlines Xiiph@0: end Xiiph@0: Xiiph@0: local buttonnum = 1 Xiiph@0: for i = first, last do Xiiph@0: local line = lines[i] Xiiph@0: local button = buttons[buttonnum] Xiiph@0: if not button then Xiiph@0: button = self:CreateButton() Xiiph@0: Xiiph@0: buttons[buttonnum] = button Xiiph@0: button:SetParent(treeframe) Xiiph@0: button:SetFrameLevel(treeframe:GetFrameLevel()+1) Xiiph@0: button:ClearAllPoints() Xiiph@0: if buttonnum == 1 then Xiiph@0: if self.showscroll then Xiiph@0: button:SetPoint("TOPRIGHT", -22, -10) Xiiph@0: button:SetPoint("TOPLEFT", 0, -10) Xiiph@0: else Xiiph@0: button:SetPoint("TOPRIGHT", 0, -10) Xiiph@0: button:SetPoint("TOPLEFT", 0, -10) Xiiph@0: end Xiiph@0: else Xiiph@0: button:SetPoint("TOPRIGHT", buttons[buttonnum-1], "BOTTOMRIGHT",0,0) Xiiph@0: button:SetPoint("TOPLEFT", buttons[buttonnum-1], "BOTTOMLEFT",0,0) Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: UpdateButton(button, line, status.selected == line.uniquevalue, line.hasChildren, groupstatus[line.uniquevalue] ) Xiiph@0: button:Show() Xiiph@0: buttonnum = buttonnum + 1 Xiiph@0: end Xiiph@0: end, Xiiph@0: Xiiph@0: ["SetSelected"] = function(self, value) Xiiph@0: local status = self.status or self.localstatus Xiiph@0: if status.selected ~= value then Xiiph@0: status.selected = value Xiiph@0: self:Fire("OnGroupSelected", value) Xiiph@0: end Xiiph@0: end, Xiiph@0: Xiiph@0: ["Select"] = function(self, uniquevalue, ...) Xiiph@0: self.filter = false Xiiph@0: local status = self.status or self.localstatus Xiiph@0: local groups = status.groups Xiiph@0: for i = 1, select('#', ...) do Xiiph@0: groups[BuildUniqueValue(select(i, ...))] = true Xiiph@0: end Xiiph@0: status.selected = uniquevalue Xiiph@0: self:RefreshTree() Xiiph@0: self:Fire("OnGroupSelected", uniquevalue) Xiiph@0: end, Xiiph@0: Xiiph@0: ["SelectByPath"] = function(self, ...) Xiiph@0: self:Select(BuildUniqueValue(...), ...) Xiiph@0: end, Xiiph@0: Xiiph@0: ["SelectByValue"] = function(self, uniquevalue) Xiiph@0: self:Select(uniquevalue, ("\001"):split(uniquevalue)) Xiiph@0: end, Xiiph@0: Xiiph@0: ["ShowScroll"] = function(self, show) Xiiph@0: self.showscroll = show Xiiph@0: if show then Xiiph@0: self.scrollbar:Show() Xiiph@0: if self.buttons[1] then Xiiph@0: self.buttons[1]:SetPoint("TOPRIGHT", self.treeframe,"TOPRIGHT",-22,-10) Xiiph@0: end Xiiph@0: else Xiiph@0: self.scrollbar:Hide() Xiiph@0: if self.buttons[1] then Xiiph@0: self.buttons[1]:SetPoint("TOPRIGHT", self.treeframe,"TOPRIGHT",0,-10) Xiiph@0: end Xiiph@0: end Xiiph@0: end, Xiiph@0: Xiiph@0: ["OnWidthSet"] = function(self, width) Xiiph@0: local content = self.content Xiiph@0: local treeframe = self.treeframe Xiiph@0: local status = self.status or self.localstatus Xiiph@0: status.fullwidth = width Xiiph@0: Xiiph@0: local contentwidth = width - status.treewidth - 20 Xiiph@0: if contentwidth < 0 then Xiiph@0: contentwidth = 0 Xiiph@0: end Xiiph@0: content:SetWidth(contentwidth) Xiiph@0: content.width = contentwidth Xiiph@0: Xiiph@0: local maxtreewidth = math_min(400, width - 50) Xiiph@0: Xiiph@0: if maxtreewidth > 100 and status.treewidth > maxtreewidth then Xiiph@0: self:SetTreeWidth(maxtreewidth, status.treesizable) Xiiph@0: end Xiiph@0: treeframe:SetMaxResize(maxtreewidth, 1600) Xiiph@0: end, Xiiph@0: Xiiph@0: ["OnHeightSet"] = function(self, height) Xiiph@0: local content = self.content Xiiph@0: local contentheight = height - 20 Xiiph@0: if contentheight < 0 then Xiiph@0: contentheight = 0 Xiiph@0: end Xiiph@0: content:SetHeight(contentheight) Xiiph@0: content.height = contentheight Xiiph@0: end, Xiiph@0: Xiiph@0: ["SetTreeWidth"] = function(self, treewidth, resizable) Xiiph@0: if not resizable then Xiiph@0: if type(treewidth) == 'number' then Xiiph@0: resizable = false Xiiph@0: elseif type(treewidth) == 'boolean' then Xiiph@0: resizable = treewidth Xiiph@0: treewidth = DEFAULT_TREE_WIDTH Xiiph@0: else Xiiph@0: resizable = false Xiiph@0: treewidth = DEFAULT_TREE_WIDTH Xiiph@0: end Xiiph@0: end Xiiph@0: self.treeframe:SetWidth(treewidth) Xiiph@0: self.dragger:EnableMouse(resizable) Xiiph@0: Xiiph@0: local status = self.status or self.localstatus Xiiph@0: status.treewidth = treewidth Xiiph@0: status.treesizable = resizable Xiiph@0: Xiiph@0: -- recalculate the content width Xiiph@0: if status.fullwidth then Xiiph@0: self:OnWidthSet(status.fullwidth) Xiiph@0: end Xiiph@0: end, Xiiph@0: Xiiph@0: ["LayoutFinished"] = function(self, width, height) Xiiph@0: if self.noAutoHeight then return end Xiiph@0: self:SetHeight((height or 0) + 20) Xiiph@0: end Xiiph@0: } Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Constructor Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local PaneBackdrop = { Xiiph@0: bgFile = "Interface\\ChatFrame\\ChatFrameBackground", Xiiph@0: edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", Xiiph@0: tile = true, tileSize = 16, edgeSize = 16, Xiiph@0: insets = { left = 3, right = 3, top = 5, bottom = 3 } Xiiph@0: } Xiiph@0: Xiiph@0: local DraggerBackdrop = { Xiiph@0: bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", Xiiph@0: edgeFile = nil, Xiiph@0: tile = true, tileSize = 16, edgeSize = 0, Xiiph@0: insets = { left = 3, right = 3, top = 7, bottom = 7 } Xiiph@0: } Xiiph@0: Xiiph@0: local function Constructor() Xiiph@0: local num = AceGUI:GetNextWidgetNum(Type) Xiiph@0: local frame = CreateFrame("Frame", nil, UIParent) Xiiph@0: Xiiph@0: local treeframe = CreateFrame("Frame", nil, frame) Xiiph@0: treeframe:SetPoint("TOPLEFT") Xiiph@0: treeframe:SetPoint("BOTTOMLEFT") Xiiph@0: treeframe:SetWidth(DEFAULT_TREE_WIDTH) Xiiph@0: treeframe:EnableMouseWheel(true) Xiiph@0: treeframe:SetBackdrop(PaneBackdrop) Xiiph@0: treeframe:SetBackdropColor(0.1, 0.1, 0.1, 0.5) Xiiph@0: treeframe:SetBackdropBorderColor(0.4, 0.4, 0.4) Xiiph@0: treeframe:SetResizable(true) Xiiph@0: treeframe:SetMinResize(100, 1) Xiiph@0: treeframe:SetMaxResize(400, 1600) Xiiph@0: treeframe:SetScript("OnUpdate", FirstFrameUpdate) Xiiph@0: treeframe:SetScript("OnSizeChanged", Tree_OnSizeChanged) Xiiph@0: treeframe:SetScript("OnMouseWheel", Tree_OnMouseWheel) Xiiph@0: Xiiph@0: local dragger = CreateFrame("Frame", nil, treeframe) Xiiph@0: dragger:SetWidth(8) Xiiph@0: dragger:SetPoint("TOP", treeframe, "TOPRIGHT") Xiiph@0: dragger:SetPoint("BOTTOM", treeframe, "BOTTOMRIGHT") Xiiph@0: dragger:SetBackdrop(DraggerBackdrop) Xiiph@0: dragger:SetBackdropColor(1, 1, 1, 0) Xiiph@0: dragger:SetScript("OnEnter", Dragger_OnEnter) Xiiph@0: dragger:SetScript("OnLeave", Dragger_OnLeave) Xiiph@0: dragger:SetScript("OnMouseDown", Dragger_OnMouseDown) Xiiph@0: dragger:SetScript("OnMouseUp", Dragger_OnMouseUp) Xiiph@0: Xiiph@0: local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), treeframe, "UIPanelScrollBarTemplate") Xiiph@0: scrollbar:SetScript("OnValueChanged", nil) Xiiph@0: scrollbar:SetPoint("TOPRIGHT", -10, -26) Xiiph@0: scrollbar:SetPoint("BOTTOMRIGHT", -10, 26) Xiiph@0: scrollbar:SetMinMaxValues(0,0) Xiiph@0: scrollbar:SetValueStep(1) Xiiph@0: scrollbar:SetValue(0) Xiiph@0: scrollbar:SetWidth(16) Xiiph@0: scrollbar:SetScript("OnValueChanged", OnScrollValueChanged) Xiiph@0: Xiiph@0: local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND") Xiiph@0: scrollbg:SetAllPoints(scrollbar) Xiiph@0: scrollbg:SetTexture(0,0,0,0.4) Xiiph@0: Xiiph@0: local border = CreateFrame("Frame",nil,frame) Xiiph@0: border:SetPoint("TOPLEFT", treeframe, "TOPRIGHT") Xiiph@0: border:SetPoint("BOTTOMRIGHT") Xiiph@0: border:SetBackdrop(PaneBackdrop) Xiiph@0: border:SetBackdropColor(0.1, 0.1, 0.1, 0.5) Xiiph@0: border:SetBackdropBorderColor(0.4, 0.4, 0.4) Xiiph@0: Xiiph@0: --Container Support Xiiph@0: local content = CreateFrame("Frame", nil, border) Xiiph@0: content:SetPoint("TOPLEFT", 10, -10) Xiiph@0: content:SetPoint("BOTTOMRIGHT", -10, 10) Xiiph@0: Xiiph@0: local widget = { Xiiph@0: frame = frame, Xiiph@0: lines = {}, Xiiph@0: levels = {}, Xiiph@0: buttons = {}, Xiiph@0: hasChildren = {}, Xiiph@0: localstatus = { groups = {}, scrollvalue = 0 }, Xiiph@0: filter = false, Xiiph@0: treeframe = treeframe, Xiiph@0: dragger = dragger, Xiiph@0: scrollbar = scrollbar, Xiiph@0: border = border, Xiiph@0: content = content, Xiiph@0: type = Type Xiiph@0: } Xiiph@0: for method, func in pairs(methods) do Xiiph@0: widget[method] = func Xiiph@0: end Xiiph@0: treeframe.obj, dragger.obj, scrollbar.obj = widget, widget, widget Xiiph@0: Xiiph@0: return AceGUI:RegisterAsContainer(widget) Xiiph@0: end Xiiph@0: Xiiph@0: AceGUI:RegisterWidgetType(Type, Constructor, Version)