]> gitweb.factorcode.org Git - factor.git/commitdiff
UI fixes
authorSlava Pestov <slava@factorcode.org>
Tue, 15 Feb 2005 23:05:28 +0000 (23:05 +0000)
committerSlava Pestov <slava@factorcode.org>
Tue, 15 Feb 2005 23:05:28 +0000 (23:05 +0000)
TODO.FACTOR.txt
examples/gadget-test.factor
library/bootstrap/boot-stage2.factor
library/ui/buttons.factor
library/ui/hand.factor
library/ui/layouts.factor
library/ui/shapes.factor
library/ui/world.factor
native/unix/io.c

index 6ada5d8e5e7f9dd828c1558548ef9393d3695a1a..3d4a59d61a3133bb1512e3ae48e047b53ea59aae 100644 (file)
@@ -8,18 +8,18 @@
 - support USING:\r
 - special completion for USE:/IN:\r
 - vectors: ensure its ok with bignum indices\r
-- if gadgets are moved, added or deleted, update hand.\r
 - code gc\r
 - type inference fails with some assembler words;\r
   displaced, register and other predicates need to inherit from list\r
   not cons, and need stronger branch partial eval\r
 - print warning on null class\r
 - optimize away dispatch\r
-- layouts with gaps\r
 - alignment of gadgets inside their bounding boxes needs thought\r
 - faster completion\r
 - ppc register decls\r
 \r
+- begin-scan, next-object, end-scan primitives\r
+- each-object, each-slot combinators\r
 - port leak\r
 - references primitive\r
 - ditch % for tuples?\r
index dd53fab69b3aa0b994b7e31e34c14317d7436586..7a46689dc97a53b7d7ab86f5a8f0be4f36763c97 100644 (file)
@@ -66,8 +66,8 @@ USE: words
 : make-shapes ( -- )
     f world get set-gadget-children
     
-    100 20 0 0 <rectangle> <pile> "pile" set
-    0 0 0 0 <rectangle> <shelf> "shelf" set
+    default-gap <pile> "pile" set
+    default-gap <shelf> "shelf" set
     "Close" [ "dialog" get world get remove-gadget ] <button> "shelf" get add-gadget
     "New Rectangle" [ drop 100 100 100 100 <funny-rect> dup [ 255 255 0 ] background set-paint-property world get add-gadget ] <button> "shelf" get add-gadget
     "New Ellipse" [ drop 100 100 200 100 <funny-ellipse> dup [ 0 255 0 ] background set-paint-property world get add-gadget ] <button> "shelf" get add-gadget
index 5dc2a8e8b8b490c30f028caed0c06cc82a3dc012..e8827dbe132987c1f40be50e1c01a1cd3cd7072e 100644 (file)
@@ -50,87 +50,102 @@ USING: kernel lists parser stdio words namespaces ;
     "/library/io/presentation.factor"\r
     "/library/io/vocabulary-style.factor"\r
     "/library/syntax/prettyprint.factor"\r
-    "/library/syntax/see.factor"\r
     "/library/tools/debugger.factor"\r
 \r
-    "/library/math/constants.factor"\r
-    "/library/math/pow.factor"\r
-    "/library/math/trig-hyp.factor"\r
-    "/library/math/arc-trig-hyp.factor"\r
-\r
-    "/library/in-thread.factor"\r
-    "/library/io/network.factor"\r
-    "/library/io/logging.factor"\r
-    "/library/random.factor"\r
-    "/library/io/stdio-binary.factor"\r
     "/library/io/files.factor"\r
     "/library/eval-catch.factor"\r
     "/library/tools/heap-stats.factor"\r
     "/library/tools/listener.factor"\r
