Mercurial > wow > breuesk
view SelectorList.lua @ 52:7c7e80f63b51
First pass. Taking stuff from TreeGroup that I like/need/want in order to make a standalone selection list
author | John@Yosemite-PC |
---|---|
date | Sat, 24 Mar 2012 13:37:29 -0400 |
parents | |
children | 708d8a423b4c |
line wrap: on
line source
-- no bsk namespace here - we're hooking into AceGUI local Type, Version = "SelectorList", 34 local AceGUI = LibStub and LibStub("AceGUI-3.0",true) if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type local math_min, math_max, floor = math.min, math.max, floor local select, tremove, unpack, tconcat = select, table.remove, unpack, table.concat local CreateFrame, UIParent = CreateFrame, UIParent local new, del do local pool = setmetatable({},{__mode='k'}) function new() local t = next(pool) if t then pool[t] = nil return t else return {} end end function del(t) for k in pairs(t) do t[k] = nil end pool[t] = true end end local DEFAULT_SL_WIDTH = 175 --local DEFAULT_TREE_SIZABLE = true local function Layout(self) self:SetHeight(self.numlines * 18 + 20) end local function CreateButton(widget) local num = AceGUI:GetNextWidgetNum("TreeGroupButton") local button = CreateFrame("Button", ("AceGUI30TreeButton%d"):format(num), widget.slframe, "OptionsListButtonTemplate") button.obj = widget local icon = button:CreateTexture(nil, "OVERLAY") icon:SetWidth(14) icon:SetHeight(14) button.icon = icon button:SetScript("OnClick",Button_OnClick) button:SetScript("OnDoubleClick", Button_OnDoubleClick) button:SetScript("OnEnter",Button_OnEnter) button:SetScript("OnLeave",Button_OnLeave) return button end local function UpdateButton(button, line, selected) local self = button.obj local frame = self.frame local text = line.text or "" local icon = line.icon local iconCoords = line.iconCoords local level = line.level or 1 local value = line.value local uniquevalue = line.uniquevalue local disabled = line.disabled button.line = line button.value = value button.uniquevalue = uniquevalue if selected then button:LockHighlight() button.selected = true else button:UnlockHighlight() button.selected = false end local normalTexture = button:GetNormalTexture() local line = button.line button.level = level if ( level == 1 ) then button:SetNormalFontObject("GameFontNormal") button:SetHighlightFontObject("GameFontHighlight") button.text:SetPoint("LEFT", (icon and 16 or 0) + 8, 2) else button:SetNormalFontObject("GameFontHighlightSmall") button:SetHighlightFontObject("GameFontHighlightSmall") button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2) end if disabled then button:EnableMouse(false) button.text:SetText("|cff808080"..text..FONT_COLOR_CODE_CLOSE) else button.text:SetText(text) button:EnableMouse(true) end if icon then button.icon:SetTexture(icon) button.icon:SetPoint("LEFT", 8 * level, (level == 1) and 0 or 1) else button.icon:SetTexture(nil) end if iconCoords then button.icon:SetTexCoord(unpack(iconCoords)) else button.icon:SetTexCoord(0, 1, 0, 1) end end local methods = { ["OnAcquire"] = function(self) self:SetWidth(DEFAULT_SL_WIDTH) self:SetNumLines() --self:EnableButtonTooltips(true) end, --["SetWidth"] = function(self, width) -- self.slframe:SetWidth(width) -- local status = self.status or self.localstatus -- status.width = width -- status.treesizable = resizable --end, ["SetNumLines"] = function(self,value) if not value or value < 4 then value = 4 end self.numlines = value Layout(self) end, ["SetList"] = function(self, list) for i,v in ipairs(list) do self.lines[i] = v end self:Refresh() end, ["Refresh"] = function(self) local f = self.slframe local buttons = self.buttons local lines = self.lines local bnum = 1 for i=1,self.numlines do local l = lines[i] if not l then break end local b = buttons[bnum] if not b then b = CreateButton(self) buttons[bnum] = b b:SetParent(f) b:SetFrameLevel(f:GetFrameLevel()+1) b:ClearAllPoints() if bnum == 1 then -- todo: if scroll ... b:SetPoint("TOPLEFT",0,-10) b:SetPoint("TOPRIGHT",0,-10) else b:SetPoint("TOPRIGHT", buttons[bnum-1], "BOTTOMRIGHT", 0, 0) b:SetPoint("TOPLEFT", buttons[bnum-1], "BOTTOMLEFT", 0, 0) end end UpdateButton(b, l) b:Show() bnum = bnum + 1 end end, } local PaneBackdrop = { bgFile = "Interface\\ChatFrame\\ChatFrameBackground", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, insets = { left = 3, right = 3, top = 5, bottom = 3 } } local function Constructor() local num = AceGUI:GetNextWidgetNum(Type) local frame = CreateFrame("Frame", nil, UIParent) local slframe = CreateFrame("Frame", nil, frame) slframe:SetAllPoints() --slframe:SetPoint("TOPLEFT") --slframe:SetPoint("BOTTOMLEFT") --slframe:SetWidth(DEFAULT_SL_WIDTH) --slframe:SetHeight(DEFAULT_SL_WIDTH) -- todo slframe:EnableMouseWheel(true) slframe:SetBackdrop(PaneBackdrop) slframe:SetBackdropColor(0.1, 0.1, 0.1, 0.5) slframe:SetBackdropBorderColor(0.4, 0.4, 0.4) --slframe:SetResizable(true) --slframe:SetMinResize(100, 1) --slframe:SetMaxResize(400, 1600) --slframe:SetScript("OnUpdate", FirstFrameUpdate) --slframe:SetScript("OnSizeChanged", Tree_OnSizeChanged) --slframe:SetScript("OnMouseWheel", Tree_OnMouseWheel) --local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), slframe, "UIPanelScrollBarTemplate") --scrollbar:SetScript("OnValueChanged", nil) --scrollbar:SetPoint("TOPRIGHT", -10, -26) --scrollbar:SetPoint("BOTTOMRIGHT", -10, 26) --scrollbar:SetMinMaxValues(0,0) --scrollbar:SetValueStep(1) --scrollbar:SetValue(0) --scrollbar:SetWidth(16) --scrollbar:SetScript("OnValueChanged", OnScrollValueChanged) --local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND") --scrollbg:SetAllPoints(scrollbar) --scrollbg:SetTexture(0,0,0,0.4) --local border = CreateFrame("Frame",nil,frame) --border:SetPoint("TOPLEFT", slframe, "TOPRIGHT") --border:SetPoint("BOTTOMRIGHT") --border:SetBackdrop(PaneBackdrop) --border:SetBackdropColor(0.1, 0.1, 0.1, 0.5) --border:SetBackdropBorderColor(0.4, 0.4, 0.4) ----Container Support --local content = CreateFrame("Frame", nil, border) --content:SetPoint("TOPLEFT", 10, -10) --content:SetPoint("BOTTOMRIGHT", -10, 10) local widget = { frame = frame, lines = {}, --levels = {}, buttons = {}, --hasChildren = {}, localstatus = { --groups = {}, scrollvalue = 0 }, filter = false, slframe = slframe, --dragger = dragger, --scrollbar = scrollbar, --border = border, --content = slframe, -- content is for containers type = Type } if methods then for method, func in pairs(methods) do widget[method] = func end end slframe.obj = widget --dragger.obj = widget --scrollbar.obj = widget return AceGUI:RegisterAsWidget(widget) end AceGUI:RegisterWidgetType(Type, Constructor, Version)