annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-DropDownGroup.lua @ 5:c31ee4251181

Libs Update
author tercio
date Tue, 25 Nov 2014 21:15:10 -0200
parents fc346da3afd9
children
rev   line source
tercio@0 1 --[[-----------------------------------------------------------------------------
tercio@0 2 DropdownGroup Container
tercio@0 3 Container controlled by a dropdown on the top.
tercio@0 4 -------------------------------------------------------------------------------]]
tercio@0 5 local Type, Version = "DropdownGroup", 21
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 assert, pairs, type = assert, pairs, type
tercio@0 11
tercio@0 12 -- WoW APIs
tercio@0 13 local CreateFrame = CreateFrame
tercio@0 14
tercio@0 15 --[[-----------------------------------------------------------------------------
tercio@0 16 Scripts
tercio@0 17 -------------------------------------------------------------------------------]]
tercio@0 18 local function SelectedGroup(self, event, value)
tercio@0 19 local group = self.parentgroup
tercio@0 20 local status = group.status or group.localstatus
tercio@0 21 status.selected = value
tercio@0 22 self.parentgroup:Fire("OnGroupSelected", value)
tercio@0 23 end
tercio@0 24
tercio@0 25 --[[-----------------------------------------------------------------------------
tercio@0 26 Methods
tercio@0 27 -------------------------------------------------------------------------------]]
tercio@0 28 local methods = {
tercio@0 29 ["OnAcquire"] = function(self)
tercio@0 30 self.dropdown:SetText("")
tercio@0 31 self:SetDropdownWidth(200)
tercio@0 32 self:SetTitle("")
tercio@0 33 end,
tercio@0 34
tercio@0 35 ["OnRelease"] = function(self)
tercio@0 36 self.dropdown.list = nil
tercio@0 37 self.status = nil
tercio@0 38 for k in pairs(self.localstatus) do
tercio@0 39 self.localstatus[k] = nil
tercio@0 40 end
tercio@0 41 end,
tercio@0 42
tercio@0 43 ["SetTitle"] = function(self, title)
tercio@0 44 self.titletext:SetText(title)
tercio@0 45 self.dropdown.frame:ClearAllPoints()
tercio@0 46 if title and title ~= "" then
tercio@0 47 self.dropdown.frame:SetPoint("TOPRIGHT", -2, 0)
tercio@0 48 else
tercio@0 49 self.dropdown.frame:SetPoint("TOPLEFT", -1, 0)
tercio@0 50 end
tercio@0 51 end,
tercio@0 52
tercio@0 53 ["SetGroupList"] = function(self,list,order)
tercio@0 54 self.dropdown:SetList(list,order)
tercio@0 55 end,
tercio@0 56
tercio@0 57 ["SetStatusTable"] = function(self, status)
tercio@0 58 assert(type(status) == "table")
tercio@0 59 self.status = status
tercio@0 60 end,
tercio@0 61
tercio@0 62 ["SetGroup"] = function(self,group)
tercio@0 63 self.dropdown:SetValue(group)
tercio@0 64 local status = self.status or self.localstatus
tercio@0 65 status.selected = group
tercio@0 66 self:Fire("OnGroupSelected", group)
tercio@0 67 end,
tercio@0 68
tercio@0 69 ["OnWidthSet"] = function(self, width)
tercio@0 70 local content = self.content
tercio@0 71 local contentwidth = width - 26
tercio@0 72 if contentwidth < 0 then
tercio@0 73 contentwidth = 0
tercio@0 74 end
tercio@0 75 content:SetWidth(contentwidth)
tercio@0 76 content.width = contentwidth
tercio@0 77 end,
tercio@0 78
tercio@0 79 ["OnHeightSet"] = function(self, height)
tercio@0 80 local content = self.content
tercio@0 81 local contentheight = height - 63
tercio@0 82 if contentheight < 0 then
tercio@0 83 contentheight = 0
tercio@0 84 end
tercio@0 85 content:SetHeight(contentheight)
tercio@0 86 content.height = contentheight
tercio@0 87 end,
tercio@0 88
tercio@0 89 ["LayoutFinished"] = function(self, width, height)
tercio@0 90 self:SetHeight((height or 0) + 63)
tercio@0 91 end,
tercio@0 92
tercio@0 93 ["SetDropdownWidth"] = function(self, width)
tercio@0 94 self.dropdown:SetWidth(width)
tercio@0 95 end
tercio@0 96 }
tercio@0 97
tercio@0 98 --[[-----------------------------------------------------------------------------
tercio@0 99 Constructor
tercio@0 100 -------------------------------------------------------------------------------]]
tercio@0 101 local PaneBackdrop = {
tercio@0 102 bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
tercio@0 103 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tercio@0 104 tile = true, tileSize = 16, edgeSize = 16,
tercio@0 105 insets = { left = 3, right = 3, top = 5, bottom = 3 }
tercio@0 106 }
tercio@0 107
tercio@0 108 local function Constructor()
tercio@0 109 local frame = CreateFrame("Frame")
tercio@0 110 frame:SetHeight(100)
tercio@0 111 frame:SetWidth(100)
tercio@0 112 frame:SetFrameStrata("FULLSCREEN_DIALOG")
tercio@0 113
tercio@0 114 local titletext = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
tercio@0 115 titletext:SetPoint("TOPLEFT", 4, -5)
tercio@0 116 titletext:SetPoint("TOPRIGHT", -4, -5)
tercio@0 117 titletext:SetJustifyH("LEFT")
tercio@0 118 titletext:SetHeight(18)
tercio@0 119
tercio@0 120 local dropdown = AceGUI:Create("Dropdown")
tercio@0 121 dropdown.frame:SetParent(frame)
tercio@0 122 dropdown.frame:SetFrameLevel(dropdown.frame:GetFrameLevel() + 2)
tercio@0 123 dropdown:SetCallback("OnValueChanged", SelectedGroup)
tercio@0 124 dropdown.frame:SetPoint("TOPLEFT", -1, 0)
tercio@0 125 dropdown.frame:Show()
tercio@0 126 dropdown:SetLabel("")
tercio@0 127
tercio@0 128 local border = CreateFrame("Frame", nil, frame)
tercio@0 129 border:SetPoint("TOPLEFT", 0, -26)
tercio@0 130 border:SetPoint("BOTTOMRIGHT", 0, 3)
tercio@0 131 border:SetBackdrop(PaneBackdrop)
tercio@0 132 border:SetBackdropColor(0.1,0.1,0.1,0.5)
tercio@0 133 border:SetBackdropBorderColor(0.4,0.4,0.4)
tercio@0 134
tercio@0 135 --Container Support
tercio@0 136 local content = CreateFrame("Frame", nil, border)
tercio@0 137 content:SetPoint("TOPLEFT", 10, -10)
tercio@0 138 content:SetPoint("BOTTOMRIGHT", -10, 10)
tercio@0 139
tercio@0 140 local widget = {
tercio@0 141 frame = frame,
tercio@0 142 localstatus = {},
tercio@0 143 titletext = titletext,
tercio@0 144 dropdown = dropdown,
tercio@0 145 border = border,
tercio@0 146 content = content,
tercio@0 147 type = Type
tercio@0 148 }
tercio@0 149 for method, func in pairs(methods) do
tercio@0 150 widget[method] = func
tercio@0 151 end
tercio@0 152 dropdown.parentgroup = widget
tercio@0 153
tercio@0 154 return AceGUI:RegisterAsContainer(widget)
tercio@0 155 end
tercio@0 156
tercio@0 157 AceGUI:RegisterWidgetType(Type, Constructor, Version)