annotate 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
rev   line source
kkallio@6 1 datatype menuState = Open | Closed
kkallio@6 2
kkallio@6 3 type formatCtl = {FormatMenu : xbody -> xbody -> xbody,
kkallio@6 4 OpenCtl : transaction unit -> xbody,
kkallio@6 5 CloseCtl : transaction unit -> xbody}
kkallio@6 6
kkallio@6 7 val defaultFormat = {FormatMenu = fn ctl menu => <xml>{ctl}<ul>{menu}</ul></xml>,
kkallio@6 8 OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>,
kkallio@6 9 CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>}
kkallio@6 10
kkallio@6 11 open Navbar
kkallio@6 12
kkallio@6 13 con popupNav t = {MenuState : source menuState,
kkallio@6 14 FormatCtl : formatCtl,
kkallio@6 15 NavBar : navBar t}
kkallio@6 16
kkallio@6 17 fun create [t ::: Type] (f : formatCtl) (m : mode t) (bar : navBar t) : transaction (popupNav t) =
kkallio@6 18 state <- source Closed;
kkallio@6 19
kkallio@6 20 return {MenuState = state,
kkallio@6 21 FormatCtl = f,
kkallio@6 22 NavBar = bar}
kkallio@6 23
kkallio@6 24 fun render [t ::: Type] (m : mode t) (popup : popupNav t) =
kkallio@6 25 popup.FormatCtl.FormatMenu
kkallio@6 26 <xml>
kkallio@6 27 <dyn signal={c <- signal popup.MenuState;
kkallio@6 28 return
kkallio@6 29 (case c of
kkallio@6 30 Open => <xml>{popup.FormatCtl.CloseCtl (set popup.MenuState Closed)}</xml>
kkallio@6 31 | Closed => <xml>{popup.FormatCtl.OpenCtl (set popup.MenuState Open)}</xml>)
kkallio@6 32 }/>
kkallio@6 33 </xml>
kkallio@6 34
kkallio@6 35 <xml>
kkallio@6 36 <dyn signal={c <- signal popup.MenuState;
kkallio@6 37 return
kkallio@6 38 (case c of
kkallio@6 39 Open => <xml>{navBarToXml popup.NavBar}</xml>
kkallio@6 40 | Closed => <xml/>)
kkallio@6 41 }/>
kkallio@6 42 </xml>