Thread Tools Display Modes
05-27-09, 09:54 AM   #1
Crowfeather
A Fallenroot Satyr
 
Crowfeather's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2008
Posts: 28
AddOn beginner questions

Iīm new to coding (just started writing my first AddOn in the past few weeks). In my AddOn I want the user to be able to disable some frames if he/she doesnīt need them anymore. Now Iīm wondering how do I remove frames efficiently (eg. not just hiding them) once theyīve been created.

example:
Code:
-- frame creation
FS.ttlMover = CreateFrame("Frame","ttlMover", UIParent)
(...) 
FS.ttlFrame = CreateFrame("Frame", "ttlFrame", FS.ttlMover)
(...)
FS.ttlFrame.text = FS.ttlFrame:CreateFontString("ttlFrameText", "ARTWORK", "GameFontNormal")

-- supposed frame removal (doesnīt work this way)
FS.ttlFrame = nil
FS.ttlMover = nil
The first frame created contains the actual frame and is used to move the second frame even when thereīs no text in it at that moment. Thereīre more lines between the CreateFrame commands ofc, if theyīre relevant for my question Iīll gladly post them too.

Just setting them to nil doesnīt remove them from my UI and if I create another frame with the same name Iīm getting a second frame.

Another thing I wanted to ask for a while - is there an easy way to make frames "dock" (as in sticking togather if you drag them close to each other) with each other or would I have to hardcode that behavior myself?

Last edited by Crowfeather : 05-29-09 at 05:09 AM.
  Reply With Quote
05-27-09, 10:08 AM   #2
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
Frames can't be deleted as they are not garbage-collected. You could only hide it and remove all references to it - but they won't remove the frame, rather making it inaccessible.

If you want to create and destroy lots of frames at different times, you should write some kind of frame-recycling method, so that older ones will be used once more instead of just lying around somewhere.

Concerning the sticky frames, I think there are 2-3 different libraries which can handle that, but I never tested anything around it. If I remember right, one is called LibStickyFrames and there's also FlyPaper from Tuller which he uses in Dominos, for example.
__________________
Ŧ Website | GitHub ŧ

Oh hai!
  Reply With Quote
05-27-09, 10:14 AM   #3
Crowfeather
A Fallenroot Satyr
 
Crowfeather's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2008
Posts: 28
Well I guess it ainīt so many frames and if I canīt really remove them itīs propably better to just hide them so I can reuse them if needed. Thanks for the quick answer anyway.
  Reply With Quote
05-27-09, 10:22 AM   #4
Gimbli
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2009
Posts: 15
I'd imagine after whatever process that renders the reference to your frame(s) as 'nil', that when you want to use that frame again, you're redefining the frame as, for example:

Code:
FS.ttlMover = CreateFrame("Frame","ttlMover", UIParent)
As was stated, there is no way to remove a frame once it is created without a reload of the user interface to rebuild based on "new" conditions, but with use of :Hide() and :Show() for deactivation/activation methods instead of using or defining the frame as 'nil', you avoid problematic recreation of frames.

If you have functions you want to recognize the frame as non-active to avoid referencing them for unnecessary changes/actions/etc., simply do something like this:

Code:
local ttlMoverActive
if ( not FS.ttlMover ) then FS.ttlMover = CreateFrame("Frame","ttlMover", UIParent) end

local function ttlMoverFunction()
     if ( ttlMoverActive ) then -- Check true/false, true being active
          -- Do active stuff here
     else
          -- Action taken if inactive
     end
end
The "if ( not FS.ttlMover ) then" segment ensures that if it's "not" created, it continues making the frame. However, if it "is" already designated as a frame (which would mean it's not 'nil'), it will not recreate the frame.

You use the local ttMoverActive outside of the functions as a Red/Green light using true/false statements to indicate it's active state. You only need a way to govern this, for instance, set it to 'true' on an OnLoad function/event, and then when it is disabled, have that function change the local to 'false'. If you want the frame to retain it's state through logout/logins, you need to save that true/false local to a saved variable instead (ie. yoursavedvar.db.ttlMoverActive).

Using t/f handlers for active/inactive elements is an easy way to get around having to build hefty frame recycling methods. And if done in locals instead of globals, it's fairly light on usage.
  Reply With Quote
05-29-09, 12:50 AM   #5
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Technically you can get rid of a frame, but from my experiences it's touchy and should only be used with your own frames.

Code:
frame = nil
I used this while building my GUIs in-game and wanted to reset the frame without having to keep doing a /reload. It's crude, but it works.

EDIT: Here's a quick snippet that I use for CFM's config frame to determine if it should be built or show based on whether it's already been made:

Code:
function CFM_GUI()
	if CFM_Config then  -- check to see if the frame exists already
		CFM_Config:Show()  -- show it
	else
        -- start creating the frame from scratch
        end
end
EDIT2: I see someone already talked about niling a frame. Should really fully read stuff instead of just skimming.

Last edited by Sythalin : 05-29-09 at 01:00 AM.
  Reply With Quote
05-29-09, 05:08 AM   #6
Crowfeather
A Fallenroot Satyr
 
Crowfeather's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2008
Posts: 28
Thanks for all the replies. After Cargors answer I figured as much and changed my code accordingly. It looks almost like the code Gimbli posted now... well I guess I should make much more use of local variables but thatīs another story.

One thing Iīm wondering about now is how to "red out" buttons (the way they look when you canīt use the specific action). When I couldnīt find a "native" way to display a texture in red I resorted to slaping a translucent, red frame right on top of it. Is there any way to do this in a more beutiful way?

I guess I should start a new thread because the problrem really isnīt related to removing frames, but I donīt want to keep spawning new threads for each and every question I have.

edit: I changed the topic name to something more appropriate.
edit2: Looks like changing the topic isnīt the same thing as changing the thread title

Last edited by Crowfeather : 05-29-09 at 05:54 AM.
  Reply With Quote
05-29-09, 05:24 AM   #7
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
myTexture:SetVertexColor(1, 0, 0) should do the trick.

WoWWIKI: API_LayeredRegion_SetVertexColor
__________________
Ŧ Website | GitHub ŧ

Oh hai!

Last edited by xConStruct : 05-29-09 at 05:25 AM. Reason: typo ;)
  Reply With Quote
05-29-09, 05:52 AM   #8
Crowfeather
A Fallenroot Satyr
 
Crowfeather's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2008
Posts: 28
Thanks again, will try it as soon as Iīm back home.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How do I remove frames


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