diff togglePanel.ur @ 23:7c734edc6301

Merge from Adam.
author Karn Kallio <kkallio@eka>
date Sat, 24 Sep 2011 18:55:27 -0430
parents 30f9a763f5fb
children 5905b56e0cd9
line wrap: on
line diff
--- a/togglePanel.ur	Mon Aug 22 05:06:15 2011 -0430
+++ b/togglePanel.ur	Sat Sep 24 18:55:27 2011 -0430
@@ -1,34 +1,39 @@
 datatype panelState = Open | Closed
 
-type formatCtl = {FormatPanel : xbody -> xbody -> xbody,
-                  OpenCtl : transaction unit -> xbody,
-                  CloseCtl : transaction unit -> xbody}
+con formatCtl = fn ctx :: {Unit} => [body ~ ctx] =>
+                   {FormatPanel : xml (body ++ ctx) [] []
+                                  -> xml (body ++ ctx) [] []
+                                  -> xml (body ++ ctx) [] [],
+                    OpenCtl : transaction unit -> xml (body ++ ctx) [] [],
+                    CloseCtl : transaction unit -> xml (body ++ ctx) [] []}
 
-val defaultFormat = {FormatPanel = fn ctl panel => <xml>{ctl}{panel}</xml>,
-                     OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>,
-                     CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>}
+val defaultFormat [body ~ []] =
+    {FormatPanel = fn ctl panel => <xml>{ctl}{panel}</xml>,
+     OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>,
+     CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>}
                     
-con togglePanel t = {PanelState : source panelState,
-                     FormatCtl : formatCtl,
-                     Content : t}
+con togglePanel t ctx = {PanelState : source panelState,
+                         FormatCtl : formatCtl ctx,
+                         Content : t}
 
 open Gui
 
-fun create [t ::: Type] (toXml : gui t) (f : formatCtl) (content : t) (startOpen : bool) : transaction (togglePanel t) =
+fun create [t ::: Type] [ctx ::: {Unit}] (f : formatCtl ctx) (content : t) (startOpen : bool) : transaction (togglePanel t ctx) =
     state <- source (if startOpen then Open else Closed);
 
     return {PanelState = state,
-            FormatCtl = f,
+            FormatCtl = @f,
             Content = content}
 
-fun render [t ::: Type] (_ : gui t) (panel : togglePanel t) =
+fun render [t ::: Type] [ctx ::: {Unit}] (_ : gui t ctx) [body ~ ctx] (panel : togglePanel t ctx) =
     let
-        val openCtl = panel.FormatCtl.CloseCtl (set panel.PanelState Closed)
-        val closeCtl = panel.FormatCtl.OpenCtl (set panel.PanelState Open)
+        val format = panel.FormatCtl !
+        val openCtl = format.CloseCtl (set panel.PanelState Closed)
+        val closeCtl = format.OpenCtl (set panel.PanelState Open)
 
         val content = toXml panel.Content
     in
-        panel.FormatCtl.FormatPanel
+        format.FormatPanel
             <xml>
               <dyn signal={c <- signal panel.PanelState;
                            return
@@ -48,4 +53,4 @@
             </xml>
     end
 
-fun gui_togglePanel [t ::: Type] (_ : gui t) = mkGui render 
+fun gui_togglePanel [t ::: Type] [ctx ::: {Unit}] (g : gui t ctx) = mkGui (@render g)