changeset 23:7c734edc6301

Merge from Adam.
author Karn Kallio <kkallio@eka>
date Sat, 24 Sep 2011 18:55:27 -0430
parents 4362b15220e4 30f9a763f5fb
children d314d2ec3300
files
diffstat 10 files changed, 97 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/calendar.ur	Mon Aug 22 05:06:15 2011 -0430
+++ b/calendar.ur	Sat Sep 24 18:55:27 2011 -0430
@@ -207,7 +207,7 @@
     SourceL.onChange ctl.Day f
 
 val gui_t = Gui.mkGui 
-                (fn ctl =>
+                (fn [body ~ []] ctl =>
                     <xml>
                       <dyn signal={render' ctl}/>
                     </xml>)
--- a/calendar.urs	Mon Aug 22 05:06:15 2011 -0430
+++ b/calendar.urs	Sat Sep 24 18:55:27 2011 -0430
@@ -20,7 +20,7 @@
 val value : t -> signal date
 (* Read the date of the calendar. *)
 
-val gui_t : Gui.gui t
+val gui_t : Gui.gui t []
 (* Witness that this is a gui widget. *)
 
 val create : time -> transaction t
--- a/datebox.ur	Mon Aug 22 05:06:15 2011 -0430
+++ b/datebox.ur	Sat Sep 24 18:55:27 2011 -0430
@@ -1,5 +1,5 @@
 type t = {Cal : Calendar.t,
-          Panel : TogglePanel.togglePanel Calendar.t}
+          Panel : TogglePanel.togglePanel Calendar.t []}
 
 type date = Calendar.date
 val date_eq = Calendar.date_eq
@@ -7,14 +7,15 @@
 val time = Calendar.time
 val date = Calendar.date
 
-val format = TogglePanel.defaultFormat 
-                 --#OpenCtl -- #CloseCtl
-                 ++ {OpenCtl = fn behaviour => <xml><button value="Choose" onclick={behaviour}/></xml>,
-                     CloseCtl = fn behaviour => <xml><button value="Hide" onclick={behaviour}/></xml>}
+val format : TogglePanel.formatCtl [] = fn [body ~ []] =>
+    TogglePanel.defaultFormat
+        -- #OpenCtl -- #CloseCtl
+        ++ {OpenCtl = fn behaviour => <xml><button value="Choose" onclick={behaviour}/></xml>,
+            CloseCtl = fn behaviour => <xml><button value="Hide" onclick={behaviour}/></xml>}
 
 fun create tm =
     cal <- Calendar.create tm;
-    panel <- TogglePanel.create format cal False;
+    panel <- TogglePanel.create @format cal False;
 
     return {Cal = cal,
             Panel = panel}
@@ -27,9 +28,9 @@
 
 fun value db = Calendar.value db.Cal
 
-fun render db = 
+val gui_t = Gui.mkGui (fn [body ~ []] db =>
     <xml>
       <dyn signal={date <- Calendar.value db.Cal;
                    return <xml>{[date.Year]}-{[date.Month]}-{[date.Day]}</xml>}/>
       {Gui.toXml db.Panel}
-    </xml>
+    </xml>)
--- a/datebox.urs	Mon Aug 22 05:06:15 2011 -0430
+++ b/datebox.urs	Sat Sep 24 18:55:27 2011 -0430
@@ -1,7 +1,7 @@
 type t
-(* The type of dateboxes, which are input elements
- * allowing the user to select a date from a popup
- * calendar. *)
+
+(* The type of dateboxes, which are input elements allowing the user to select a
+ * date from a popup calendar. *)
 
 type date = {Year : int, Month : int, Day : int}
 val date_eq : eq date
@@ -22,5 +22,5 @@
 val value : t -> signal date
 (* Extract the current date value. *)
 
-val render : t -> xbody
+val gui_t : Gui.gui t []
 (* Draws the datebox as a piece of xml. *)
--- a/examples/datebox.ur	Mon Aug 22 05:06:15 2011 -0430
+++ b/examples/datebox.ur	Sat Sep 24 18:55:27 2011 -0430
@@ -1,15 +1,14 @@
 fun main () =
+    tm <- now;
 
-tm <- now;
+    dayCtl <- Datebox.create tm;
 
-dayCtl <- Datebox.create tm;
+    load <- return (Datebox.onChange dayCtl (fn d => alert (show d.Day)));
 
-load <- return (Datebox.onChange dayCtl (fn d => alert (show d.Day)));
-
-return
-    <xml>
-      <head><title>Datebox Example</title></head>
-      <body onload={load}>
-        {Datebox.render dayCtl}
-      </body>
-    </xml>
+    return
+        <xml>
+          <head><title>Datebox Example</title></head>
+          <body onload={load}>
+            {Gui.toXml dayCtl}
+          </body>
+        </xml>
--- a/examples/togglepanel.ur	Mon Aug 22 05:06:15 2011 -0430
+++ b/examples/togglepanel.ur	Sat Sep 24 18:55:27 2011 -0430
@@ -4,14 +4,15 @@
 val defaultContent : xbody = <xml><p>Here I am inside the panel.<br/><b>Default format</b></p></xml>
 val otherContent : xbody = <xml><p>Here I am inside the panel.<br/><b>Other format</b></p></xml>
 
-val otherFormat = {FormatPanel = fn ctl panel => <xml><span>A Custom {ctl} Format</span>{panel}</xml>,
-                   OpenCtl = fn behaviour => <xml><a href={bless "http://#"} onclick={behaviour}>View</a></xml>,
-                   CloseCtl = fn behaviour => <xml><a href={bless "http://#"} onclick={behaviour}>Hide</a></xml>}
+val otherFormat = fn [body ~ []] =>
+                     {FormatPanel = fn ctl panel => <xml><span>A Custom {ctl} Format</span>{panel}</xml>,
+                      OpenCtl = fn behaviour => <xml><a href={bless "http://#"} onclick={behaviour}>View</a></xml>,
+                      CloseCtl = fn behaviour => <xml><a href={bless "http://#"} onclick={behaviour}>Hide</a></xml>}
 
 fun main () =
 
-    defaultFormatPanel <- create defaultFormat defaultContent True;
-    otherFormatPanel <- create otherFormat otherContent False;
+    defaultFormatPanel <- create @defaultFormat defaultContent True;
+    otherFormatPanel <- create @otherFormat otherContent False;
 
     return <xml>
       <head>
--- a/gui.ur	Mon Aug 22 05:06:15 2011 -0430
+++ b/gui.ur	Sat Sep 24 18:55:27 2011 -0430
@@ -1,7 +1,8 @@
-class gui t = t -> xbody
+class gui = fn (t :: Type) (ctx :: {Unit}) => [body ~ ctx] => t -> xml (body ++ ctx) [] []
 
-fun toXml [t ::: Type] (xmlize : gui t) = xmlize
+fun gui_xbody [body ~ []] x = x
+fun gui_xtable [body ~ _] x = x
 
-fun gui_xbody x = x
+fun mkGui [t ::: Type] [ctx ::: {Unit}] (toXml : [body ~ ctx] => t -> xml (body ++ ctx) [] []) = @toXml
 
-fun mkGui [t ::: Type] (toXml : t -> xbody) = toXml
+fun toXml [t ::: Type] [ctx ::: {Unit}] [body ~ ctx] (toXml : gui t ctx) = toXml
--- a/gui.urs	Mon Aug 22 05:06:15 2011 -0430
+++ b/gui.urs	Sat Sep 24 18:55:27 2011 -0430
@@ -1,14 +1,17 @@
 (* Gui framework elements common across individual components. *)
 
-class gui
 (* Types of this class describe gui components. *)
+class gui :: Type (* The type of an object to render *)
+      -> {Unit} (* The HTML context to render it for (minus [body]) *)
+      -> Type
 
-val toXml : t ::: Type -> gui t -> t -> xbody
+(* How to add components to the gui class. *)
+val mkGui : t ::: Type -> ctx ::: {Unit} -> ([body ~ ctx] => t -> xml (body ++ ctx) [] []) -> gui t ctx
+
+(* XML itself can be a gui component. *)
+val gui_xbody : gui xbody []
+val gui_xtable : gui xtable [Table]
+
 (* Currently the only thing a gui component can do is be
  * pretty printed to a piece of xml. *)
-
-val gui_xbody : gui xbody
-(* Xml itself can be a gui component. *)
-
-val mkGui : t ::: Type -> (t -> xbody) -> gui t
-(* How to add components to the gui class. *)
+val toXml : t ::: Type -> ctx ::: {Unit} -> [body ~ ctx] => gui t ctx -> t -> xml (body ++ ctx) [] []
--- 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)
--- a/togglePanel.urs	Mon Aug 22 05:06:15 2011 -0430
+++ b/togglePanel.urs	Sat Sep 24 18:55:27 2011 -0430
@@ -2,33 +2,40 @@
  * disappears when the user activates an associated control.  The
  * panel may contain another gui widget as content. *)
 
