Thread Tools Display Modes
10-12-11, 08:00 AM   #1
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Few XML/LUA questions

Hello,

I have few questions I gathered, which I couldn't find answers to. I hope someone here will be able to assist me

1. I want to use local functions properly, in order to save memory.
If I'm declaring a local frame and having all my functions declared as myFrame:myFunc(), will they be local as well? Is it a good practice for saving memory?

2. I want to make a dropdown checkbutton list, which will have only one valid option at a time. Meaning, when I choose an option, the previous option will be unchecked. So I though of doing so using the initialize function, setting the "checked" flag. However, it seems to be updated only when I close and open the dropdown list. Until then, I get more than one option selected. How can I make a dropdown with one selected option which is not closed when selecting an option? I managed do both separately, but not together...

3. The dropdown list has a text that I can set using "UIDropDownMenu_SetText". How can I set the font and font size of this text? I coudn't find any function to do so.

Thanks in advance!
  Reply With Quote
10-12-11, 08:41 AM   #2
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
Originally Posted by Animor View Post
Hello,

I have few questions I gathered, which I couldn't find answers to. I hope someone here will be able to assist me

1. I want to use local functions properly, in order to save memory.
If I'm declaring a local frame and having all my functions declared as myFrame:myFunc(), will they be local as well? Is it a good practice for saving memory?

2. I want to make a dropdown checkbutton list, which will have only one valid option at a time. Meaning, when I choose an option, the previous option will be unchecked. So I though of doing so using the initialize function, setting the "checked" flag. However, it seems to be updated only when I close and open the dropdown list. Until then, I get more than one option selected. How can I make a dropdown with one selected option which is not closed when selecting an option? I managed do both separately, but not together...
1. It has nothing to do with "saving memory", since your function will use memory, regardless of being local or not. It is a matter of "good programming style" and scope. You don't want to use a global (not local) loop-variable i, cause many programmers do it and you will taint each other, if it is not local (or might taint, at least).
And yes, creating functions as the child of a local frame will make them local aswell, technically.

2. Just write a custom functions to uncheck all other options.
__________________
  Reply With Quote
10-12-11, 12:28 PM   #3
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Thank you for you answer.

1. I've encountered an issue trying to call myFrame:Myfunc() from within XML onLoad script of a parent xmlframe (a different frame). It did work ok for a check-button onClick script, though. Something I'm missing here?

2. I couldn't find a way to access the buttons and uncheck them from a function that is not the initialize function. How can I access them and modify the checked field?
  Reply With Quote
10-12-11, 03:45 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,336
Originally Posted by Mischback View Post
... You don't want to use a global (not local) loop-variable i, cause many programmers do it and you will taint each other, if it is not local (or might taint, at least). ...
This depends on which loop statement you use. Each one has their tricks and specific uses.


Code:
while condition do
-- Loop code here
end
condition is checked at the beginning of each loop and is outside the scope of the loop. Locals inside the loop won't be used.

Code:
repeat
-- Loop code here
until condition
condition is checked after each loop and is contained inside the scope of the loop. Locals inside the loop are used.

Code:
for i=1,10 do
-- Loop code here
end
i is created as a local inside the scope of the loop. Conditions are checked at the beginning of the loop.





Originally Posted by Animor View Post
1. I've encountered an issue trying to call myFrame:Myfunc() from within XML onLoad script of a parent xmlframe (a different frame). It did work ok for a check-button onClick script, though. Something I'm missing here?

2. I couldn't find a way to access the buttons and uncheck them from a function that is not the initialize function. How can I access them and modify the checked field?
Frames defined in XML need to either have a name that places them in a global variable sharing the same name or have the parentKey attribute set so it can be accessed through its parent.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-12-11, 11:49 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Animor View Post
3. The dropdown list has a text that I can set using "UIDropDownMenu_SetText". How can I set the font and font size of this text? I coudn't find any function to do so.
There is no API for changing the font of dropdown menu buttons. You would need to study Blizzard's template code to learn the structure of the buttons and how to programatically identify which buttons are being displayed on an open menu. Then, each time your dropdown was shown, you would need to change the font of all of the buttons being displayed on it, and each time your dropdown was hidden, you would need to reset the fonts for all of those buttons (otherwise your font changes will show up randomly in other dropdowns, since addons that do not change the fonts will not expect to have to change it back).

You may be better off writing your own dropdown menu widget; that's what I did for my addons where I wanted to have scrollable dropdown menus, or custom fonts/textures in the dropdown menu. See my addon oUF_Phanx for examples if you're interested.
  Reply With Quote
10-14-11, 03:14 PM   #6
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Thanks

Perhaps there is a common lib for dropdown list with more control? I don't want to write that myself, will take me too long I'm afraid.

Does someone know the answer to my other question, about choosing from dropdown list while keeping it open?
  Reply With Quote
10-14-11, 03:30 PM   #7
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by Animor View Post
Thanks

Perhaps there is a common lib for dropdown list with more control? I don't want to write that myself, will take me too long I'm afraid.

Does someone know the answer to my other question, about choosing from dropdown list while keeping it open?
The keepShownOnClick arg will allow that.

http://www.wowwiki.com/UI_Object_UID...The_info_table
  Reply With Quote
10-14-11, 04:38 PM   #8
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Xinhuan has written a good guide for using UIDropDownMenus.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
10-14-11, 08:39 PM   #9
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Originally Posted by Nibelheim View Post
The keepShownOnClick arg will allow that.

http://www.wowwiki.com/UI_Object_UID...The_info_table
I've read that, and I've also read the link that Torhal gave. keepShownOnClick is the way to keep the list open. but as I wrote at my original post, the problem is not keeping it open. The problem is unchecking all but one option while the list remains open.
  Reply With Quote
10-14-11, 09:25 PM   #10
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by Animor View Post
I've read that, and I've also read the link that Torhal gave. keepShownOnClick is the way to keep the list open. but as I wrote at my original post, the problem is not keeping it open. The problem is unchecking all but one option while the list remains open.
Ahh. Not sure if it can be done. Might have to make your own DropDownMenu.
  Reply With Quote
10-17-11, 07:15 AM   #11
SaraFdS
A Fallenroot Satyr
 
SaraFdS's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 24
Originally Posted by Animor View Post
2. I want to make a dropdown checkbutton list, which will have only one valid option at a time. Meaning, when I choose an option, the previous option will be unchecked. So I though of doing so using the initialize function, setting the "checked" flag. However, it seems to be updated only when I close and open the dropdown list. Until then, I get more than one option selected. How can I make a dropdown with one selected option which is not closed when selecting an option? I managed do both separately, but not together...
Isn't it as simple as combining
Code:
isNotRadio = false
and
Code:
keepShownOnClick = true
?
__________________
Sará the Insane
  Reply With Quote
10-17-11, 09:14 AM   #12
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Unfortunately, no...
and btw, isNotRadio = false is the default.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Few XML/LUA questions


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