如何将声明为vbox/hbox的数组显示到主窗口?
2021-4-17 16:29:41
收藏:0
阅读:159
评论:1
我正在创建一个函数,该函数在执行 certain function 之后应该将元素显示到IUP for Lua的主窗口中。
问题在于,每当我运行没有vbox/hbox数组的函数时,程序正常显示GUI元素(在这个测试案例中是文本框)。我还通过在新窗口上显示此内容进行了测试,这也起作用。这是我使用的正常代码:
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元素的数组变量起作用,以便可以将其显示到主窗口中?我不知道该怎么做,在研究了所有资料之后,我陷入了困境。
任何答案和建议都将不胜感激。
先感谢您!
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

我试图创建一个 最小复现示例:
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 = {} 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 Button.action = function (Ih) wa() end Frame:show() iup.MainLoop()因此,基本上,你的代码正常工作。请确保在
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你实际上需要
map新创建的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]) -- 将文本附加到新盒子 iup.Append(hrbox, a[1]) -- 将新盒子附加到主盒子 iup.Map(a[1]) -- 映射新盒子及其子项 iup.Refresh(hrbox) -- 重新计算布局 end Button.action = function (Ih) wa() end Frame:show() iup.MainLoop()