From 2b4c49c33abb391c9403e15c3fc69d2700867e56 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 29 Jun 2005 23:40:44 +0000 Subject: [PATCH] big cleanup of UI code --- library/math/math.factor | 17 +++---- library/test/gadgets.factor | 10 ---- library/ui/borders.factor | 8 +-- library/ui/checkboxes.factor | 2 +- library/ui/frames.factor | 2 +- library/ui/init-world.factor | 4 +- library/ui/layouts.factor | 87 ++++++++++++++++++++++++++++----- library/ui/load.factor | 3 -- library/ui/menus.factor | 2 +- library/ui/piles.factor | 49 ------------------- library/ui/presentations.factor | 2 + library/ui/scrolling.factor | 8 --- library/ui/shelves.factor | 45 ----------------- library/ui/splitters.factor | 28 +++-------- library/ui/stacks.factor | 20 -------- 15 files changed, 101 insertions(+), 186 deletions(-) delete mode 100644 library/ui/piles.factor delete mode 100644 library/ui/shelves.factor delete mode 100644 library/ui/stacks.factor diff --git a/library/math/math.factor b/library/math/math.factor index bc962eb5f5..b1aab5208d 100644 --- a/library/math/math.factor +++ b/library/math/math.factor @@ -60,19 +60,16 @@ GENERIC: abs ( z -- |z| ) 2dup mod dup 0 number= [ 2drop ] [ - + ] ifte ; : (repeat) ( i n quot -- ) - pick pick >= [ - 3drop - ] [ - [ swap >r call 1 + r> ] keep (repeat) - ] ifte ; inline + pick pick >= + [ 3drop ] [ [ swap >r call 1 + r> ] keep (repeat) ] ifte ; + inline -: repeat ( n quot -- ) - #! Execute a quotation n times. The loop counter is kept on - #! the stack, and ranges from 0 to n-1. +: repeat ( n quot -- | quot: n -- n ) + #! The loop counter is kept on the stack, and ranges from + #! 0 to n-1. 0 -rot (repeat) ; inline -: times ( n quot -- ) - #! Evaluate a quotation n times. +: times ( n quot -- | quot: -- ) swap [ >r dup slip r> ] repeat drop ; inline : 2repeat ( i j quot -- | quot: i j -- i j ) diff --git a/library/test/gadgets.factor b/library/test/gadgets.factor index 8f0bf9f23c..ed9c9aca14 100644 --- a/library/test/gadgets.factor +++ b/library/test/gadgets.factor @@ -67,16 +67,6 @@ USING: gadgets kernel lists math namespaces test sequences ; ] with-scope ] unit-test -[ - 300 620 -] [ - 0 { 10 10 10 } 0 "pile" set - 0 0 100 100 "pile" get add-gadget - 0 0 200 200 "pile" get add-gadget - 0 0 300 300 "pile" get add-gadget - "pile" get pref-size -] unit-test - [ ] [ "pile" get layout* ] unit-test [ diff --git a/library/ui/borders.factor b/library/ui/borders.factor index a7205167a5..2898a4de3a 100644 --- a/library/ui/borders.factor +++ b/library/ui/borders.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: gadgets -USING: errors generic hashtables kernel lists math namespaces -sdl vectors ; +USING: errors generic hashtables kernel lists math matrices +namespaces sdl vectors ; ! A border lays out its children on top of each other, all with ! a 5-pixel padding. @@ -34,8 +34,8 @@ C: border ( child delegate size -- border ) gadget-child resize-gadget ; M: border pref-dim ( border -- dim ) - [ border-size 2 * ] keep - gadget-child pref-size >r over + r> rot + 0 3vector ; + [ border-size dup dup 3vector 2 v*n ] keep + gadget-child pref-dim v+ ; M: border layout* ( border -- ) dup layout-border-x/y layout-border-w/h ; diff --git a/library/ui/checkboxes.factor b/library/ui/checkboxes.factor index 1c66061f07..5c2b129c08 100644 --- a/library/ui/checkboxes.factor +++ b/library/ui/checkboxes.factor @@ -41,7 +41,7 @@ TUPLE: checkbox bevel selected? ; [ checkbox-bevel button-update ] [ mouse-enter ] set-action ; C: checkbox ( label -- checkbox ) - over set-delegate + over set-delegate [ f line-border swap init-checkbox-bevel ] keep [ >r