factor/library/ui/hierarchy.factor

65 lines
1.8 KiB
Factor
Raw Normal View History

2005-03-07 22:11:36 -05:00
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
USING: generic hashtables kernel lists math matrices namespaces
2005-07-16 23:01:51 -04:00
sequences vectors ;
2005-03-07 22:11:36 -05:00
2005-07-09 16:08:50 -04:00
: remove-gadget ( gadget parent -- )
2005-03-07 22:11:36 -05:00
[ 2dup gadget-children remq swap set-gadget-children ] keep
2005-08-23 18:16:42 -04:00
relayout f swap set-gadget-parent ;
2005-03-07 22:11:36 -05:00
: unparent ( gadget -- )
[
dup gadget-parent dup
[ remove-gadget ] [ 2drop ] ifte
] when* ;
2005-03-07 22:11:36 -05:00
2005-07-17 00:21:10 -04:00
: (clear-gadget) ( gadget -- )
gadget-children [
dup [ f swap set-gadget-parent ] each 0 swap set-length
] when* ;
: clear-gadget ( gadget -- )
2005-07-17 00:21:10 -04:00
dup (clear-gadget) relayout ;
2005-07-16 22:16:18 -04:00
: ?push ( elt seq/f -- seq )
2005-07-16 23:01:51 -04:00
[ [ push ] keep ] [ 1vector ] ifte* ;
2005-07-09 16:08:50 -04:00
: (add-gadget) ( gadget box -- )
2005-03-07 22:11:36 -05:00
over unparent
dup pick set-gadget-parent
2005-07-16 22:16:18 -04:00
[ gadget-children ?push ] keep set-gadget-children ;
2005-07-09 16:08:50 -04:00
: add-gadget ( gadget parent -- )
#! Add a gadget to a parent gadget.
[ (add-gadget) ] keep relayout ;
2005-03-07 22:11:36 -05:00
: (parents-down) ( list gadget -- list )
[ [ swons ] keep gadget-parent (parents-down) ] when* ;
: parents-down ( gadget -- list )
#! A list of all parents of the gadget, the last element
#! is the gadget itself.
f swap (parents-down) ;
: parents-up ( gadget -- list )
2005-07-13 21:03:34 -04:00
#! A list of all parents of the gadget, the first element
#! is the gadget itself.
dup [ dup gadget-parent parents-up cons ] when ;
2005-03-07 22:11:36 -05:00
: each-parent ( gadget quot -- ? )
>r parents-up r> all? ; inline
2005-03-07 22:11:36 -05:00
2005-07-20 16:03:03 -04:00
: find-parent ( gadget quot -- ? )
>r parents-up r> find nip ; inline
2005-07-20 16:03:03 -04:00
: screen-loc ( gadget -- point )
#! The position of the gadget on the screen.
parents-up { 0 0 0 } [ rect-loc v+ ] reduce ;
2005-03-07 22:11:36 -05:00
: relative ( g1 g2 -- g2-g1 )
screen-loc swap screen-loc v- ;
2005-03-07 22:11:36 -05:00
: child? ( parent child -- ? )
parents-down memq? ;