annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-DropDownGroup.lua @ 57:01b63b8ed811 v21

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