Thread: Grid
View Single Post
08/28/14, 10:47 AM   #8
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Lua Code:
  1. pool = ZO_ControlPool:New(templateName, parentControl, namePrefix)
  2. pool:SetCustomFactoryBehavior(
  3.     function (control)
  4.         -- custom init called for each new control created (not for each Acquire!)
  5.     end)
  6. pool:SetCustomResetBehavior(
  7.     function (control)
  8.         -- custom cleanup called for each Release
  9.     end)
  10.  
  11. control, key = pool:AcquireObject()
  12. pool:ReleaseObject(key)
  13.  
  14. pool:ReleaseAllObjects()

templateName ... is the name of a virtual control in XML
parentControl ... optional parent to all controls created by the pool; if it's nil, GuiRoot will be their parent
namePrefix ... optional "prefix" to created controls' names

For example, if parentControl:GetName() == "GridContainer" and namePrefix == "Line", created child controls will be named "GridContainerLine1", "GridContainerLine2", etc. If namePrefix == nil, templateName will be used instead (which makes ugly long names, so I rather use prefix ).

You don't have to maintain a table of active objects unless you want to release them selectively. In this case I think you could just hide the parent control, and only rebuild the grid (ReleaseAllObjects and re-create) when settings change (screen resolution, grid spacing).

Last edited by merlight : 08/28/14 at 10:52 AM. Reason: added custom reset comment
  Reply With Quote