Thread Tools Display Modes
05/02/14, 05:49 PM   #1
NickK
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 10
CreateControlFromVirtual -- help

Once again i need help. I'm trying to dynamically create labels and so far nothing i tried worked. I read the part "Is there a way to dynamically create controls like buttons or labels?" on Addon Quick Questions on wiki but i can't figure out what i am doing wrong.

First i copy/pasted the xml from the wiki and i removed the button while changing the name of the label and adding virtual = "true", but i was getting the error "CreateControlFromVirtual Failed". After messing around and trying different things (while still getting the failed message) i decided to copy paste and use what wiki had as is, without changing anything, only to find out that i was getting the same error again.

This is the xml (same as wiki):
Code:
<Button name="DynamicButton" virtual="true" text="Click">
    <Controls>
        <Label name="$(parent)InnerLabel" text="Label" font="ZoFontGame">
            <AnchorFill/>
        </Label>
    </Controls>
</Button>
And this is the lua:
Lua Code:
  1. function OnLoad(eventCode, name)
  2. for i = 1, 10 do
  3.     local dynamicControl = CreateControlFromVirtual("DynamicButton", ZO_FriendsListList, "DynamicButton", i)
  4. end
  5.  
  6. DynamicButton2:SetText("2")
  7.  
  8.  
  9. end

The only difference is that i added a TopLevelControl which is the ZO_FriendsListList.

What am i doing wrong here?

I also checked around in the forum and i found that Wykkyd managed to create a dynamicly dropdown menu using WINDOW_MANAGER only, i tried to do it with WINDOW_MANAGER as well but it didn't work ether.

Thanks for your help.
  Reply With Quote
05/02/14, 07:53 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Well, your button template does not have a size, for starters. It also doesn't have a texture, if you wanted it to look like anything.
  Reply With Quote
05/03/14, 11:46 AM   #3
ingeniousclown
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 122
Originally Posted by Seerah View Post
Well, your button template does not have a size, for starters. It also doesn't have a texture, if you wanted it to look like anything.
Buttons don't need textures if they have text. For a long time, Grid View used a text-only button until I got around to changing it to an icon.
  Reply With Quote
05/03/14, 12:26 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
like I said...

Originally Posted by Seerah View Post
if you wanted it to look like anything.
  Reply With Quote
05/19/14, 04:22 AM   #5
Loaf
Join Date: May 2014
Posts: 4
Hi, had same issue with my own dynamically created buttons. Found from Zgoo that "i" was not being appended to the name how it was supposed to from wiki, so buttons were all "DynamicButton". Found I had to do: (obviously without the "ZO_FriendsListList" bit!)
Code:
for i = 1, 10 do
    local dynamicControl = CreateControlFromVirtual("DynamicButton" .. i, ZO_FriendsListList, "DynamicButton", i)
end
(also the "i" at the end could be omitted, seemed to do nothing!)
Buttons were then created with no errors and with differing names as they were supposed to.

Also I found that "DynamicButton2:SetText("2")" didn't change the label I had on the button. Changing the XML; removing the label part fixed it.
Code:
<Button name="DynamicButton" virtual="true" text="Click">
</Button>
Hope any of that helps.
  Reply With Quote
05/19/14, 05:42 AM   #6
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Loaf View Post
Hi, had same issue with my own dynamically created buttons. Found from Zgoo that "i" was not being appended to the name how it was supposed to from wiki, so buttons were all "DynamicButton". Found I had to do: (obviously without the "ZO_FriendsListList" bit!)
Code:
for i = 1, 10 do
    local dynamicControl = CreateControlFromVirtual("DynamicButton" .. i, ZO_FriendsListList, "DynamicButton", i)
end
(also the "i" at the end could be omitted, seemed to do nothing!)
Buttons were then created with no errors and with differing names as they were supposed to.

Also I found that "DynamicButton2:SetText("2")" didn't change the label I had on the button. Changing the XML; removing the label part fixed it.
Code:
<Button name="DynamicButton" virtual="true" text="Click">
</Button>
Hope any of that helps.
Suffix is defined in global function CreateControlFromVirtual(...), so if you use this function it works just fine.
Please do not confuse that function with WINDOW_MANAGER:CreateControlFromVirtual(...).


EDIT: As to the original question I'd try to use default template instead of custom (this code works for me):
lua Code:
  1. for i, row in pairs(ZO_FriendsListList.activeControls) do
  2.    local button = CreateControlFromVirtual("DynamicButton", ZO_FriendsListList, "ZO_DefaultTextButton", i)
  3.    button:SetAnchor(RIGHT, row, LEFT, 50, 0)
  4.    button:SetText(tostring(i))
  5. end

Last edited by Garkin : 05/19/14 at 06:21 AM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » CreateControlFromVirtual -- help


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