-    "/library/tools/word-tools.factor"\r
-    "/library/test/test.factor"\r
-    "/library/io/ansi.factor"\r
-    "/library/tools/telnetd.factor"\r
-    "/library/tools/jedit-wire.factor"\r
-    "/library/tools/profiler.factor"\r
-    "/library/gensym.factor"\r
-    "/library/tools/interpreter.factor"\r
-\r
-    ! Inference needs to know primitive stack effects at load time\r
-    "/library/primitives.factor"\r
-\r
-    "/library/inference/dataflow.factor"\r
-    "/library/inference/inference.factor"\r
-    "/library/inference/branches.factor"\r
-    "/library/inference/words.factor"\r
-    "/library/inference/stack.factor"\r
-    "/library/inference/types.factor"\r
-    "/library/inference/test.factor"\r
-\r
-    "/library/compiler/assembler.factor"\r
-    "/library/compiler/xt.factor"\r
-    "/library/compiler/optimizer.factor"\r
-    "/library/compiler/linearizer.factor"\r
-    "/library/compiler/simplifier.factor"\r
-    "/library/compiler/generator.factor"\r
-    "/library/compiler/compiler.factor"\r
-    "/library/compiler/alien-types.factor"\r
-    "/library/compiler/alien.factor"\r
-\r
-    "/library/sdl/sdl.factor"\r
-    "/library/sdl/sdl-video.factor"\r
-    "/library/sdl/sdl-event.factor"\r
-    "/library/sdl/sdl-gfx.factor"\r
-    "/library/sdl/sdl-keysym.factor"\r
-    "/library/sdl/sdl-keyboard.factor"\r
-    "/library/sdl/sdl-ttf.factor"\r
-    "/library/sdl/sdl-utils.factor"\r
-    "/library/sdl/hsv.factor"\r
-\r
-    "/library/bootstrap/image.factor"\r
-\r
-    "/library/httpd/url-encoding.factor"\r
-    "/library/httpd/html-tags.factor"\r
-    "/library/httpd/html.factor"\r
-    "/library/httpd/http-common.factor"\r
-    "/library/httpd/responder.factor"\r
-    "/library/httpd/httpd.factor"\r
-    "/library/httpd/file-responder.factor"\r
-    "/library/httpd/test-responder.factor"\r
-    "/library/httpd/quit-responder.factor"\r
-    "/library/httpd/resource-responder.factor"\r
-    "/library/httpd/cont-responder.factor"\r
-    "/library/httpd/browser-responder.factor"\r
-    "/library/httpd/default-responders.factor"\r
-\r
-    "/library/tools/jedit.factor"\r
-\r
     "/library/cli.factor"\r
 ] [\r
-    dup print\r
-    run-resource\r
+    dup print run-resource\r
 ] each\r
 \r
