Skip to content

Instantly share code, notes, and snippets.

@CatherineH
Created December 13, 2016 17:47
Show Gist options
  • Save CatherineH/b0d94d3ecde5dd3d406fb243f62b5ad2 to your computer and use it in GitHub Desktop.
Save CatherineH/b0d94d3ecde5dd3d406fb243f62b5ad2 to your computer and use it in GitHub Desktop.
recursive monad gui
module Main (main) where
import Graphics.UI.Gtk
import Data.List.Split
poem = "Best Witchcraft is Geometry To the magician’s mind His ordinary acts are feats To thinking of mankind."
makebuttonbox :: [String] -> IO HBox
makebuttonbox [] = do
box1 <- hBoxNew False 0
return box1
makebuttonbox (label1:label2:labels) = do
hBox <- hBoxNew False 0
vBox <- vBoxNew False 0
hButton <- buttonNewWithLabel label1
vButton <- buttonNewWithLabel label2
box2 <- makebuttonbox labels
let pack_style = PackRepel
let padding = 0
boxPackStart hBox hButton pack_style padding
boxPackStart vBox vButton pack_style padding
boxPackStart vBox box2 pack_style padding
boxPackStart hBox vBox pack_style padding
return hBox
makebuttonbox [label1] = do
hBox <- hBoxNew False 0
hButton <- buttonNewWithLabel label1
boxPackStart hBox hButton PackNatural 0
return hBox
main :: IO ()
main = do
initGUI
window <- windowNew
on window objectDestroy mainQuit
set window [ containerBorderWidth := 10 ]
hBox <- makebuttonbox (splitOn " " poem)
set window [ containerChild := hBox]
widgetShowAll window
mainGUI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment