Mercurial > wow > askmrrobot
comparison Libs/AceGUI-3.0/widgets/AceGUIContainer-BlizOptionsGroup.lua @ 57:01b63b8ed811 v21
total rewrite to version 21
| author | yellowfive |
|---|---|
| date | Fri, 05 Jun 2015 11:05:15 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 56:75431c084aa0 | 57:01b63b8ed811 |
|---|---|
| 1 --[[----------------------------------------------------------------------------- | |
| 2 BlizOptionsGroup Container | |
| 3 Simple container widget for the integration of AceGUI into the Blizzard Interface Options | |
| 4 -------------------------------------------------------------------------------]] | |
| 5 local Type, Version = "BlizOptionsGroup", 21 | |
| 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true) | |
| 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end | |
| 8 | |
| 9 -- Lua APIs | |
| 10 local pairs = pairs | |
| 11 | |
| 12 -- WoW APIs | |
| 13 local CreateFrame = CreateFrame | |
| 14 | |
| 15 --[[----------------------------------------------------------------------------- | |
| 16 Scripts | |
| 17 -------------------------------------------------------------------------------]] | |
| 18 | |
| 19 local function OnShow(frame) | |
| 20 frame.obj:Fire("OnShow") | |
| 21 end | |
| 22 | |
| 23 local function OnHide(frame) | |
| 24 frame.obj:Fire("OnHide") | |
| 25 end | |
| 26 | |
| 27 --[[----------------------------------------------------------------------------- | |
| 28 Support functions | |
| 29 -------------------------------------------------------------------------------]] | |
| 30 | |
| 31 local function okay(frame) | |
| 32 frame.obj:Fire("okay") | |
| 33 end | |
| 34 | |
| 35 local function cancel(frame) | |
| 36 frame.obj:Fire("cancel") | |
| 37 end | |
| 38 | |
| 39 local function default(frame) | |
| 40 frame.obj:Fire("default") | |
| 41 end | |
| 42 | |
| 43 local function refresh(frame) | |
| 44 frame.obj:Fire("refresh") | |
| 45 end | |
| 46 | |
| 47 --[[----------------------------------------------------------------------------- | |
| 48 Methods | |
| 49 -------------------------------------------------------------------------------]] | |
| 50 | |
| 51 local methods = { | |
| 52 ["OnAcquire"] = function(self) | |
| 53 self:SetName() | |
| 54 self:SetTitle() | |
| 55 end, | |
| 56 | |
| 57 -- ["OnRelease"] = nil, | |
| 58 | |
| 59 ["OnWidthSet"] = function(self, width) | |
| 60 local content = self.content | |
| 61 local contentwidth = width - 63 | |
| 62 if contentwidth < 0 then | |
| 63 contentwidth = 0 | |
| 64 end | |
| 65 content:SetWidth(contentwidth) | |
| 66 content.width = contentwidth | |
| 67 end, | |
| 68 | |
| 69 ["OnHeightSet"] = function(self, height) | |
| 70 local content = self.content | |
| 71 local contentheight = height - 26 | |
| 72 if contentheight < 0 then | |
| 73 contentheight = 0 | |
| 74 end | |
| 75 content:SetHeight(contentheight) | |
| 76 content.height = contentheight | |
| 77 end, | |
| 78 | |
| 79 ["SetName"] = function(self, name, parent) | |
| 80 self.frame.name = name | |
| 81 self.frame.parent = parent | |
| 82 end, | |
| 83 | |
| 84 ["SetTitle"] = function(self, title) | |
| 85 local content = self.content | |
| 86 content:ClearAllPoints() | |
| 87 if not title or title == "" then | |
| 88 content:SetPoint("TOPLEFT", 10, -10) | |
| 89 self.label:SetText("") | |
| 90 else | |
| 91 content:SetPoint("TOPLEFT", 10, -40) | |
| 92 self.label:SetText(title) | |
| 93 end | |
| 94 content:SetPoint("BOTTOMRIGHT", -10, 10) | |
| 95 end | |
| 96 } | |
| 97 | |
| 98 --[[----------------------------------------------------------------------------- | |
| 99 Constructor | |
| 100 -------------------------------------------------------------------------------]] | |
| 101 local function Constructor() | |
| 102 local frame = CreateFrame("Frame") | |
| 103 frame:Hide() | |
| 104 | |
| 105 -- support functions for the Blizzard Interface Options | |
| 106 frame.okay = okay | |
| 107 frame.cancel = cancel | |
| 108 frame.default = default | |
| 109 frame.refresh = refresh | |
| 110 | |
| 111 frame:SetScript("OnHide", OnHide) | |
| 112 frame:SetScript("OnShow", OnShow) | |
| 113 | |
| 114 local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge") | |
| 115 label:SetPoint("TOPLEFT", 10, -15) | |
| 116 label:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 10, -45) | |
| 117 label:SetJustifyH("LEFT") | |
| 118 label:SetJustifyV("TOP") | |
| 119 | |
| 120 --Container Support | |
| 121 local content = CreateFrame("Frame", nil, frame) | |
| 122 content:SetPoint("TOPLEFT", 10, -10) | |
| 123 content:SetPoint("BOTTOMRIGHT", -10, 10) | |
| 124 | |
| 125 local widget = { | |
| 126 label = label, | |
| 127 frame = frame, | |
| 128 content = content, | |
| 129 type = Type | |
| 130 } | |
| 131 for method, func in pairs(methods) do | |
| 132 widget[method] = func | |
| 133 end | |
| 134 | |
| 135 return AceGUI:RegisterAsContainer(widget) | |
| 136 end | |
| 137 | |
| 138 AceGUI:RegisterWidgetType(Type, Constructor, Version) |
