Thread Tools Display Modes
11-28-14, 04:44 PM   #1
thebdc
A Murloc Raider
Join Date: Mar 2011
Posts: 5
Problem anchoring SecureActionButton to FontString

Hello there,

I'm trying to anchor a SecureActionButton to a FontString, but it doesn't seem to work - the SecureActionButton just doesn't show up at all. Here's an example:

Code:
local frame = CreateFrame("Frame", nil, UIParent)
frame:SetBackdrop({ bgFile = "Interface/BUTTONS/WHITE8X8" })
frame:SetBackdropColor(1, 0, 0, 0.5)
frame:SetPoint("LEFT")
frame:SetWidth(100)
frame:SetHeight(100)

local label = frame:CreateFontString(nil, "BACKGROUND", "GameFontHighlight")
label:SetText("Test")
label:SetPoint("TOPLEFT")

local button = CreateFrame("Button", nil, frame, "SecureActionButtonTemplate")
button:SetBackdrop({ bgFile = "Interface/BUTTONS/WHITE8X8" })
button:SetHeight(20)
button:SetWidth(80)
button:SetPoint("TOPLEFT", label, "BOTTOMLEFT")
button:SetScript("OnClick", function() print("Button was clicked!") end)
What I expect: there should be a white square (the button) below the text "Test". Anchoring to a Frame works, like replacing the line
Code:
button:SetPoint("TOPLEFT", label, "BOTTOMLEFT")
with
Code:
button:SetPoint("TOPLEFT", frame, "BOTTOMLEFT")
Will show the white square (the button) below the red frame. This only seems to happen when I inherit from SecureActionButtonTemplate. Removing that when creating the button lets me anchor the button the the FontString.

Is that some limitation of the SecureActionButton? If so, what's the best way around? Just to create another frame where the FontString is, and anchor to that frame?
  Reply With Quote
11-28-14, 07:21 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I would guess that this is because anything you parent a secure frame to becomes protected itself -- since a font string cannot be a protected object, you cannot parent a secure frame to a font string. If you were allowed to do that, then you could move the secure frame programmatically during combat by, say, anchoring the frame to the right end of the font string and then changing the contents of the fontstring to move the frame back and forth horizontally.

In your case, based on your example, I'd suggest you're actually working backwards -- you should be parenting the secure button to the containing frame, and parenting the font string to the button, since logically it is a label for the button, and therefore belongs to the button, not the button's parent container. Just use a vertical offset in your SetPoint call to move the button down to make room for the font string, then anchor the bottom of the font string to the top of the button.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-29-14, 04:58 AM   #3
thebdc
A Murloc Raider
Join Date: Mar 2011
Posts: 5
That explanation makes sense I guess. I tried your suggestion and it works fine. Here's the code, if anybody cares:

Code:
local frame = CreateFrame("Frame", nil, UIParent)
frame:SetBackdrop({ bgFile = "Interface/BUTTONS/WHITE8X8" })
frame:SetBackdropColor(1, 0, 0, 0.5)
frame:SetPoint("LEFT")
frame:SetWidth(100)
frame:SetHeight(100)

local button = CreateFrame("Button", nil, frame, "SecureActionButtonTemplate")
button:SetBackdrop({ bgFile = "Interface/BUTTONS/WHITE8X8" })
button:SetHeight(20)
button:SetWidth(80)
button:SetScript("OnClick", function() print("Button was clicked!") end)

local label = button:CreateFontString(nil, "BACKGROUND", "GameFontHighlight")
label:SetText("Test")

button:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, -label:GetStringHeight())
label:SetPoint("BOTTOMLEFT", button, "TOPLEFT")
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Problem anchoring SecureActionButton to FontString


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off