drop down menu - Making this function infinitely nesting based off a table -
i solved problem make dropdown menu in world of warcraft off of table.
now need able nest far down user supplies. how this?
here function use:
local info = uidropdownmenu_createinfo() if level == 1 a,b in pairs(menulist) info.text = b[1] info.hasarrow = b[2] uidropdownmenu_addbutton(info, level) end elseif level == 2 a,b in pairs(menulist[uidropdownmenu_menu_value][3]) info.text = b info.func = onclick uidropdownmenu_addbutton(info, level) end end
here table example used:
testmenulist = {greetings = {"greetings", true, {"hi", "hello", "good day"}}, farewells = {"farewells", true, {"bye", "goodbye", "later"}}}
it can setup 2 levels down. first , submenus.
can me out?
here solution:
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 info = uidropdownmenu_createinfo() info.text = title info.istitle = true uidropdownmenu_addbutton(info, level) if level == 1 a,b in pairs(menulist) info = uidropdownmenu_createinfo() info.text = b[1] info.hasarrow = b[2] info.func = onclick if info.hasarrow _menulists[b[1]] = b[3] end uidropdownmenu_addbutton(info, level) end elseif level > 1 --print(#_menulists[uidropdownmenu_menu_value][2]) --for x=1, #_menulists[uidropdownmenu_menu_value] a,b in pairs(_menulists[uidropdownmenu_menu_value]) info = uidropdownmenu_createinfo() info.text = b[1] info.hasarrow = b[2] if info.hasarrow _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
here example of table used function:
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}}
Comments
Post a Comment