# HG changeset patch # User Ron de Bruijn # Date 1316712241 -7200 # Node ID 16447dc6a68ccda90a85ff9702cb2f214a05af14 # Parent 2947170fcfd6a5d3078fa303a44a65aec4712e61 Introduction of multi-parameter type class for gui components diff -r 2947170fcfd6 -r 16447dc6a68c calendar.urs --- a/calendar.urs Sun Aug 21 11:27:41 2011 -0400 +++ b/calendar.urs Thu Sep 22 19:24:01 2011 +0200 @@ -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 xbody (* Witness that this is a gui widget. *) val create : time -> transaction t diff -r 2947170fcfd6 -r 16447dc6a68c gui.ur --- a/gui.ur Sun Aug 21 11:27:41 2011 -0400 +++ b/gui.ur Thu Sep 22 19:24:01 2011 +0200 @@ -1,7 +1,16 @@ -class gui t = t -> xbody +class gui = fn t :: Type => fn xcomponent :: Type => t -> xcomponent -fun toXml [t ::: Type] (xmlize : gui t) = xmlize +fun gui_xbody (x:xbody) : xbody = x +fun gui_xtable (x:xtable) : xtable = x -fun gui_xbody x = x +fun mkGui [t ::: Type] [xcomponent:::Type] (toXml : t -> xcomponent) = toXml -fun mkGui [t ::: Type] (toXml : t -> xbody) = toXml +fun toXml [t:::Type] [xcomponent ::: Type] (xmlize: gui t xcomponent) = xmlize + +(* class gui t = t -> xbody *) + +(* fun toXml [t ::: Type] (xmlize : gui t) = xmlize *) + +(* fun gui_xbody x = x *) + +(* fun mkGui [t ::: Type] (toXml : t -> xbody) = toXml *) diff -r 2947170fcfd6 -r 16447dc6a68c gui.urs --- a/gui.urs Sun Aug 21 11:27:41 2011 -0400 +++ b/gui.urs Thu Sep 22 19:24:01 2011 +0200 @@ -1,14 +1,21 @@ (* Gui framework elements common across individual components. *) -class gui (* Types of this class describe gui components. *) +class gui :: Type -> Type -> Type + -val toXml : t ::: Type -> gui t -> t -> xbody +(* class gui = fn t xcomponent => t -> xcomponent *) +(* class gui :: Type -> Type -> Type *) + +(* How to add components to the gui class. *) +val mkGui : t ::: Type -> xcomponent:::Type -> (t -> xcomponent) -> gui t xcomponent + +(* Xml itself can be a gui component. *) +val gui_xbody : gui xbody xbody + (* Currently the only thing a gui component can do is be * pretty printed to a piece of xml. *) +val toXml : t ::: Type -> xcomponent ::: Type -> gui t xcomponent -> t -> xcomponent -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. *) + diff -r 2947170fcfd6 -r 16447dc6a68c togglePanel.ur --- a/togglePanel.ur Sun Aug 21 11:27:41 2011 -0400 +++ b/togglePanel.ur Thu Sep 22 19:24:01 2011 +0200 @@ -14,14 +14,14 @@ open Gui -fun create [t ::: Type] (toXml : gui t) (f : formatCtl) (content : t) (startOpen : bool) : transaction (togglePanel t) = +fun create [t ::: Type] (toXml : gui t xbody) (f : formatCtl) (content : t) (startOpen : bool) : transaction (togglePanel t) = state <- source (if startOpen then Open else Closed); return {PanelState = state, FormatCtl = f, Content = content} -fun render [t ::: Type] (_ : gui t) (panel : togglePanel t) = +fun render [t ::: Type] (_ : gui t xbody) (panel : togglePanel t) = let val openCtl = panel.FormatCtl.CloseCtl (set panel.PanelState Closed) val closeCtl = panel.FormatCtl.OpenCtl (set panel.PanelState Open) @@ -48,4 +48,4 @@ end -fun gui_togglePanel [t ::: Type] (_ : gui t) = mkGui render +fun gui_togglePanel [t ::: Type] (_ : gui t xbody) = mkGui render diff -r 2947170fcfd6 -r 16447dc6a68c togglePanel.urs --- a/togglePanel.urs Sun Aug 21 11:27:41 2011 -0400 +++ b/togglePanel.urs Thu Sep 22 19:24:01 2011 +0200 @@ -25,10 +25,10 @@ val defaultFormat : formatCtl (* Some reasonable default formats for the layout and controls. *) -val create : t ::: Type -> Gui.gui t -> formatCtl -> t -> bool -> transaction (togglePanel t) +val create : t ::: Type -> Gui.gui t xbody -> 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 gui_togglePanel : t ::: Type -> Gui.gui t -> Gui.gui (togglePanel t) +val gui_togglePanel : t ::: Type -> Gui.gui t xbody -> Gui.gui (togglePanel t) xbody (* The togglePanel is itself a widget. It can be pretty printed to a piece * of xml with a use of toXml. *)