module Graphics.UI.Gtk.Custom.ToggleButtonList where
import Graphics.UI.Gtk as GTK
type ToggleButtonListUpdater = [String]->IO ()
data Orientation = Horizontal | Vertical
toggleButtonListNew
onToggle
orientation
drawHelper
labels
= do
b <- case orientation of
Horizontal -> do
hb <- GTK.hBoxNew False 0
return $ castToBox hb
Vertical -> do
vb <- GTK.vBoxNew False 0
return $ castToBox vb
let
addToggleButton label = do
tb <- GTK.toggleButtonNewWithLabel label
GTK.boxPackStart b tb GTK.PackNatural 0
return tb
clearBox = do
GTK.containerForall b GTK.widgetDestroy
fillBox labels = do
tbs<-mapM addToggleButton labels
mapM drawHelper tbs
GTK.widgetShowAll b
return tbs
tbs <- fillBox labels
let
tbWithLabels tbs labels = zip tbs labels
setupToggleButton
labels'
tbs
(tb,label)
=
tb `on` GTK.toggled $ do
active <- get tb GTK.toggleButtonActive
case active of
True -> do
onToggle label
mapM_
(\(tb',label') ->
case label == label' of
True -> return ()
False -> set tb' [GTK.toggleButtonActive := False])
(tbWithLabels tbs labels')
False-> return ()
updateToggleButtons :: [String] -> IO()
updateToggleButtons labels = do
clearBox
tbs <- fillBox labels
mapM_ (setupToggleButton labels tbs) (tbWithLabels tbs labels)
mapM (setupToggleButton labels tbs) (tbWithLabels tbs labels)
return (b,updateToggleButtons)