-! Copyright (C) 2005, 2009 Slava Pestov.
+! Copyright (C) 2005, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays hashtables kernel math namespaces
make sequences quotations math.vectors combinators sorting
<PRIVATE
-: ((fast-children-on)) ( gadget dim axis -- <=> )
- [ swap loc>> v- ] dip v. 0 <=> ;
-
-:: (fast-children-on) ( dim axis children -- i )
- children [ dim axis ((fast-children-on)) ] search drop ;
+:: (fast-children-on) ( point axis children quot -- i )
+ children [
+ [ point ] dip
+ quot call( value -- loc ) v-
+ axis v. 0 <=>
+ ] search drop ; inline
PRIVATE>
-: fast-children-on ( rect axis children -- from to )
- [ [ loc>> ] 2dip (fast-children-on) 0 or ]
- [ [ rect-bounds v+ ] 2dip (fast-children-on) ?1+ ]
- 3bi ;
+:: fast-children-on ( rect axis children quot -- slice )
+ rect loc>> axis children quot (fast-children-on) 0 or
+ rect rect-bounds v+ axis children quot (fast-children-on) ?1+
+ children <slice> ; inline
M: gadget contains-rect? ( bounds gadget -- ? )
dup visible?>> [ call-next-method ] [ 2drop f ] if ;
USING: ui.gadgets ui.gadgets.grids tools.test kernel arrays
namespaces math.rectangles accessors ui.gadgets.grids.private
-ui.gadgets.debug sequences ;
+ui.gadgets.debug sequences classes ;
IN: ui.gadgets.grids.tests
[ { 0 0 } ] [ { } <grid> pref-dim ] unit-test
: 100x100 ( -- gadget ) <gadget> { 100 100 } >>dim ;
+: 200x200 ( -- gadget ) <gadget> { 200 200 } >>dim ;
+
[ { 100 100 } ] [
100x100
1array 1array <grid> pref-dim
"g" get
dup layout
children>> [ loc>> ] map
-] unit-test
\ No newline at end of file
+] unit-test
+
+! children-on logic was insufficient
+[ ] [
+ 100x100 dup "a" set 200x200 2array
+ 100x100 dup "b" set 200x200 2array 2array <grid> f >>fill? "g" set
+] unit-test
+
+[ ] [ "g" get prefer ] unit-test
+[ ] [ "g" get layout ] unit-test
+
+[ { 0 50 } ] [ "a" get loc>> ] unit-test
+[ { 0 250 } ] [ "b" get loc>> ] unit-test
+
+[ gadget { 200 200 } ]
+[ { 120 20 } "g" get pick-up [ class ] [ dim>> ] bi ] unit-test
+
+[ gadget { 200 200 } ]
+[ { 120 220 } "g" get pick-up [ class ] [ dim>> ] bi ] unit-test
\ No newline at end of file
-! Copyright (C) 2006, 2009 Slava Pestov.
+! Copyright (C) 2006, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: arrays kernel math math.order math.matrices namespaces make sequences words io
-math.vectors ui.gadgets ui.baseline-alignment columns accessors strings.tables
+USING: arrays kernel math math.order math.matrices namespaces
+make sequences words io math.vectors ui.gadgets
+ui.baseline-alignment columns accessors strings.tables
math.rectangles fry ;
IN: ui.gadgets.grids
M: grid children-on ( rect gadget -- seq )
dup children>> empty? [ 2drop f ] [
- [ { 0 1 } ] dip grid>>
- [ 0 <column> fast-children-on ] [ <slice> concat ] bi
+ [ { 0 1 } ] dip
+ [ grid>> ] [ dim>> ] bi
+ '[ _ [ loc>> vmin ] reduce ] fast-children-on
+ concat
] if ;
M: grid gadget-text*
-! Copyright (C) 2005, 2009 Slava Pestov.
+! Copyright (C) 2005, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: sequences ui.gadgets ui.baseline-alignment
ui.baseline-alignment.private kernel math math.functions math.vectors
dup children>> pref-dims pack-layout ;
M: pack children-on ( rect gadget -- seq )
- [ orientation>> ] [ children>> ] bi
- [ fast-children-on ] keep <slice> ;
+ [ orientation>> ] [ children>> ] bi [ loc>> ] fast-children-on ;
-! Copyright (C) 2005, 2009 Slava Pestov.
+! Copyright (C) 2005, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays hashtables io kernel namespaces sequences
strings quotations math opengl combinators memoize math.vectors
GENERIC: sloppy-pick-up* ( loc gadget -- n )
M: pack sloppy-pick-up* ( loc gadget -- n )
- [ orientation>> ] [ children>> ] bi (fast-children-on) ;
+ [ orientation>> ] [ children>> ] bi
+ [ loc>> ] (fast-children-on) ;
M: gadget sloppy-pick-up*
children>> [ contains-point? ] with find-last drop ;