+IN: command-line DEFER: parse-command-line\r
+parse-command-line\r
+\r
+! Dummy defs for mini bootstrap\r
+IN: compiler : compile-all ;\r
+IN: assembler : init-assembler ;\r
+IN: alien : add-library 3drop ;\r
+\r
+"mini" get [\r
+    [\r
+        "/library/math/constants.factor"\r
+        "/library/math/pow.factor"\r
+        "/library/math/trig-hyp.factor"\r
+        "/library/math/arc-trig-hyp.factor"\r
+\r
+        "/library/syntax/see.factor"\r
+\r
+        "/library/gensym.factor"\r
+        "/library/in-thread.factor"\r
+        "/library/io/network.factor"\r
+        "/library/io/logging.factor"\r
+        "/library/random.factor"\r
+        "/library/io/stdio-binary.factor"\r
+\r
+        "/library/tools/word-tools.factor"\r
+        "/library/test/test.factor"\r
+        "/library/io/ansi.factor"\r
+        "/library/tools/telnetd.factor"\r
+        "/library/tools/jedit-wire.factor"\r
+        "/library/tools/profiler.factor"\r
+        "/library/tools/interpreter.factor"\r
+    \r
+        ! Inference needs to know primitive stack effects at load time\r
+        "/library/primitives.factor"\r
+    \r
+        "/library/inference/dataflow.factor"\r
+        "/library/inference/inference.factor"\r
+        "/library/inference/branches.factor"\r
+        "/library/inference/words.factor"\r
+        "/library/inference/stack.factor"\r
+        "/library/inference/types.factor"\r
+        "/library/inference/test.factor"\r
+    \r
+        "/library/compiler/assembler.factor"\r
+        "/library/compiler/xt.factor"\r
+        "/library/compiler/optimizer.factor"\r
+        "/library/compiler/linearizer.factor"\r
+        "/library/compiler/simplifier.factor"\r
+        "/library/compiler/generator.factor"\r
+        "/library/compiler/compiler.factor"\r
+        "/library/compiler/alien-types.factor"\r
+        "/library/compiler/alien.factor"\r
+    \r
+        "/library/sdl/sdl.factor"\r
+        "/library/sdl/sdl-video.factor"\r
+        "/library/sdl/sdl-event.factor"\r
+        "/library/sdl/sdl-gfx.factor"\r
+        "/library/sdl/sdl-keysym.factor"\r
+        "/library/sdl/sdl-keyboard.factor"\r
+        "/library/sdl/sdl-ttf.factor"\r
+        "/library/sdl/sdl-utils.factor"\r
+        "/library/sdl/hsv.factor"\r
+    \r
+        "/library/bootstrap/image.factor"\r
+    \r
+        "/library/httpd/url-encoding.factor"\r
+        "/library/httpd/html-tags.factor"\r
+        "/library/httpd/html.factor"\r
+        "/library/httpd/http-common.factor"\r
+        "/library/httpd/responder.factor"\r
+        "/library/httpd/httpd.factor"\r
+        "/library/httpd/file-responder.factor"\r
+        "/library/httpd/test-responder.factor"\r
+        "/library/httpd/quit-responder.factor"\r
+        "/library/httpd/resource-responder.factor"\r
+        "/library/httpd/cont-responder.factor"\r
+        "/library/httpd/browser-responder.factor"\r
+        "/library/httpd/default-responders.factor"\r
+    \r
+        "/library/tools/jedit.factor"\r
+    ] [\r
+        dup print run-resource\r
+    ] each\r
+] unless\r
+\r
 os "win32" = [\r
     [\r
         "/library/io/buffer.factor"\r
@@ -146,7 +161,7 @@ os "win32" = [
     ] each\r
 ] when\r
 \r
-cpu "x86" = [\r
+cpu "x86" = "mini" get not and [\r
     [\r
         "/library/compiler/x86/assembler.factor"\r
         "/library/compiler/x86/stack.factor"\r
index f071c2db2649813a31d0b79247b53df61977c606..99aa6ffd91d3f6adcff14643f16762d7b9c94788 100644 (file)
@@ -75,7 +75,7 @@ TUPLE: checkbox bevel selected? delegate ;
     update-checkbox ;
 
 C: checkbox ( label -- checkbox )
-    0 0 0 0 <rectangle> <shelf> over set-checkbox-delegate
+    default-gap <shelf> over set-checkbox-delegate
     [ >r <label> r> add-gadget ] keep
     [ f bevel-border swap init-checkbox-bevel ] keep
     dup [ toggle-checkbox ] button-actions
index 6fd738bab6a399b2dbbfeb0a8c4940642455b3a4..b8887cdb7e618f02c740fa50d5d0a23eda1d4bbe 100644 (file)
@@ -85,6 +85,10 @@ C: hand ( world -- hand )
     dup fire-motion
     r> swap fire-enter ;
 
+: update-hand ( hand -- )
+    #! Called when a gadget is removed or added.
+    [ dup shape-x swap shape-y ] keep move-hand ;
+
 : request-focus ( gadget hand -- )
     dup >r hand-focus
     2dup lose-focus
index 586b5904f6f19f02063b2a8760d6f7662d06bc4e..c2dfe3d378e37332dc04392d1ef259f3308af84f 100644 (file)
@@ -21,27 +21,31 @@ M: gadget layout* drop ;
         drop
     ] ifte ;
 
+: default-gap 3 ;
+
 ! A pile is a box that lays out its contents vertically.
-TUPLE: pile delegate ;
+TUPLE: pile gap delegate ;
 
-C: pile ( shape -- pile )
-    [ >r <gadget> r> set-pile-delegate ] keep ;
+C: pile ( gap -- pile )
+    0 0 0 0 <rectangle> <gadget> over set-pile-delegate
+    [ set-pile-gap ] keep ;
 
 M: pile layout* ( pile -- )
-    dup gadget-children run-heights >r >r
+    dup pile-gap over gadget-children run-heights >r >r
     dup gadget-children max-width r> pick resize-gadget
     gadget-children r> zip [
         uncons 0 swap rot move-gadget
     ] each ;
 
 ! A shelf is a box that lays out its contents horizontally.
-TUPLE: shelf delegate ;
+TUPLE: shelf gap delegate ;
 
-C: shelf ( shape -- pile )
-    [ >r <gadget> r> set-shelf-delegate ] keep ;
+C: shelf ( gap -- pile )
+    0 0 0 0 <rectangle> <gadget> over set-shelf-delegate
+    [ set-shelf-gap ] keep ;
 
 M: shelf layout* ( pile -- )
-    dup gadget-children run-widths >r >r
+    dup shelf-gap over gadget-children run-widths >r >r
     dup gadget-children max-height r> swap pick resize-gadget
     gadget-children r> zip [
         uncons 0 rot move-gadget
index 6d41f12857336d017376daa7c8b6f7e9cf0ed1ad..2e7bb3fb4544bd8b5f255e7068842e609bee9756 100644 (file)
@@ -41,13 +41,18 @@ GENERIC: resize-shape ( w h shape -- )
     #! The height of the tallest shape.
     [ [ shape-h ] map [ > ] top ] [ 0 ] ifte* ;
 
-: run-widths ( list -- w list )
+: accumilate ( gap list -- n list )
+    #! The nth element of the resulting list is the sum of the
+    #! first n elements of the given list plus gap, n times.
+    [ 0 swap [ over , + over + ] each ] make-list >r swap - r> ;
+
+: run-widths ( gap list -- w list )
     #! Compute a list of running sums of widths of shapes.
-    [ 0 swap [ over , shape-w + ] each ] make-list ;
+    [ shape-w ] map accumilate ;
 
-: run-heights ( list -- h list )
+: run-heights ( gap list -- h list )
     #! Compute a list of running sums of heights of shapes.
-    [ 0 swap [ over , shape-h + ] each ] make-list ;
+    [ shape-h ] map accumilate ;
 
 ! A point, represented as a complex number, is the simplest
 ! shape. It is not mutable and cannot be used as the delegate of
index 9339c3b07c28554658311e780b5329a19fe6bcb7..d2cb0557d6a871b8bfe54bed31c3a15e1086557e 100644 (file)
@@ -23,7 +23,7 @@ M: world inside? ( point world -- ? ) 2drop t ;
 
 : draw-world ( -- )
     world get dup gadget-redraw? [
-        [
+        dup world-hand update-hand [
             f over set-gadget-redraw?
             dup draw-gadget
             dup gadget-paint [ world-hand draw-gadget ] bind
@@ -34,7 +34,7 @@ M: world inside? ( point world -- ? ) 2drop t ;
 
 DEFER: handle-event
 
-: layout-world world get layout ;
+: layout-world world get dup layout world-hand update-hand ;
 
 : eat-events ( event -- )
     #! Keep polling for events until there are no more events in
index 37db181e59904051b6b8f9926656771a8309d774..29b771e24e878a1237b1858a5e7ad2c9f43fbaee 100644 (file)
@@ -279,6 +279,10 @@ void primitive_close(void)
        F_PORT* port = untag_port(dpop());
        close(port->fd);
        port->closed = true;
+       port->buffer = F;
+       port->buf_fill = 0;
+       port->buf_pos = 0;
+       port->line = F;
 }
 
 void collect_io_tasks(void)