Thread Tools Display Modes
12-21-06, 01:25 PM   #1
Jaycyn
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 2
DropDown Menu re-use code

I have 2 drop down menus that contain the same table list. How would one go about 're-using' lua code to populate each dropdown and handle clicks.

Speaking generically...

in XML, in the UIDropDownMenuTemplate, in the <OnShow> I call MyDropDown_OnShow

MyDropDown_OnShow function calls UIDropDownMenu_Initialize and passes MyDropDown_Initialize function: this allows the dropdown to know it's init function

MyDropDown_Initialize populates the dropdown and sets info.function to MyDropDown_OnClick, so the dropdown knows what to do when an item is selected

MyDropDown_OnClick just gets what the user selected in the list and shows it in chat. (for testing purposes)

The problem I am running in to is differentiating which dropdown is making the calls. I thought I could put the drop down name (i.e. MyDropDown_Menu1 or MyDropDown_Menu2) in info.value via info.value = this, and then use that value (aka frame) when the OnClick does

local i = this:GetID(); --ID is the # of the selected item, 1, 2, 3 in the dropdown list.
UIDropDownMenu_SetSelectedID( this.value, i);

however, it appears that Initialize gets called twice: once when it it shown, which then sets info.value to MyDropDown_Menu2 (so far so good) but when you click the disclosure button to show the list, it gets called again, and this time this = MyDropDown_Menu2Button.

Can anyone suggest a solution?
  Reply With Quote
12-22-06, 07:24 AM   #2
Jaycyn
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 2
Solution

I answered my own question.

In UIDropDownMenu.lua at the bottom is a function that returns which drop down menu is currently open.

local currentDropDown = UIDropDownMenu_GetCurrentDropDown();

Once I know the current drop down, I can then populate/update each one as needed.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » DropDown Menu re-use 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