kkallio@8: datatype panelState = Open | Closed
kkallio@8:
kkallio@8: type formatCtl = {FormatPanel : xbody -> xbody -> xbody,
kkallio@8: OpenCtl : transaction unit -> xbody,
kkallio@8: CloseCtl : transaction unit -> xbody}
kkallio@8:
kkallio@8: val defaultFormat = {FormatPanel = fn ctl panel => {ctl}{panel},
kkallio@8: OpenCtl = fn behaviour => ,
kkallio@8: CloseCtl = fn behaviour => }
kkallio@8:
kkallio@8: con togglePanel t = {PanelState : source panelState,
kkallio@8: FormatCtl : formatCtl,
kkallio@8: Content : t}
kkallio@8:
kkallio@8: open Gui
kkallio@8:
kkallio@8: fun create [t ::: Type] (toXml : gui t) (f : formatCtl) (content : t) (startOpen : bool) : transaction (togglePanel t) =
kkallio@8: state <- source (if startOpen then Open else Closed);
kkallio@8:
kkallio@8: return {PanelState = state,
kkallio@8: FormatCtl = f,
kkallio@8: Content = content}
kkallio@8:
kkallio@8: fun render [t ::: Type] (_ : gui t) (panel : togglePanel t) =
kkallio@8: let
kkallio@8: val openCtl = panel.FormatCtl.CloseCtl (set panel.PanelState Closed)
kkallio@8: val closeCtl = panel.FormatCtl.OpenCtl (set panel.PanelState Open)
kkallio@8:
kkallio@8: val content = toXml panel.Content
kkallio@8: in
kkallio@8: panel.FormatCtl.FormatPanel
kkallio@8:
kkallio@8: {openCtl}
kkallio@8: | Closed => {closeCtl})
kkallio@8: }/>
kkallio@8:
kkallio@8:
kkallio@8:
kkallio@8: {content}
kkallio@8: | Closed => )
kkallio@8: }/>
kkallio@8:
kkallio@8: end
kkallio@8:
kkallio@8: fun gui_togglePanel [t ::: Type] (_ : gui t) = mkGui render