Quantcast
Remove/destroy controls? - ESOUI
Thread Tools Display Modes
07/21/15, 01:14 AM   #1
@AlphaLemming
 
@AlphaLemming's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 122
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.
__________________
Andral Gwain Remus - Ebonheart Pact - EU
Addons: AlphaGear, CraftStore
  Reply With Quote
07/21/15, 02:06 AM   #2
Fyrakin
 
Fyrakin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 129
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.
  Reply With Quote
07/21/15, 02:18 AM   #3
@AlphaLemming
 
@AlphaLemming's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 122
Hmm, thanks Fyrakin.
__________________
Andral Gwain Remus - Ebonheart Pact - EU
Addons: AlphaGear, CraftStore
  Reply With Quote
07/21/15, 03:58 AM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,490
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:
--[[

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.
--]]
__________________
https://www.imperialtradingcompany.eu/ - My Addons - The Vault (Early updates and experimental projects) - My patreon - My blog
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.

Last edited by sirinsidiator : 07/21/15 at 04:01 AM.
  Reply With Quote
07/21/15, 05:56 AM   #5
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
The templated control case is further simplified by ZO_ControlPool subclass, see e.g. http://esodata.uesp.net/100011/src/i....lua.html#1000
  Reply With Quote
07/21/15, 05:58 AM   #6
@AlphaLemming
 
@AlphaLemming's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 122
Thanks all, that will help.
__________________
Andral Gwain Remus - Ebonheart Pact - EU
Addons: AlphaGear, CraftStore
  Reply With Quote
04/27/21, 12:36 AM   #7
Mipps
Join Date: Sep 2020
Posts: 10
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?
  Reply With Quote
04/27/21, 04:13 AM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,490
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.
__________________
https://www.imperialtradingcompany.eu/ - My Addons - The Vault (Early updates and experimental projects) - My patreon - My blog
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote
04/27/21, 06:52 AM   #9
Mipps
Join Date: Sep 2020
Posts: 10
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

Last edited by Mipps : 04/27/21 at 08:07 AM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Remove/destroy controls?

Thread Tools
Display Modes

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