factor/library/ui/tiles.factor

70 lines
2.0 KiB
Factor
Raw Normal View History

2005-03-06 19:46:29 -05:00
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
USING: generic kernel math namespaces ;
2005-03-06 19:46:29 -05:00
! A tile is a gadget with a caption. Dragging the caption
! moves the gadget. The title bar also has buttons for
! performing various actions.
: click-rel ( gadget -- point )
screen-pos
hand [ hand-clicked screen-pos - ] keep hand-click-rel - ;
2005-03-22 21:20:58 -05:00
: move-tile ( tile -- )
2005-03-06 19:46:29 -05:00
dup click-rel hand screen-pos + >rect rot move-gadget ;
2005-03-22 21:20:58 -05:00
: resize-tile ( tile -- )
dup hand relative >rect rot resize-gadget ;
2005-03-06 19:46:29 -05:00
: raise ( gadget -- )
dup gadget-parent >r dup unparent r> add-gadget ;
: caption-actions ( caption -- )
2005-03-22 21:20:58 -05:00
dup [ raise ] [ button-down 1 ] link-action
2005-03-06 19:46:29 -05:00
dup [ drop ] [ button-up 1 ] set-action
2005-03-22 21:20:58 -05:00
[ move-tile ] [ drag 1 ] link-action ;
2005-03-06 19:46:29 -05:00
: close-tile [ close-tile ] swap handle-gesture drop ;
2005-03-10 22:52:55 -05:00
: <close-box> ( -- gadget )
<check> line-border dup [ close-tile ] button-actions ;
2005-03-06 19:46:29 -05:00
: caption-content ( text -- gadget )
1/2 10 0 <shelf>
2005-03-10 22:52:55 -05:00
[ <close-box> swap add-gadget ] keep
2005-03-06 19:46:29 -05:00
[ >r <label> r> add-gadget ] keep ;
: <caption> ( text -- caption )
2005-03-10 22:52:55 -05:00
caption-content filled-border
dup t reverse-video set-paint-prop
dup caption-actions ;
2005-03-06 19:46:29 -05:00
: tile-actions ( tile -- )
dup [ unparent ] [ close-tile ] set-action
dup [ raise ] [ raise ] set-action
2005-03-22 21:20:58 -05:00
dup [ move-tile ] [ move-tile ] set-action
[ resize-tile ] [ resize-tile ] set-action ;
: <resizer> ( -- gadget )
<frame>
dup [ resize-tile ] [ drag 1 ] link-action
0 0 40 10 <plain-rect> <gadget>
dup t reverse-video set-paint-prop
over add-right ;
: tile-content ( child caption -- pile )
2005-03-22 21:20:58 -05:00
<frame>
[ >r <caption> r> add-top ] keep
[ <resizer> swap add-bottom ] keep
[ add-center ] keep ;
TUPLE: tile ;
C: tile ( child caption -- tile )
[ f line-border swap set-delegate ] keep
[ >r tile-content r> add-gadget ] keep
[ tile-actions ] keep
dup delegate pref-size pick resize-gadget ;
M: tile pref-size shape-size ;