以编程方式更改 wxhaskell 布局

change wxhaskell layout programmatically

我想在事件发生后切换布局(即单击按钮)。所以我设置了新布局并重新绘制面板,但布局没有改变。 (它只有在我手动调整框架大小后才会这样做。)缺少的神奇调味料是什么?谢谢你帮我!

import Graphics.UI.WX

buildGUI = do
  f <- frame [ text := "Hello" ]

  controls <- panel f []
  ctext <- staticText controls [ text := "Foo" ]
  butn <- button controls [text := "change layout"]
  set controls [ layout := row 0 [margin 5 (widget ctext),
                                  margin 5 (widget butn) ]]

  set f [ layout := widget controls ]

  set butn [on command := do
      -- switch layout, button first, text second
      set controls [layout := row 0 [ margin 5 (widget butn)
                                    , margin 5 (widget ctext) ]]
  {-
     repaint doesn't do it, but if I resize the frame by hand,
     the layout changes
  -}    
      repaint controls         ]

  return ()

main = start buildGUI

在谷歌搜索数学兰花的评论后,我自己找到了答案。该函数称为 refit.