Search code examples
rcontainersgwidgets

How to dynamically switch a `ggroup` from `horizontal=TRUE` to `horizontal=FALSE`?


How could I change a ggroup from horizontal=TRUE to horizontal=FALSE in a gWidgets2 GUI that is already visible? Consider the following:

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

If I now execute:

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

then the GUI blanks out. Instead, I would have expected the g container to become horizontal=FALSE and for the contained buttons to be vertically arranged. How can the latter be achieved?


Solution

  • This may not work cross platform, but with Gtk it does:

    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)