Thread Tools Display Modes
Prev Previous Post   Next Post Next
07/23/14, 03:08 PM   #8
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by zgrssd View Post
I think I get it. The template was not properly put into <GuiXml> and <Controls> Tags. Hence the template was never properly read and could not be found

After solving this issues and some minor issue with the retreival of data I have anotehr issue:
Nothing is shown in the window. I double checked by giving the lables text and putting d(row) into the code - it is executed and the items are created. They are just not shown.

I asume that I am adding them on a level too high or that something in my window is wrong.
Its because rows are not properly anchored to the window.

Try this code:
xml Code:
  1. <GuiXml>
  2.     <Controls>
  3.         <Control name="EventExplorerRow" virtual="true">
  4.             <Dimensions y="25"/>
  5.             <Controls>
  6.                 <Label name="$(parent)Id" font="ZoFontGame" horizontalAlignment="RIGHT">
  7.                     <Dimensions x="60"/>
  8.                     <Anchor point="LEFT" />
  9.                 </Label>
  10.                 <Label name="$(parent)Name" font="ZoFontGame">
  11.                     <Anchor point="LEFT" relativeTo="$(parent)Id" relativePoint="RIGHT" offsetX="20"/>
  12.                 </Label>
  13.             </Controls>
  14.         </Control>
  15.         <TopLevelControl name="EventExplorerWindow" mouseEnabled="true" movable="true" clampedToScreen="true" hidden="true">
  16.             <Dimensions x="760" y="650" />
  17.             <Anchor point="CENTER" />
  18.             <Controls>
  19.                 <Label name="$(parent)Title" inherits="ZO_WindowTitle" text="Event Explorer" />
  20.                 <Button name="$(parent)Close" inherits="ZO_CloseButton">
  21.                     <Anchor point="TOPRIGHT" offsetY="3" />
  22.                     <OnClicked>
  23.                         EventExplorerWindow:SetHidden(true)
  24.                     </OnClicked>
  25.                 </Button>
  26.                 <Control name="$(parent)Container" inherits="ZO_ScrollContainer">
  27.                     <Anchor point="TOPLEFT" offsetY="30" />
  28.                     <Anchor point="BOTTOMRIGHT" />
  29.                 </Control>
  30.                 <Backdrop name="$(parent)BG" inherits="ZO_DefaultBackdrop" />
  31.             </Controls>
  32.         </TopLevelControl>
  33.     </Controls>
  34. </GuiXml>

Lua Code:
  1. local LCM = LibStub("LibConstantMapper")
  2.  
  3. local dataList = {}
  4. local lastRow
  5.  
  6. --get the list of Events
  7. local Events = LCM:getDataByMapping("Events")
  8.  
  9. local function fillWindow()
  10.     for key, value in ipairs(Events) do
  11.         local row = CreateControlFromVirtual("$(parent)Row", EventExplorerWindowContainerScrollChild, "EventExplorerRow", key)
  12.         if key == 1 then
  13.             row:SetAnchor(TOPLEFT, EventExplorerWindowContainerScrollChild, TOPLEFT, 0, 0)
  14.         else
  15.             row:SetAnchor(TOP, lastRow, BOTTOM, 0, 0)
  16.         end
  17.         row:GetNamedChild("Id"):SetText(tostring(value.value))        
  18.         row:GetNamedChild("Name"):SetText(value.key)
  19.         lastRow = row        
  20.     end
  21. end
  22.  
  23. local function windowToggle()
  24.     EventExplorerWindow:SetHidden(not EventExplorerWindow:IsHidden())
  25. end
  26.  
  27. local function OnAddOnLoaded(eventID, AddonName)
  28.     if (AddonName~= "EventExplorer") then return end
  29.    
  30.     fillWindow()
  31.    
  32.     SLASH_COMMANDS["/eventexplo"] = windowToggle
  33. end
  34.  
  35. EVENT_MANAGER:RegisterForEvent("MyAddOn", EVENT_ADD_ON_LOADED, OnAddOnLoaded)

EDIT:
By the way list of events in your library contains global reference to EVENT_MANAGER.
Updated mapping:
lua Code:
  1. { mapping = "Events", pattern = "^EVENT_", exclude = "^EVENT_MANAGER"},

Last edited by Garkin : 07/23/14 at 03:11 PM. Reason: added LibConstantMapper note
  Reply With Quote
 

ESOUI » Developer Discussions » Lua/XML Help » Creating a whole bunch of Elements dynamic from code


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