rearrange stuff, import config
[QuestHelper.git] / libs / AceGUI-3.0 / widgets / AceGUIWidget-Label.lua
blob538faf06d9dd7ba865f42011313f95816566f24c
1 local AceGUI = LibStub("AceGUI-3.0")
3 -- Lua APIs
4 local max, select = math.max, select
6 -- WoW APIs
7 local CreateFrame, UIParent = CreateFrame, UIParent
9 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
10 -- List them here for Mikk's FindGlobals script
11 -- GLOBALS: GameFontHighlightSmall
13 --------------------------
14 -- Label --
15 --------------------------
17 local Type = "Label"
18 local Version = 12
20 local function OnAcquire(self)
21 self:SetHeight(18)
22 self:SetWidth(200)
23 self:SetText("")
24 self:SetImage(nil)
25 self:SetImageSize(16, 16)
26 self:SetColor()
27 self:SetFontObject()
28 end
30 local function OnRelease(self)
31 self.frame:ClearAllPoints()
32 self.frame:Hide()
33 end
35 local function UpdateImageAnchor(self)
36 local width = self.frame.width or self.frame:GetWidth() or 0
37 local image = self.image
38 local label = self.label
39 local frame = self.frame
40 local height
42 label:ClearAllPoints()
43 image:ClearAllPoints()
45 if self.imageshown then
46 local imagewidth = image:GetWidth()
47 if (width - imagewidth) < 200 or (label:GetText() or "") == "" then
48 --image goes on top centered when less than 200 width for the text, or if there is no text
49 image:SetPoint("TOP",frame,"TOP",0,0)
50 label:SetPoint("TOP",image,"BOTTOM",0,0)
51 label:SetPoint("LEFT",frame,"LEFT",0,0)
52 label:SetWidth(width)
53 height = image:GetHeight() + label:GetHeight()
54 else
55 --image on the left
56 image:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
57 label:SetPoint("TOPLEFT",image,"TOPRIGHT",4,0)
58 label:SetWidth(width - imagewidth)
59 height = max(image:GetHeight(), label:GetHeight())
60 end
61 else
62 --no image shown
63 label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
64 label:SetWidth(width)
65 height = self.label:GetHeight()
66 end
68 self.resizing = true
69 self.frame:SetHeight(height)
70 self.frame.height = height
71 self.resizing = nil
72 end
74 local function SetText(self, text)
75 self.label:SetText(text or "")
76 UpdateImageAnchor(self)
77 end
79 local function SetColor(self, r, g, b)
80 if not (r and g and b) then
81 r, g, b = 1, 1, 1
82 end
83 self.label:SetVertexColor(r, g, b)
84 end
86 local function OnWidthSet(self, width)
87 if self.resizing then return end
88 UpdateImageAnchor(self)
89 end
91 local function SetImage(self, path, ...)
92 local image = self.image
93 image:SetTexture(path)
95 if image:GetTexture() then
96 self.imageshown = true
97 local n = select('#', ...)
98 if n == 4 or n == 8 then
99 image:SetTexCoord(...)
100 else
101 image:SetTexCoord(0, 1, 0, 1)
103 else
104 self.imageshown = nil
106 UpdateImageAnchor(self)
109 local function SetFont(self, font, height, flags)
110 self.label:SetFont(font, height, flags)
113 local function SetFontObject(self, font)
114 self.label:SetFontObject(font or GameFontHighlightSmall)
117 local function SetImageSize(self, width, height)
118 self.image:SetWidth(width)
119 self.image:SetHeight(height)
120 UpdateImageAnchor(self)
123 local function Constructor()
124 local frame = CreateFrame("Frame",nil,UIParent)
125 local self = {}
126 self.type = Type
128 self.OnRelease = OnRelease
129 self.OnAcquire = OnAcquire
130 self.SetText = SetText
131 self.SetColor = SetColor
132 self.frame = frame
133 self.OnWidthSet = OnWidthSet
134 self.SetImage = SetImage
135 self.SetImageSize = SetImageSize
136 self.SetFont = SetFont
137 self.SetFontObject = SetFontObject
138 frame.obj = self
140 frame:SetHeight(18)
141 frame:SetWidth(200)
142 local label = frame:CreateFontString(nil,"BACKGROUND","GameFontHighlightSmall")
143 label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
144 label:SetWidth(200)
145 label:SetJustifyH("LEFT")
146 label:SetJustifyV("TOP")
147 self.label = label
149 local image = frame:CreateTexture(nil,"BACKGROUND")
150 self.image = image
152 AceGUI:RegisterAsWidget(self)
153 return self
156 AceGUI:RegisterWidgetType(Type,Constructor,Version)