annotate togglePanel.ur @ 19:3a303df9ae92

Partial generalize togglePanel solution (breaks build)
author Ron de Bruijn <rmbruijn@gmail.com>
date Fri, 23 Sep 2011 13:30:01 +0200
parents 16447dc6a68c
children 554e342665fe
rev   line source
kkallio@8 1 datatype panelState = Open | Closed
kkallio@8 2
rmbruijn@19 3 con formatCtl :: {Unit} -> Type = fn other_ctx => {FormatPanel : (xml ([Body] ++ other_ctx) [] []) -> (xml ([Body] ++ other_ctx) [] []) -> (xml ([Body] ++ other_ctx) [] []),
rmbruijn@19 4 OpenCtl : transaction unit -> xml ([Body] ++ other_ctx) [] [],
rmbruijn@19 5 CloseCtl : transaction unit -> xml ([Body] ++ other_ctx) [] []}
kkallio@8 6
kkallio@8 7 val defaultFormat = {FormatPanel = fn ctl panel => <xml>{ctl}{panel}</xml>,
kkallio@8 8 OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>,
kkallio@8 9 CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>}
kkallio@8 10
rmbruijn@19 11 con togglePanel t other_ctx = {PanelState : source panelState,
rmbruijn@19 12 FormatCtl : formatCtl other_ctx,
kkallio@8 13 Content : t}
kkallio@8 14
kkallio@8 15 open Gui
kkallio@8 16
rmbruijn@19 17 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 18 state <- source (if startOpen then Open else Closed);
kkallio@8 19
kkallio@8 20 return {PanelState = state,
kkallio@8 21 FormatCtl = f,
kkallio@8 22 Content = content}
kkallio@8 23
rmbruijn@19 24 fun render [t ::: Type] [other_ctx:::{Unit}] [other_ctx ~ body] (_ : gui t (xml ([Body] ++ other_ctx) [] [])) (panel : togglePanel t other_ctx) =
kkallio@8 25 let
kkallio@8 26 val openCtl = panel.FormatCtl.CloseCtl (set panel.PanelState Closed)
kkallio@8 27 val closeCtl = panel.FormatCtl.OpenCtl (set panel.PanelState Open)
kkallio@8 28
kkallio@8 29 val content = toXml panel.Content
kkallio@8 30 in
kkallio@8 31 panel.FormatCtl.FormatPanel
kkallio@8 32 <xml>
kkallio@8 33 <dyn signal={c <- signal panel.PanelState;
kkallio@8 34 return
kkallio@8 35 (case c of
kkallio@8 36 Open => <xml>{openCtl}</xml>
kkallio@8 37 | Closed => <xml>{closeCtl}</xml>)
kkallio@8 38 }/>
kkallio@8 39 </xml>
kkallio@8 40
kkallio@8 41 <xml>
kkallio@8 42 <dyn signal={c <- signal panel.PanelState;
kkallio@8 43 return
kkallio@8 44 (case c of
kkallio@8 45 Open => <xml>{content}</xml>
kkallio@8 46 | Closed => <xml/>)
kkallio@8 47 }/>
kkallio@8 48 </xml>
kkallio@8 49 end
kkallio@8 50
rmbruijn@19 51 fun gui_togglePanel [t ::: Type] [other_ctx:::{Unit}] [other_ctx ~ body] (_ : gui t (xml ([Body] ++ other_ctx) [] [])) = mkGui render