User interface 如何在主窗口中显示声明为vbox/hbox的数组?
我正在创建一个函数,该函数应该在IUP for Lua中执行某个函数后将元素显示到主窗口中 问题是,每当我在没有vbox/hbox数组的情况下运行函数时,程序都会正常显示GUI元素(在这个测试用例中,是一个文本框)。我还通过在一个新窗口上显示来测试这一点,它也可以工作。这是我使用的普通代码:User interface 如何在主窗口中显示声明为vbox/hbox的数组?,user-interface,lua,iup,User Interface,Lua,Iup,我正在创建一个函数,该函数应该在IUP for Lua中执行某个函数后将元素显示到主窗口中 问题是,每当我在没有vbox/hbox数组的情况下运行函数时,程序都会正常显示GUI元素(在这个测试用例中,是一个文本框)。我还通过在一个新窗口上显示来测试这一点,它也可以工作。这是我使用的普通代码: function wa() local txt = {} txt[1] = iup.text{ multiline = "NO", padding
function wa()
local txt = {}
txt[1] = iup.text{
multiline = "NO",
padding = "5x5",
size="100x15",
scrollbar="Horizontal",
}
iup.Append(hrbox, txt[1])
iup.Map(txt[1])
iup.Refresh(hrbox)
end
但是,当我通过在函数中声明一个数组变量作为hbox/vbox来运行代码时,突然,程序根本不会在主窗口或新窗口中显示元素:
function wa()
local txt = {}
local a = {}
a[1] = iup.vbox{}
txt[1] = iup.text{
multiline = "NO",
padding = "5x5",
size="100x15",
scrollbar="Horizontal",
}
iup.Append(a[1], txt[1])
iup.Map(txt[1])
iup.Refresh(a[1])
iup.Append(hrbox, a[1])
iup.Refresh(hrbox)
end
最奇怪的是,当我把hrbox(我用来在主窗口中显示元素的框)变成一个单独的变量时,它不会在主窗口中显示,但会在新窗口中显示。下面是随后出现的代码:
function wa()
local txt = {}
hrbox = iup.hbox{}
a = {}
a[1] = iup.vbox{}
txt[1] = iup.text{
multiline = "NO",
padding = "5x5",
size="100x15",
scrollbar="Horizontal",
}
iup.Append(a[1], txt[1])
iup.Map(txt[1])
iup.Refresh(a[1])
iup.Append(hrbox, a[1])
iup.Refresh(hrbox)
end
如何使声明为hbox/vbox元素的数组变量工作,以便它可以显示在主窗口中?我不知道该怎么做,在经历了所有的研究之后,我基本上陷入了困境
任何答案和建议都将不胜感激
提前谢谢 我试图创建:
因此,基本上,您的代码工作正常。请确保在wa
上方声明hrbox
编辑:我终于明白你的问题了
这段代码中有一个问题:
function wa()
local txt = {}
local a = {}
a[1] = iup.vbox{}
txt[1] = iup.text{
multiline = "NO",
padding = "5x5",
size="100x15",
scrollbar="Horizontal",
}
iup.Append(a[1], txt[1])
iup.Map(txt[1])
iup.Refresh(a[1])
iup.Append(hrbox, a[1])
iup.Refresh(hrbox)
end
实际上,您需要映射新创建的hbox
。子对象将同时自动映射。调用refresh
一次就足够了
local iup = require("iuplua")
local Button = iup.button{TITLE="Add"}
local hrbox = iup.vbox{Button}
local Frame = iup.dialog{hrbox,SIZE="THIRDxTHIRD"}
function wa()
local txt = {}
local a = {}
a[1] = iup.vbox{}
txt[1] = iup.text{
multiline = "NO",
padding = "5x5",
size="100x15",
scrollbar="Horizontal",
}
iup.Append(a[1], txt[1]) -- Append the text to the new-box
iup.Append(hrbox, a[1]) -- Append the new-box to the main box
iup.Map(a[1]) -- Map the new-box and its children
iup.Refresh(hrbox) -- Re-calculate the layout
end
Button.action = function (Ih)
wa()
end
Frame:show()
iup.MainLoop()
您想试试iup.RefreshChildren吗?@Robert Nope,它不起作用。我也尝试了不同的iup组合,但没有效果。非常感谢!我已经为这个问题绞尽脑汁好几天了。最后,我可以完成我的程序了。
local iup = require("iuplua")
local Button = iup.button{TITLE="Add"}
local hrbox = iup.vbox{Button}
local Frame = iup.dialog{hrbox,SIZE="THIRDxTHIRD"}
function wa()
local txt = {}
local a = {}
a[1] = iup.vbox{}
txt[1] = iup.text{
multiline = "NO",
padding = "5x5",
size="100x15",
scrollbar="Horizontal",
}
iup.Append(a[1], txt[1]) -- Append the text to the new-box
iup.Append(hrbox, a[1]) -- Append the new-box to the main box
iup.Map(a[1]) -- Map the new-box and its children
iup.Refresh(hrbox) -- Re-calculate the layout
end
Button.action = function (Ih)
wa()
end
Frame:show()
iup.MainLoop()