diff demo/more/dragList.ur @ 916:b873feb3eb52

dragList almost kinda works
author Adam Chlipala <adamc@hcoop.net>
date Tue, 08 Sep 2009 10:18:19 -0400
parents
children 321a2d6feb40
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/more/dragList.ur	Tue Sep 08 10:18:19 2009 -0400
@@ -0,0 +1,33 @@
+fun draggableList title items =
+    itemSources <- List.mapM source items;
+    draggingItem <- source None;
+    return <xml>
+      <h2>Great {[title]}</h2>
+      <ul>
+        {List.mapX (fn itemSource => <xml>
+          <li onmousedown={set draggingItem (Some itemSource)}
+              onmouseup={set draggingItem None}
+              onmouseover={di <- get draggingItem;
+                           case di of
+                               None => return ()
+                             | Some di => item1 <- get di;
+                               item2 <- get itemSource;
+                               set di item2;
+                               set itemSource item1}>
+              <dyn signal={s <- signal itemSource; return <xml>{[s]}</xml>}/>
+         </li></xml>) itemSources}
+      </ul>
+    </xml>
+
+fun main () =
+    bears <- draggableList "Bears" ("Pooh" :: "Paddington" :: "Rupert" :: "Edward" :: []);
+    beers <- draggableList "Beers" ("Budvar" :: "Delirium Tremens" :: "Deuchars" :: []);
+    boars <- draggableList "Boars" ("Sus scrofa scrofa"
+                                        :: "Sus scrofa ussuricus"
+                                        :: "Sus scrofa cristatus"
+                                        :: "Sus scrofa taiwanus" :: []);
+    return <xml><body>
+      {bears}
+      {beers}
+      {boars}
+    </body></xml>