Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: BlizOptionsGroup Container Xiiph@0: Simple container widget for the integration of AceGUI into the Blizzard Interface Options Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local Type, Version = "BlizOptionsGroup", 20 Xiiph@0: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) Xiiph@0: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end Xiiph@0: Xiiph@0: -- Lua APIs Xiiph@0: local pairs = pairs Xiiph@0: Xiiph@0: -- WoW APIs Xiiph@0: local CreateFrame = CreateFrame Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Scripts Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: Xiiph@0: local function OnShow(frame) Xiiph@0: frame.obj:Fire("OnShow") Xiiph@0: end Xiiph@0: Xiiph@0: local function OnHide(frame) Xiiph@0: frame.obj:Fire("OnHide") Xiiph@0: end Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Support functions Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: Xiiph@0: local function okay(frame) Xiiph@0: frame.obj:Fire("okay") Xiiph@0: end Xiiph@0: Xiiph@0: local function cancel(frame) Xiiph@0: frame.obj:Fire("cancel") Xiiph@0: end Xiiph@0: Xiiph@0: local function defaults(frame) Xiiph@0: frame.obj:Fire("defaults") Xiiph@0: end Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Methods Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: Xiiph@0: local methods = { Xiiph@0: ["OnAcquire"] = function(self) Xiiph@0: self:SetName() Xiiph@0: self:SetTitle() Xiiph@0: end, Xiiph@0: Xiiph@0: -- ["OnRelease"] = nil, Xiiph@0: Xiiph@0: ["OnWidthSet"] = function(self, width) Xiiph@0: local content = self.content Xiiph@0: local contentwidth = width - 63 Xiiph@0: if contentwidth < 0 then Xiiph@0: contentwidth = 0 Xiiph@0: end Xiiph@0: content:SetWidth(contentwidth) Xiiph@0: content.width = contentwidth Xiiph@0: end, Xiiph@0: Xiiph@0: ["OnHeightSet"] = function(self, height) Xiiph@0: local content = self.content Xiiph@0: local contentheight = height - 26 Xiiph@0: if contentheight < 0 then Xiiph@0: contentheight = 0 Xiiph@0: end Xiiph@0: content:SetHeight(contentheight) Xiiph@0: content.height = contentheight Xiiph@0: end, Xiiph@0: Xiiph@0: ["SetName"] = function(self, name, parent) Xiiph@0: self.frame.name = name Xiiph@0: self.frame.parent = parent Xiiph@0: end, Xiiph@0: Xiiph@0: ["SetTitle"] = function(self, title) Xiiph@0: local content = self.content Xiiph@0: content:ClearAllPoints() Xiiph@0: if not title or title == "" then Xiiph@0: content:SetPoint("TOPLEFT", 10, -10) Xiiph@0: self.label:SetText("") Xiiph@0: else Xiiph@0: content:SetPoint("TOPLEFT", 10, -40) Xiiph@0: self.label:SetText(title) Xiiph@0: end Xiiph@0: content:SetPoint("BOTTOMRIGHT", -10, 10) Xiiph@0: end Xiiph@0: } Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Constructor Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local function Constructor() Xiiph@0: local frame = CreateFrame("Frame") Xiiph@0: frame:Hide() Xiiph@0: Xiiph@0: -- support functions for the Blizzard Interface Options Xiiph@0: frame.okay = okay Xiiph@0: frame.cancel = cancel Xiiph@0: frame.defaults = defaults Xiiph@0: Xiiph@0: frame:SetScript("OnHide", OnHide) Xiiph@0: frame:SetScript("OnShow", OnShow) Xiiph@0: Xiiph@0: local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge") Xiiph@0: label:SetPoint("TOPLEFT", 10, -15) Xiiph@0: label:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 10, -45) Xiiph@0: label:SetJustifyH("LEFT") Xiiph@0: label:SetJustifyV("TOP") Xiiph@0: Xiiph@0: --Container Support Xiiph@0: local content = CreateFrame("Frame", nil, frame) Xiiph@0: content:SetPoint("TOPLEFT", 10, -10) Xiiph@0: content:SetPoint("BOTTOMRIGHT", -10, 10) Xiiph@0: Xiiph@0: local widget = { Xiiph@0: label = label, Xiiph@0: frame = frame, Xiiph@0: content = content, Xiiph@0: type = Type Xiiph@0: } Xiiph@0: for method, func in pairs(methods) do Xiiph@0: widget[method] = func Xiiph@0: end Xiiph@0: Xiiph@0: return AceGUI:RegisterAsContainer(widget) Xiiph@0: end Xiiph@0: Xiiph@0: AceGUI:RegisterWidgetType(Type, Constructor, Version)