I have some issues with incorrect zero returns from frame:GetWidth(). I set the width of the frame in question by using SetPoint()
Lua Code:
local AddOverlay = function(self, unit)
local overlay = CreateFrame("Frame", self:GetName().."_Overlay", self.Portrait)
overlay:SetPoint("TOPLEFT", self.Portrait, 0, 1)
overlay:SetPoint("BOTTOMRIGHT", self.Portrait, 0, -1)
local tex = overlay:CreateTexture(nil, "BORDER")
tex:SetAllPoints()
tex:SetTexture(ns.media.OVERLAY)
tex:SetVertexColor(0.1, 0.1, 0.1, 0.75)
if (unit == "target") then
self.CCWarn = tex
end
self.Overlay = overlay
end
I then position some elements on the overlay and need its width to size them appropriately
Lua Code:
local AddComboPointsBar = function(self, height, spacing)
local comboPoints = {}
local maxCPoints = MAX_COMBO_POINTS
local width = self.Overlay:GetWidth()
width = (width - maxCPoints * spacing - spacing) / maxCPoints -- factoring causes rounding issues?
spacing = width + spacing
for i = 1, maxCPoints do
local cPoint = self.Overlay:CreateTexture("oUF_Rain_ComboPoint_"..i, "OVERLAY")
cPoint:SetSize(width, height)
cPoint:SetPoint("BOTTOMLEFT", (i - 1) * spacing + 1, 1)
local color = ns.colors.cpoints[i]
cPoint:SetTexture(color[1], color[2], color[3])
comboPoints[i] = cPoint
end
self.CPoints = comboPoints
end
Here self.Overlay:GetWidth() returns 0. Further self.Overlay:GetPoint(1) returns just
TOPLEFT, but self.Overlay:GetPoint(2) returns
BOTTOMRIGHT, table: 01234, BOTTOMRIGHT, 0, -1 as expected. I'm sure I added self.Overlay before adding the combo points as otherwise I would get errors about self.Overlay being unknown. GetLeft(), GetRight() and GetSize() also return 0.
The frames get created at PLAYER_ENTERING_WORLD (the code is from my oUF layout) if this plays a role. /dump oUF_Rain_Player_Overlay:GetWidth() from in-game returns correct values.
So is this some limitation of GetWidth() or is something wrong on my side?