comparison popupNav.ur @ 6:f17b869fbb71

Shifting some generic theme navigation menu code to the library.
author Karn Kallio <kkallio@eka>
date Tue, 26 Apr 2011 20:27:04 -0430
parents
children 48a4180171b0
comparison
equal deleted inserted replaced
5:4385bc6a0d2d 6:f17b869fbb71
1 datatype menuState = Open | Closed
2
3 type formatCtl = {FormatMenu : xbody -> xbody -> xbody,
4 OpenCtl : transaction unit -> xbody,
5 CloseCtl : transaction unit -> xbody}
6
7 val defaultFormat = {FormatMenu = fn ctl menu => <xml>{ctl}<ul>{menu}</ul></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 open Navbar
12
13 con popupNav t = {MenuState : source menuState,
14 FormatCtl : formatCtl,
15 NavBar : navBar t}
16
17 fun create [t ::: Type] (f : formatCtl) (m : mode t) (bar : navBar t) : transaction (popupNav t) =
18 state <- source Closed;
19
20 return {MenuState = state,
21 FormatCtl = f,
22 NavBar = bar}
23
24 fun render [t ::: Type] (m : mode t) (popup : popupNav t) =
25 popup.FormatCtl.FormatMenu
26 <xml>
27 <dyn signal={c <- signal popup.MenuState;
28 return
29 (case c of
30 Open => <xml>{popup.FormatCtl.CloseCtl (set popup.MenuState Closed)}</xml>
31 | Closed => <xml>{popup.FormatCtl.OpenCtl (set popup.MenuState Open)}</xml>)
32 }/>
33 </xml>
34
35 <xml>
36 <dyn signal={c <- signal popup.MenuState;
37 return
38 (case c of
39 Open => <xml>{navBarToXml popup.NavBar}</xml>
40 | Closed => <xml/>)
41 }/>
42 </xml>