annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-DropDownGroup.lua @ 63:3552946c0b9a tip

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