annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-DropDownGroup.lua @ 0:c6ff7ba0e8f6

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