annotate togglePanel.ur @ 27:5905b56e0cd9

Adapt to new HTML contexts
author Adam Chlipala <adam@chlipala.net>
date Tue, 20 Dec 2011 21:04:21 -0500
parents 30f9a763f5fb
children 7d0014542199
rev   line source
kkallio@8 1 datatype panelState = Open | Closed
kkallio@8 2
adam@27 3 con formatCtl = fn ctx :: {Unit} => [[Dyn] ~ ctx] =>
adam@27 4 {FormatPanel : xml ([Dyn] ++ ctx) [] []
adam@27 5 -> xml ([Dyn] ++ ctx) [] []
adam@27 6 -> xml ([Dyn] ++ ctx) [] [],
adam@27 7 OpenCtl : transaction unit -> xml ([Dyn] ++ ctx) [] [],
adam@27 8 CloseCtl : transaction unit -> xml ([Dyn] ++ ctx) [] []}
kkallio@8 9
adam@27 10 val defaultFormat [[Dyn] ~ body'] =
adam@20 11 {FormatPanel = fn ctl panel => <xml>{ctl}{panel}</xml>,
adam@20 12 OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>,
adam@20 13 CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>}
kkallio@8 14
adam@20 15 con togglePanel t ctx = {PanelState : source panelState,
adam@20 16 FormatCtl : formatCtl ctx,
adam@20 17 Content : t}
kkallio@8 18
kkallio@8 19 open Gui
kkallio@8 20
adam@20 21 fun create [t ::: Type] [ctx ::: {Unit}] (f : formatCtl ctx) (content : t) (startOpen : bool) : transaction (togglePanel t ctx) =
kkallio@8 22 state <- source (if startOpen then Open else Closed);
kkallio@8 23
kkallio@8 24 return {PanelState = state,
adam@20 25 FormatCtl = @f,
kkallio@8 26 Content = content}
kkallio@8 27
adam@27 28 fun render [t ::: Type] [ctx ::: {Unit}] (_ : gui t ctx) [[Dyn] ~ ctx] (panel : togglePanel t ctx) =
kkallio@8 29 let
adam@20 30 val format = panel.FormatCtl !
adam@20 31 val openCtl = format.CloseCtl (set panel.PanelState Closed)
adam@20 32 val closeCtl = format.OpenCtl (set panel.PanelState Open)
kkallio@8 33
kkallio@8 34 val content = toXml panel.Content
kkallio@8 35 in
adam@20 36 format.FormatPanel
kkallio@8 37 <xml>
kkallio@8 38 <dyn signal={c <- signal panel.PanelState;
kkallio@8 39 return
kkallio@8 40 (case c of
kkallio@8 41 Open => <xml>{openCtl}</xml>
kkallio@8 42 | Closed => <xml>{closeCtl}</xml>)
kkallio@8 43 }/>
kkallio@8 44 </xml>
kkallio@8 45
kkallio@8 46 <xml>
kkallio@8 47 <dyn signal={c <- signal panel.PanelState;
kkallio@8 48 return
kkallio@8 49 (case c of
kkallio@8 50 Open => <xml>{content}</xml>
kkallio@8 51 | Closed => <xml/>)
kkallio@8 52 }/>
kkallio@8 53 </xml>
kkallio@8 54 end
kkallio@8 55
adam@20 56 fun gui_togglePanel [t ::: Type] [ctx ::: {Unit}] (g : gui t ctx) = mkGui (@render g)