kkallio@8
|
1 datatype panelState = Open | Closed
|
kkallio@8
|
2
|
adam@20
|
3 con formatCtl = fn ctx :: {Unit} => [body ~ ctx] =>
|
adam@21
|
4 {FormatPanel : xml (body ++ ctx) [] []
|
adam@21
|
5 -> xml (body ++ ctx) [] []
|
adam@21
|
6 -> xml (body ++ ctx) [] [],
|
adam@21
|
7 OpenCtl : transaction unit -> xml (body ++ ctx) [] [],
|
adam@21
|
8 CloseCtl : transaction unit -> xml (body ++ ctx) [] []}
|
kkallio@8
|
9
|
adam@20
|
10 val defaultFormat [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@20
|
28 fun render [t ::: Type] [ctx ::: {Unit}] (_ : gui t ctx) [body ~ 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)
|