Thread: DropDown Menus
View Single Post
06-10-14, 06:40 PM   #10
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Nevermind I just got it off a random idea that happened to work.

For all of you to see and test here is the code:
Code:
function IOLib_CreateDropDown(parent, name, title, width, anchor, posX, posY, menuList, OnClick)
	local dropDown = CreateFrame("Button", name, parent, "UIDropDownMenuTemplate")
	--_G[name].list = menuList
	dropDown.list = menuList
	-- dropDown.Func = OnClick
	dropDown:ClearAllPoints()
	dropDown:SetPoint(anchor, posY, posX)
	
	local function initialize(self, level)
		local info = UIDropDownMenu_CreateInfo()
		
		if level ~= nil then
			info = UIDropDownMenu_CreateInfo()
			info.text = title
			info.isTitle = true
			UIDropDownMenu_AddButton(info, level)
			
			if level == 1 then
				
				for a,b in pairs(menuList) do
					info = UIDropDownMenu_CreateInfo()
					info.text = b[1]
					info.hasArrow = b[2]
					info.func = OnClick
					if info.hasArrow then _menuLists[b[1]] = b[3] end
					UIDropDownMenu_AddButton(info, level)
				end
				
			elseif level > 1 then
				--print(#_menuLists[UIDROPDOWNMENU_MENU_VALUE][2])
				--for x=1, #_menuLists[UIDROPDOWNMENU_MENU_VALUE] do
				for a,b in pairs(_menuLists[UIDROPDOWNMENU_MENU_VALUE]) do
					info = UIDropDownMenu_CreateInfo()
					info.text = b[1]
					info.hasArrow = b[2]
					if info.hasArrow then _menuLists[b[1]] = b[3] end
					info.func = OnClick
					UIDropDownMenu_AddButton(info, level)
				end
			end
			
			
		end
	end
	
	UIDropDownMenu_Initialize(dropDown, initialize)
	UIDropDownMenu_SetWidth(dropDown, width) -- Use in place of dropDown:SetWidth
	UIDropDownMenu_SetButtonWidth(dropDown, width + 24)
	UIDropDownMenu_SetSelectedID(dropDown, 1)
	UIDropDownMenu_JustifyText(dropDown, "LEFT")
	
	return dropDown
end
I used this table passed to it:
Code:
testMenuList = {{"Greetings", true, {{"Hi", true, {{"H", true, {{"Amazing", false, nil}}},{"i", false, nil}}},
										 {"Hello", false, nil}}},
					{"Farewells", true, {{"Bye", false, nil},
										 {"Goodbye", false, nil}}},
					{"Test", false, nil}}
Note: The ending level has to be enclosed in a {} as seen by the "Amazing" level. It stores all the level 3 entries of each table into a table. That had the chance for infinity and does have repeated information in the table but it works and I say thats fine by me. Anyone else can see about removing the useless cloned info if needed but for now it should be left as is.