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