-con togglePanel :: Type -> Type
-(* The type of appearing and disappearing panels.  The argument
- * is the type of the content. *)
+con togglePanel :: Type -> {Unit} -> Type
+(* The type of appearing and disappearing panels.  The arguments
+ * are as for [Gui.gui]. *)
 
-type formatCtl = {FormatPanel : xbody -> xbody -> xbody,
-                  (* Allows for formatting the panel.  The first two parameters
-                   * represent "holes" for the control and panel respectively while
-                   * the result should be the desired xml laying out the whole structure.
-                   * The controls can be formatted with the options below.
-                   * The panel part appears and disappears according to the use 
-                   * of the controls. *)
+con formatCtl = fn ctx :: {Unit} => [body ~ ctx] =>
+                   {FormatPanel : xml (body ++ ctx) [] []
+                                  -> xml (body ++ ctx) [] []
+                                  -> xml (body ++ ctx) [] [],
+                    (* Allows for formatting the panel.  The first two parameters
+                     * represent "holes" for the control and panel respectively while
+                     * the result should be the desired XML laying out the whole structure.
+                     * The controls can be formatted with the options below.
+                     * The panel part appears and disappears according to the use
+                     * of the controls. *)
                   
-                  OpenCtl : transaction unit -> xbody,
-                  (* This should accept the transaction representing the opening of
-                   * the panel and produce an xml control having this as action. *)
+                    OpenCtl : transaction unit -> xml (body ++ ctx) [] [],
+                    (* This should accept the transaction representing the opening of
+                     * the panel and produce an XML control having this as action. *)
 
-                  CloseCtl : transaction unit -> xbody}
-                  (* This should accept the transaction representing the closing of
-                   * the panel and produce an xml control having this as action. *)
+                    CloseCtl : transaction unit -> xml (body ++ ctx) [] []}
+                    (* This should accept the transaction representing the closing of
+                     * the panel and produce an xml control having this as action. *)
 
-val defaultFormat : formatCtl
 (* Some reasonable default formats for the layout and controls. *)
+val defaultFormat : formatCtl []
 
-val create : t ::: Type -> Gui.gui t -> formatCtl -> t -> bool -> transaction (togglePanel t)
-(* Given instructions for formatting the display, some content and whether to start in
- * the open state get such a togglePanel. *)
+val create : t ::: Type -> ctx ::: {Unit} ->
+    formatCtl ctx (* Formatting instructions *)
+    -> t             (* Enclosed widget *)
+    -> bool          (* Start in open state? *)
+    -> transaction (togglePanel t ctx)
 
-val gui_togglePanel : t ::: Type -> Gui.gui t -> Gui.gui (togglePanel t)
+val gui_togglePanel : t ::: Type -> ctx ::: {Unit}
+                      -> Gui.gui t ctx
+                      -> Gui.gui (togglePanel t ctx) ctx
 (* The togglePanel is itself a widget.  It can be pretty printed to a piece
- * of xml with a use of toXml. *)
+ * of XML with a use of [toXml]. *)