kkallio@8: datatype panelState = Open | Closed
kkallio@8:
rmbruijn@19: con formatCtl :: {Unit} -> Type = fn other_ctx => {FormatPanel : (xml ([Body] ++ other_ctx) [] []) -> (xml ([Body] ++ other_ctx) [] []) -> (xml ([Body] ++ other_ctx) [] []),
rmbruijn@19: OpenCtl : transaction unit -> xml ([Body] ++ other_ctx) [] [],
rmbruijn@19: CloseCtl : transaction unit -> xml ([Body] ++ other_ctx) [] []}
kkallio@8:
kkallio@8: val defaultFormat = {FormatPanel = fn ctl panel => {ctl}{panel},
kkallio@8: OpenCtl = fn behaviour => ,
kkallio@8: CloseCtl = fn behaviour => }
kkallio@8:
rmbruijn@19: con togglePanel t other_ctx = {PanelState : source panelState,
rmbruijn@19: FormatCtl : formatCtl other_ctx,
kkallio@8: Content : t}
kkallio@8:
kkallio@8: open Gui
kkallio@8:
rmbruijn@19: fun create [t ::: Type] [other_ctx:::{Unit}] [other_ctx ~ body] (toXml : gui t (xml ([Body] ++ other_ctx) [] [])) (f : formatCtl other_ctx) (content : t) (startOpen : bool) : transaction (togglePanel t other_ctx) =
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:
rmbruijn@19: fun render [t ::: Type] [other_ctx:::{Unit}] [other_ctx ~ body] (_ : gui t (xml ([Body] ++ other_ctx) [] [])) (panel : togglePanel t other_ctx) =
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:
rmbruijn@19: fun gui_togglePanel [t ::: Type] [other_ctx:::{Unit}] [other_ctx ~ body] (_ : gui t (xml ([Body] ++ other_ctx) [] [])) = mkGui render