ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Remove/destroy controls? (https://www.esoui.com/forums/showthread.php?t=4915)

@AlphaLemming 07/21/15 01:14 AM

Remove/destroy controls?
 
Is there any way to remove/destroy created controls in a save way?

After a animation i dont need them anymore and i do not want to spam the ui with hundreds of useless controls.

Fyrakin 07/21/15 02:06 AM

No, there is no way to remove any control, so if you don't need one you just hide it and remove anchors. If you need to show it again, don't create another, but re-use the one you've made before. Controls clear when you /reloadui, or restart client.

@AlphaLemming 07/21/15 02:18 AM

Hmm, thanks Fyrakin.

sirinsidiator 07/21/15 03:58 AM

Best way to handle a situation where you create a predictable amount of controls that you don't need all the time is using a ZO_ObjectPool.
You specify a Factory function that returns the object that is used and a Reset function that is called whenever an object is released.

Lua Code:
  1. local function EntryFactory(pool)
  2.   local name = "MyEntry" .. pool:GetNextControlId()
  3.   local container = parentWindow:CreateControl(name, CT_CONTROL)
  4.  
  5.   local labelA = container:CreateControl("$(parent)Level", CT_LABEL)
  6.   labelA :SetFont("ZoFontGameMedium")
  7.   container.labelA = labelA
  8.  
  9.   return container
  10. end
  11.  
  12. local function ResetEntry(entry)
  13.   entry:SetHidden(true)
  14.   entry:ClearAnchors()
  15. end
  16.  
  17. local pool = ZO_ObjectPool:New(EntryFactory, ResetEntry)

When you need a new object you call AquireObject like this:
Lua Code:
  1. local entry, key = pool:AcquireObject()
  2. entry:SetHidden(false)
  3. entry:SetAnchor(...)
  4. ...

And once you are finished you can release it via the key:
Lua Code:
  1. pool:ReleaseObject(key)

If you don't care about specific objects you can also just call ReleaseAllObjects and reset them all at once:
Lua Code:
  1. pool:ReleaseAllObjects()

EDIT: The comment in the zo_objectpool.lua is also quite interesting:
Quote:

--[[

A generic pool to contain "active" and "free" objects. Active objects
are typically objects which:
1. Have a relatively high construction cost
2. Are not lightweight enough to create many of them at once
3. Tend to be reused as dynamic elements of a larger container.

The pool should "rapidly" reach a high-water mark of contained objects
which should flow between active and free states on a regular basis.

Ideal uses of the ZO_ObjectPool would be to contain objects such as:
1. Scrolling combat text
2. Tracked quests
3. Buff icons

The pools are not intended to be used to track a dynamic set of
contained objects whose membership grows to a predetermined size.
As such, do NOT use the pool to track:
1. Chat filters
2. Inventory slots
3. Action buttons (unless creating something like AutoBar)

A common usage pattern is instantiating templated controls. To facilitate this
without bloating your own code you should use ZO_ObjectPool_CreateControl which has
been written here as a convenience. It creates a control named "template"..id where
id is an arbitrary value that will not conflict with other generated id's.

If your system depends on having well-known names for controls, you should not use the
convenience function.
--]]

merlight 07/21/15 05:56 AM

The templated control case is further simplified by ZO_ControlPool subclass, see e.g. http://esodata.uesp.net/100011/src/i....lua.html#1000

@AlphaLemming 07/21/15 05:58 AM

Thanks all, that will help.

Mipps 04/27/21 12:36 AM

I tried to recreate the example from sirinsidiator but can't get the label to show up ingame

following adjustments have been made:

in EntryFactory:
- local container = GuiRoot:CreateControl(name, CT_CONTROL)
- labelA:SetText("this is the label")

after creating new object:
- entry:SetHidden(false)
entry:SetAnchor(CENTER, parentControl, CENTER,0, 0 )

could some one point me into a direction?

sirinsidiator 04/27/21 04:13 AM

This example requires a bit of background knowledge. If you are new to addon development, you should try to look up some of the tutorials on the wiki instead. The SimpleNotebook Tutorial uses control pools in part 7.

Mipps 04/27/21 06:52 AM

I wouldn't call me "new" to addon development:
I have created several own addons (for example: cooldown tracker, combatlog related stuf, etc...)

now I wanted to go the next step and create stuff dynamically...
- I could't get either your example nor the example from the tutorial (yes I looked this up before posting here orginally!!) to work



edit: managed to solve it by myself ;)


All times are GMT -6. The time now is 05:02 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI