comparison togglePanel.ur @ 23:7c734edc6301

Merge from Adam.
author Karn Kallio <kkallio@eka>
date Sat, 24 Sep 2011 18:55:27 -0430
parents 30f9a763f5fb
children 5905b56e0cd9
comparison
equal deleted inserted replaced
22:4362b15220e4 23:7c734edc6301
1 datatype panelState = Open | Closed 1 datatype panelState = Open | Closed
2 2
3 type formatCtl = {FormatPanel : xbody -> xbody -> xbody, 3 con formatCtl = fn ctx :: {Unit} => [body ~ ctx] =>
4 OpenCtl : transaction unit -> xbody, 4 {FormatPanel : xml (body ++ ctx) [] []
5 CloseCtl : transaction unit -> xbody} 5 -> xml (body ++ ctx) [] []
6 -> xml (body ++ ctx) [] [],
7 OpenCtl : transaction unit -> xml (body ++ ctx) [] [],
8 CloseCtl : transaction unit -> xml (body ++ ctx) [] []}
6 9
7 val defaultFormat = {FormatPanel = fn ctl panel => <xml>{ctl}{panel}</xml>, 10 val defaultFormat [body ~ []] =
8 OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>, 11 {FormatPanel = fn ctl panel => <xml>{ctl}{panel}</xml>,
9 CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>} 12 OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>,
13 CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>}
10 14
11 con togglePanel t = {PanelState : source panelState, 15 con togglePanel t ctx = {PanelState : source panelState,
12 FormatCtl : formatCtl, 16 FormatCtl : formatCtl ctx,
13 Content : t} 17 Content : t}
14 18
15 open Gui 19 open Gui
16 20
17 fun create [t ::: Type] (toXml : gui t) (f : formatCtl) (content : t) (startOpen : bool) : transaction (togglePanel t) = 21 fun create [t ::: Type] [ctx ::: {Unit}] (f : formatCtl ctx) (content : t) (startOpen : bool) : transaction (togglePanel t ctx) =
18 state <- source (if startOpen then Open else Closed); 22 state <- source (if startOpen then Open else Closed);
19 23
20 return {PanelState = state, 24 return {PanelState = state,
21 FormatCtl = f, 25 FormatCtl = @f,
22 Content = content} 26 Content = content}
23 27
24 fun render [t ::: Type] (_ : gui t) (panel : togglePanel t) = 28 fun render [t ::: Type] [ctx ::: {Unit}] (_ : gui t ctx) [body ~ ctx] (panel : togglePanel t ctx) =
25 let 29 let
26 val openCtl = panel.FormatCtl.CloseCtl (set panel.PanelState Closed) 30 val format = panel.FormatCtl !
27 val closeCtl = panel.FormatCtl.OpenCtl (set panel.PanelState Open) 31 val openCtl = format.CloseCtl (set panel.PanelState Closed)
32 val closeCtl = format.OpenCtl (set panel.PanelState Open)
28 33
29 val content = toXml panel.Content 34 val content = toXml panel.Content
30 in 35 in
31 panel.FormatCtl.FormatPanel 36 format.FormatPanel
32 <xml> 37 <xml>
33 <dyn signal={c <- signal panel.PanelState; 38 <dyn signal={c <- signal panel.PanelState;
34 return 39 return
35 (case c of 40 (case c of
36 Open => <xml>{openCtl}</xml> 41 Open => <xml>{openCtl}</xml>
46 | Closed => <xml/>) 51 | Closed => <xml/>)
47 }/> 52 }/>
48 </xml> 53 </xml>
49 end 54 end
50 55
51 fun gui_togglePanel [t ::: Type] (_ : gui t) = mkGui render 56 fun gui_togglePanel [t ::: Type] [ctx ::: {Unit}] (g : gui t ctx) = mkGui (@render g)