This IUP GUI dialogue is similar to the predefined iup.Alarm dialogue but allows an unlimited number of buttons.
Just be aware that you could end up with a very wide or tall dialogue.
It will return the button number, or 0 if Close is pressed, just like iup.Alarm.
The strBoxType parameter determines whether the buttons appear horizontally (“H”) or vertically (“V”).
Requires: iuplua
Code
-
--[[ @Title: User Interface Buttons Snippet @Author: Mike Tate / Jane Taubman @LastUpdated: May 2012 @Version: 1.4 @Description: GUI dialogue for multiple buttons @params strTitle: Title of Message Box strMessage: Message to show above buttons strBoxType: Either "H" for Horizontal buttons or "V" for Vertical ones. ... : All other parameters will be treated as button titles. ]] function iupButtons(strTitle,strMessage,strBoxType,...) local intButton = 0 -- Returned value if X Close button is used -- Create the GUI labels and buttons local lblMessage = iup.label{title=strMessage,expand="YES"} local lblLineSep = iup.label{separator="HORIZONTAL"} local iupBox = iup.hbox{homogeneous="YES"} if strBoxType == "V" then iupBox = iup.vbox{homogeneous="YES"} end for intArgNum, strButton in ipairs(arg) do local btnName = iup.button{title=strButton,expand="YES",padding="4", action=function() intButton=intArgNum return iup.CLOSE end} iup.Append(iupBox,btnName) end -- Create dialogue and turn off resize, maximize, minimize, and menubox except Close button local dialogue = iup.dialog{title=strTitle,iup.vbox{lblMessage,lblLineSep,iupBox}, dialogframe="YES",background="250 250 250",gap="8",margin="8x8"} dialogue:show() if (iup.MainLoopLevel()==0) then iup.MainLoop() end dialogue:destroy() return intButton end -- function iupButtons
Usage
-
intButton = iupButtons("Multi-Button Title","Multi-Button Message","V","Button One","Button Two","Button Three","Button Four","Button Five") print("Button "..intButton.." Pressed")