Mercurial > gui
comparison 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 |
comparison
equal
deleted
inserted
replaced
18:16447dc6a68c | 19:3a303df9ae92 |
---|---|
1 datatype panelState = Open | Closed | 1 datatype panelState = Open | Closed |
2 | 2 |
3 type formatCtl = {FormatPanel : xbody -> xbody -> xbody, | 3 con formatCtl :: {Unit} -> Type = fn other_ctx => {FormatPanel : (xml ([Body] ++ other_ctx) [] []) -> (xml ([Body] ++ other_ctx) [] []) -> (xml ([Body] ++ other_ctx) [] []), |
4 OpenCtl : transaction unit -> xbody, | 4 OpenCtl : transaction unit -> xml ([Body] ++ other_ctx) [] [], |
5 CloseCtl : transaction unit -> xbody} | 5 CloseCtl : transaction unit -> xml ([Body] ++ other_ctx) [] []} |
6 | 6 |
7 val defaultFormat = {FormatPanel = fn ctl panel => <xml>{ctl}{panel}</xml>, | 7 val defaultFormat = {FormatPanel = fn ctl panel => <xml>{ctl}{panel}</xml>, |
8 OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>, | 8 OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>, |
9 CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>} | 9 CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>} |
10 | 10 |
11 con togglePanel t = {PanelState : source panelState, | 11 con togglePanel t other_ctx = {PanelState : source panelState, |
12 FormatCtl : formatCtl, | 12 FormatCtl : formatCtl other_ctx, |
13 Content : t} | 13 Content : t} |
14 | 14 |
15 open Gui | 15 open Gui |
16 | 16 |
17 fun create [t ::: Type] (toXml : gui t xbody) (f : formatCtl) (content : t) (startOpen : bool) : transaction (togglePanel t) = | 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) = |
18 state <- source (if startOpen then Open else Closed); | 18 state <- source (if startOpen then Open else Closed); |
19 | 19 |
20 return {PanelState = state, | 20 return {PanelState = state, |
21 FormatCtl = f, | 21 FormatCtl = f, |
22 Content = content} | 22 Content = content} |
23 | 23 |
24 fun render [t ::: Type] (_ : gui t xbody) (panel : togglePanel t) = | 24 fun render [t ::: Type] [other_ctx:::{Unit}] [other_ctx ~ body] (_ : gui t (xml ([Body] ++ other_ctx) [] [])) (panel : togglePanel t other_ctx) = |
25 let | 25 let |
26 val openCtl = panel.FormatCtl.CloseCtl (set panel.PanelState Closed) | 26 val openCtl = panel.FormatCtl.CloseCtl (set panel.PanelState Closed) |
27 val closeCtl = panel.FormatCtl.OpenCtl (set panel.PanelState Open) | 27 val closeCtl = panel.FormatCtl.OpenCtl (set panel.PanelState Open) |
28 | 28 |
29 val content = toXml panel.Content | 29 val content = toXml panel.Content |
46 | Closed => <xml/>) | 46 | Closed => <xml/>) |
47 }/> | 47 }/> |
48 </xml> | 48 </xml> |
49 end | 49 end |
50 | 50 |
51 fun gui_togglePanel [t ::: Type] (_ : gui t xbody) = mkGui render | 51 fun gui_togglePanel [t ::: Type] [other_ctx:::{Unit}] [other_ctx ~ body] (_ : gui t (xml ([Body] ++ other_ctx) [] [])) = mkGui render |