Delete a control
Hi,
I create label controls dynamically and they are zone based. Whenever I enter a new zone, I will create new label controls to add to my window, but I need to delete the previous zone's label controls first. It's been a long weekend, and I am new to both LUA and AddOns, but for the life of me I can't figure out how to delete the previous zone's label controls. Thanks |
Don't continuously create more and more new labels. Reuse the one you have. ;)
|
Quote:
It's just the way I was taught how to code, a long, long time ago. Allocate the resources when you need them, and get rid of those resources when you don't. If I need 20 labels for a particular zone based on the user options, and then go to another zone, and only need 4, I am not in the habit of keeping 16 controls around and just hiding them if I am not using them. I know I can do it that way, I just prefer not to. I was just wondering if there was a way to delete controls, that's all. |
Would set control to "nil" do the job?
myControl = nil |
It's not documented in the wiki but it looks like what you need is the ZO_ControlPool.
Use \zgoo and take a look at that table to see how it works. You can pass a virtual template to it as well. An example of it in use is in both my Gatherer addon as well as Shinni's HarvestMap addon and the CustomCompassPins library addon. Take a browse through those and see if you can see how it will work in your situation. As a taster, this is a portion of the control pool class in action in my addon. Half of the functionality is dealt with behind the scenes by ESO's ControlPool class but there are a few classes based off of it like ZO_MapPin if I remember rightly, although I couldn't use that sub class myself so stuck with the control pool for functionality. In the New() function the XRGACompassPin is my template control to use for this class and ZO_CompassContainer the parent. The "Pin" I suspect is a suffix to the internally generated control name which then has a number added to it. This last info is based on the one error I received that implied the generated pin control ended with Pin01. Lua Code:
Once something similar to the above is set up a simple call to the following will allow you to use it: local compassPinManager = CompassPinManager:New() Then all you will need to use is the compassPinManager to work on a manager instance that will handle all objects of that 'type'. As you can see there are calls to AcquireObject and ReleaseObject. These will work behind the scenes to release and locate the next available object to use. There are probably more functions that can be customised as needed but I didn't need to use them all so I didn't use them. If you are used to release and recreate you may be able to figure this functionality out pretty quickly based on the function names. Hopefully this will help you start your research off. |
Quote:
Thanks for the suggestion |
Quote:
|
Quote:
|
Yep. The pool will keep track of how many controls are in use and only create new ones when you need them. If you don't need a control and release it, it goes back into the pool for you to use later.
You cannot destroy a control once created. You can nil out any reference to it, and it will eventually be picked up by the garbage collector, but reusing your controls is the best way to do this. Reduce, Reuse, Recycle. ;) |
This is the thread where I learned :)
http://www.esoui.com/forums/showthread.php?t=143 |
All times are GMT -6. The time now is 11:01 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI