Mercurial > gui
comparison togglePanel.ur @ 8:90be8b8917d5
Add a widget that opens and closes a panel.
author | Karn Kallio <kkallio@eka> |
---|---|
date | Fri, 17 Jun 2011 10:12:05 -0430 |
parents | |
children | 16447dc6a68c |
comparison
equal
deleted
inserted
replaced
7:48a4180171b0 | 8:90be8b8917d5 |
---|---|
1 datatype panelState = Open | Closed | |
2 | |
3 type formatCtl = {FormatPanel : xbody -> xbody -> xbody, | |
4 OpenCtl : transaction unit -> xbody, | |
5 CloseCtl : transaction unit -> xbody} | |
6 | |
7 val defaultFormat = {FormatPanel = fn ctl panel => <xml>{ctl}{panel}</xml>, | |
8 OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>, | |
9 CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>} | |
10 | |
11 con togglePanel t = {PanelState : source panelState, | |
12 FormatCtl : formatCtl, | |
13 Content : t} | |
14 | |
15 open Gui | |
16 | |
17 fun create [t ::: Type] (toXml : gui t) (f : formatCtl) (content : t) (startOpen : bool) : transaction (togglePanel t) = | |
18 state <- source (if startOpen then Open else Closed); | |
19 | |
20 return {PanelState = state, | |
21 FormatCtl = f, | |
22 Content = content} | |
23 | |
24 fun render [t ::: Type] (_ : gui t) (panel : togglePanel t) = | |
25 let | |
26 val openCtl = panel.FormatCtl.CloseCtl (set panel.PanelState Closed) | |
27 val closeCtl = panel.FormatCtl.OpenCtl (set panel.PanelState Open) | |
28 | |
29 val content = toXml panel.Content | |
30 in | |
31 panel.FormatCtl.FormatPanel | |
32 <xml> | |
33 <dyn signal={c <- signal panel.PanelState; | |
34 return | |
35 (case c of | |
36 Open => <xml>{openCtl}</xml> | |
37 | Closed => <xml>{closeCtl}</xml>) | |
38 }/> | |
39 </xml> | |
40 | |
41 <xml> | |
42 <dyn signal={c <- signal panel.PanelState; | |
43 return | |
44 (case c of | |
45 Open => <xml>{content}</xml> | |
46 | Closed => <xml/>) | |
47 }/> | |
48 </xml> | |
49 end | |
50 | |
51 fun gui_togglePanel [t ::: Type] (_ : gui t) = mkGui render |