Page 1 of 1
Interface buttons
Posted: 07 Sep 2012 08:55
by MartinA
I've been using the Interface buttons snippet and can adapt it a bit to suit so that buttons show either vertically or horizontally. But how do I get a block of buttons e.g. 3 across and 3 down?
Martin
ID:6474
Interface buttons
Posted: 07 Sep 2012 10:41
by Jane
You'll need to look at the IUP documentation.
http://www.tecgraf.puc-rio.br/iup/
As you'll need to add three v groups each with 3 buttons within an h group.
Interface buttons
Posted: 07 Sep 2012 10:57
by MartinA
Thanks, Jane. I'll explore that. I'm just trying to make quite a lot of buttons more manageable.
Martin
Interface buttons
Posted: 08 Sep 2012 09:54
by MartinA
I think I've got the principle of embedding boxes, but I'm working from your Interface Button snippet.
I don't understand where intArgNum comes from. So I can't work out how to split the button arguments into groups. i.e. with six button names sent to iupButtons I want to split them into two (or three) groups in separate vertical boxes. Does that make sense?
Martin
Interface buttons
Posted: 08 Sep 2012 12:29
by tatewise
intArgNum is a counter for the button name arguments, running from
1 consecutively upwards.
An alternative to passing in arguments is to provide the button names explicitly in the function and use two horizontal boxes.
Code: Select all
local intArgNum = 0
local iupBox1 = iup.hbox{homogeneous='YES'}
for intNum, strButton in ipairs({'Btn1','Btn2','Btn3'}) do
intArgNum = intArgNum + 1
local btnName = iup.button{title=strButton,expand='YES',padding='4',action=function() intButton=intArgNum return iup.CLOSE end}
iup.Append(iupBox1,btnName)
end
local iupBox2 = iup.hbox{homogeneous='YES'}
for intNum, strButton in ipairs({'Btn4','Btn5','Btn6'}) do
intArgNum = intArgNum + 1
local btnName = iup.button{title=strButton,expand='YES',padding='4',action=function() intButton=intArgNum return iup.CLOSE end}
iup.Append(iupBox2,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,iupBox1,iupBox2},dialogframe='YES',background='250 250 250',gap='8',margin='8x8'}
Or you can test the
intArgNum value:
Code: Select all
local iupBox1 = iup.hbox{homogeneous='YES'}
local iupBox2 = iup.hbox{homogeneous='YES'}
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}
if intArgNum < 4 then
iup.Append(iupBox1,btnName)
else
iup.Append(iupBox2,btnName)
end
end
-- Create dialogue and turn off resize, maximize, minimize, and menubox except Close button
local dialogue = iup.dialog{title=strTitle,iup.vbox{lblMessage,lblLineSep,iupBox1,iupBox2},dialogframe='YES',background='250 250 250',gap='8',margin='8x8'}
Interface buttons
Posted: 08 Sep 2012 12:51
by MartinA
Great, Mike, thanks. Your second version does just what I want.
Is there a variable generated for the actual number of buttons, so that I could use ,say, that variable over 2 rather than specifying the number 4? Not crucial but it would be nice.
Interface buttons
Posted: 08 Sep 2012 14:12
by tatewise
Yes, because arg is a table listing the ... arguments, then #arg is the number of button names in the table.
Thus #arg / 2 is half the number of button names.
Interface buttons
Posted: 08 Sep 2012 15:16
by MartinA
Excellent. Got it. I now understand better what that bit is doing. I found the iup info rather confusing.