yellowfive@57
|
1 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
2 Label Widget
|
yellowfive@57
|
3 Displays text.
|
yellowfive@57
|
4 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
5 local Type, Version = "AmrUiLabel", 1
|
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 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
|
yellowfive@57
|
10
|
yellowfive@57
|
11 -- Lua APIs
|
yellowfive@133
|
12 local pairs = pairs
|
yellowfive@57
|
13
|
yellowfive@57
|
14 -- WoW APIs
|
yellowfive@57
|
15 local CreateFrame, UIParent = CreateFrame, UIParent
|
yellowfive@57
|
16
|
yellowfive@57
|
17
|
yellowfive@57
|
18 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
19 Support functions
|
yellowfive@57
|
20 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
21
|
yellowfive@57
|
22 local function updateSize(self)
|
yellowfive@57
|
23 if self.resizing then return end
|
yellowfive@57
|
24 local frame = self.frame
|
yellowfive@57
|
25 local width = frame.width or frame:GetWidth() or 0
|
yellowfive@57
|
26 local label = self.label
|
yellowfive@57
|
27 local height
|
yellowfive@57
|
28
|
yellowfive@57
|
29 label:ClearAllPoints()
|
yellowfive@57
|
30 label:SetPoint("TOPLEFT")
|
yellowfive@57
|
31 label:SetWidth(width)
|
yellowfive@57
|
32 height = label:GetHeight()
|
yellowfive@57
|
33
|
yellowfive@57
|
34 self.resizing = true
|
yellowfive@57
|
35 frame:SetHeight(height)
|
yellowfive@57
|
36 frame.height = height
|
yellowfive@57
|
37 self.resizing = nil
|
yellowfive@57
|
38 end
|
yellowfive@57
|
39
|
yellowfive@57
|
40 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
41 Scripts
|
yellowfive@57
|
42 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
43
|
yellowfive@57
|
44 local function frameOnEnter(frame)
|
yellowfive@57
|
45 frame.obj:Fire("OnEnter")
|
yellowfive@57
|
46 end
|
yellowfive@57
|
47
|
yellowfive@57
|
48 local function frameOnLeave(frame)
|
yellowfive@57
|
49 frame.obj:Fire("OnLeave")
|
yellowfive@57
|
50 end
|
yellowfive@57
|
51
|
yellowfive@57
|
52 local function frameOnMouseDown(frame, ...)
|
yellowfive@57
|
53 frame.obj:Fire("OnMouseDown", ...)
|
yellowfive@57
|
54 end
|
yellowfive@57
|
55
|
yellowfive@57
|
56 local function frameOnMouseUp(frame, ...)
|
yellowfive@57
|
57 frame.obj:Fire("OnMouseUp", ...)
|
yellowfive@57
|
58 end
|
yellowfive@57
|
59
|
yellowfive@57
|
60 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
61 Methods
|
yellowfive@57
|
62 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
63 local methods = {
|
yellowfive@57
|
64 ["OnAcquire"] = function(self)
|
yellowfive@57
|
65 -- set the flag to stop constant size updates
|
yellowfive@57
|
66 self.resizing = true
|
yellowfive@57
|
67 -- height is set dynamically by the text size
|
yellowfive@57
|
68 self:SetWidth(200)
|
yellowfive@57
|
69 self:SetText()
|
yellowfive@57
|
70 self:SetFont(Amr.CreateFont("Regular", 16, Amr.Colors.Text))
|
yellowfive@57
|
71 self:SetJustifyH("LEFT")
|
yellowfive@57
|
72 self:SetJustifyV("MIDDLE")
|
yellowfive@57
|
73 self:SetWordWrap(true)
|
yellowfive@57
|
74 self:SetVisible(true)
|
yellowfive@57
|
75
|
yellowfive@57
|
76 -- reset the flag
|
yellowfive@57
|
77 self.resizing = nil
|
yellowfive@57
|
78 -- run the update explicitly
|
yellowfive@124
|
79 --updateSize(self)
|
yellowfive@57
|
80 end,
|
yellowfive@57
|
81
|
yellowfive@57
|
82 -- ["OnRelease"] = nil,
|
yellowfive@57
|
83
|
yellowfive@57
|
84 ["OnWidthSet"] = function(self, width)
|
yellowfive@57
|
85 updateSize(self)
|
yellowfive@57
|
86 end,
|
yellowfive@57
|
87
|
yellowfive@57
|
88 ["GetHeight"] = function(self)
|
yellowfive@57
|
89 return self.frame:GetHeight()
|
yellowfive@57
|
90 end,
|
yellowfive@57
|
91
|
yellowfive@57
|
92 ["SetText"] = function(self, text)
|
yellowfive@57
|
93 self.label:SetText(text)
|
yellowfive@57
|
94 updateSize(self)
|
yellowfive@57
|
95 end,
|
yellowfive@57
|
96
|
yellowfive@57
|
97 ["SetFont"] = function(self, font)
|
yellowfive@57
|
98 self.label:SetFontObject(font)
|
yellowfive@57
|
99 updateSize(self)
|
yellowfive@57
|
100 end,
|
yellowfive@57
|
101
|
yellowfive@57
|
102 ["SetJustifyV"] = function(self, val)
|
yellowfive@57
|
103 self.label:SetJustifyV(val)
|
yellowfive@57
|
104 end,
|
yellowfive@57
|
105
|
yellowfive@57
|
106 ["SetJustifyH"] = function(self, val)
|
yellowfive@57
|
107 self.label:SetJustifyH(val)
|
yellowfive@57
|
108 end,
|
yellowfive@57
|
109
|
yellowfive@57
|
110 ["SetWordWrap"] = function(self, enable)
|
yellowfive@57
|
111 self.label:SetWordWrap(enable)
|
yellowfive@57
|
112 updateSize(self)
|
yellowfive@57
|
113 end,
|
yellowfive@57
|
114
|
yellowfive@57
|
115 ["SetVisible"] = function(self, visible)
|
yellowfive@57
|
116 if visible then
|
yellowfive@57
|
117 self.frame:Show()
|
yellowfive@57
|
118 else
|
yellowfive@57
|
119 self.frame:Hide()
|
yellowfive@57
|
120 end
|
yellowfive@57
|
121 end
|
yellowfive@57
|
122 }
|
yellowfive@57
|
123
|
yellowfive@57
|
124 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
125 Constructor
|
yellowfive@57
|
126 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
127 local function Constructor()
|
yellowfive@57
|
128 local frame = CreateFrame("Frame", nil, UIParent)
|
yellowfive@57
|
129 frame:Hide()
|
yellowfive@57
|
130
|
yellowfive@57
|
131 frame:SetScript("OnEnter", frameOnEnter)
|
yellowfive@57
|
132 frame:SetScript("OnLeave", frameOnLeave)
|
yellowfive@57
|
133 frame:SetScript("OnMouseDown", frameOnMouseDown)
|
yellowfive@57
|
134 frame:SetScript("OnMouseUp", frameOnMouseUp)
|
yellowfive@57
|
135
|
yellowfive@57
|
136 local label = frame:CreateFontString(nil, "ARTWORK")
|
yellowfive@124
|
137 label:SetPoint("TOPLEFT")
|
yellowfive@57
|
138 label:SetFontObject(Amr.CreateFont("Regular", 16, Amr.Colors.Text))
|
yellowfive@57
|
139
|
yellowfive@57
|
140 -- create widget
|
yellowfive@57
|
141 local widget = {
|
yellowfive@57
|
142 label = label,
|
yellowfive@57
|
143 frame = frame,
|
yellowfive@57
|
144 type = Type
|
yellowfive@57
|
145 }
|
yellowfive@57
|
146 for method, func in pairs(methods) do
|
yellowfive@57
|
147 widget[method] = func
|
yellowfive@57
|
148 end
|
yellowfive@57
|
149
|
yellowfive@57
|
150 return AceGUI:RegisterAsWidget(widget)
|
yellowfive@57
|
151 end
|
yellowfive@57
|
152
|
yellowfive@57
|
153 AceGUI:RegisterWidgetType(Type, Constructor, Version)
|