如何动态地将`group`从`horizo​​ntal = TRUE`切换到`horizo​​ntal = FALSE`?

时间:2014-07-25 07:10:29

标签: r containers gwidgets

如何在已经可见的gWidgets2 GUI中将ggrouphorizontal=TRUE更改为horizontal=FALSE?请考虑以下事项:

w <- gwindow("Box containers")
g <- ggroup(horizontal=TRUE, cont=w)
gbutton("one", cont=g); gbutton("two", cont=g)

如果我现在执行:

g <- ggroup(horizontal=FALSE, cont=w)

然后GUI消隐了。相反,我希望g容器变为horizontal=FALSE,并且包含的​​按钮可以垂直排列。如何实现后者?

2 个答案:

答案 0 :(得分:1)

这可能无法跨平台工作,但与Gtk相反:

w = gwindow()
g = ggroup(cont=w)
g1 = ggroup(cont=g)
g2 = ggroup(cont=g, horizontal=FALSE)
b1 = gbutton("asdf", cont=g1)
b2 = gbutton("asdfadfasd", cont=g1)
## reparent by deleting, then adding:
delete(g1, b1)
delete(g1, b2)
add(g2, b1)
add(g2, b2)

答案 1 :(得分:0)

与接受的答案类似的另一种方法是add / delete容器本身,而不是按钮:

w = gwindow()
g = ggroup(cont=w)
g1 = ggroup(cont=g)
b1 = gbutton("asdf", cont=g1)
b2 = gbutton("asdfadfasd", cont=g1)
g2 = ggroup(cont=g, horizontal=FALSE)
b1bis = gbutton("asdf", cont=g2)
b2bis = gbutton("asdfadfasd", cont=g2)
delete(g, g2)
## reparent by deleting, then adding:
delete(g, g1)
add(g, g2)
## switch back to original layout
delete(g, g2)
add(g, g1)