{- -- Interaction elements, i.e., widgets: data Widget = Entry [ConfItem] -- simple text entry | Button EventHandler [ConfItem] | Label [ConfItem] | TextEdit [ConfItem] | Scale Int Int [ConfItem] -- scaling input ... | Row [ConfCollection] [Widget] | Col [ConfCollection] [Widget] | Matrix [ConfCollection] [[Widget]] -- Widget references: abstract type data WidgetRef = ... -- Configuration of widgets: data ConfItem = Text String | Background String | WRef WidgetRef | Cmd EventHandler | ... data ConfCollection = CenterAlign | LeftAlign | ... -- The type of event handlers: type EventHandler = GuiPort -> IO () -- GuiPort: reference on window -- Basic operations for event handlers: -- Gets the value (a String) of a widget in a GUI: getValue :: WidgetRef -> GuiPort -> IO String -- Puts a string value into a widget in a GUI: setValue :: WidgetRef -> String -> GuiPort -> IO () -- Updates a string value in a widget in a GUI: updateValue :: (String -> String) -> WidgetRef -> GuiPort -> IO () updateValue upd wref gp = do val <- getValue wref gp setValue wref (upd val) gp -- Terminates the GUI: exitGUI :: GuiPort -> IO () -- To start a widget as a GUI: runGUI :: String -> Widget -> IO () -} import Graphics.UI -- in package gui: install by `cypm add gui` counterWidget :: Widget counterWidget = Col [] [Label [Text "A simple counter"], Entry [Text "0", Background "yellow", WRef entryref], Row [] [Button (updateValue incrText entryref) [Text "Increment"], Button (setValue entryref "0") [Text "Reset"], Button exitGUI [Text "Stop"]]] where entryref free incrText s = show ((read s :: Int) + 1) main :: IO () main = runGUI "A simple counter" counterWidget main4 :: IO () main4 = runGUI "Counter Matrix" (Matrix [] [[counterWidget, counterWidget], [counterWidget, counterWidget]])