2005-03-01 22:11:08 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: gadgets
|
2005-04-25 19:54:21 -04:00
|
|
|
USING: generic kernel lists math namespaces sequences ;
|
2005-03-01 22:11:08 -05:00
|
|
|
|
2005-03-02 21:26:11 -05:00
|
|
|
: hide-menu ( -- )
|
|
|
|
world get
|
2005-06-27 16:50:21 -04:00
|
|
|
dup hide-glass
|
|
|
|
[ world-menu unparent f ] keep set-world-menu ;
|
2005-03-01 22:11:08 -05:00
|
|
|
|
|
|
|
: show-menu ( menu -- )
|
2005-03-02 21:26:11 -05:00
|
|
|
hide-menu
|
|
|
|
world get
|
2005-03-01 22:11:08 -05:00
|
|
|
2dup set-world-menu
|
2005-06-29 19:40:44 -04:00
|
|
|
2dup world-hand screen-loc swap set-gadget-loc
|
2005-06-27 16:50:21 -04:00
|
|
|
show-glass ;
|
2005-03-01 22:11:08 -05:00
|
|
|
|
|
|
|
: menu-item-border ( child -- border )
|
2005-06-23 03:15:44 -04:00
|
|
|
<plain-gadget> 1 <border> ;
|
2005-03-01 22:11:08 -05:00
|
|
|
|
|
|
|
: <menu-item> ( label quot -- gadget )
|
2005-05-03 19:00:52 -04:00
|
|
|
>r <label> menu-item-border dup r> button-gestures ;
|
2005-03-01 22:11:08 -05:00
|
|
|
|
2005-03-08 22:54:59 -05:00
|
|
|
TUPLE: menu ;
|
2005-03-01 22:11:08 -05:00
|
|
|
|
|
|
|
: menu-actions ( menu -- )
|
2005-05-03 23:50:04 -04:00
|
|
|
[ drop hide-menu ] [ button-down 1 ] set-action ;
|
2005-03-02 21:26:11 -05:00
|
|
|
|
|
|
|
: assoc>menu ( assoc menu -- )
|
|
|
|
#! Given an association list mapping labels to quotations.
|
|
|
|
#! Prepend a call to hide-menu to each quotation.
|
|
|
|
[
|
|
|
|
uncons \ hide-menu swons <menu-item> swap add-gadget
|
|
|
|
] each-with ;
|
2005-03-01 22:11:08 -05:00
|
|
|
|
|
|
|
C: menu ( assoc -- gadget )
|
|
|
|
#! Given an association list mapping labels to quotations.
|
2005-03-08 22:54:59 -05:00
|
|
|
[ f line-border swap set-delegate ] keep
|
2005-03-01 22:11:08 -05:00
|
|
|
<line-pile> [ swap add-gadget ] 2keep
|
2005-03-02 21:26:11 -05:00
|
|
|
rot assoc>menu dup menu-actions ;
|
2005-03-01 22:11:08 -05:00
|
|
|
|
|
|
|
! While a menu is open, clicking anywhere sends the click to
|
|
|
|
! the menu.
|
|
|
|
M: menu inside? ( point menu -- ? ) 2drop t ;
|
2005-03-03 20:43:55 -05:00
|
|
|
|
|
|
|
: actionize ( obj assoc -- assoc )
|
|
|
|
#! Prepends an object to each cdr of the assoc list. Utility
|
|
|
|
#! word for constructing menu action association lists.
|
|
|
|
[
|
|
|
|
unswons >r >r unit [ car ] cons r> append r> swons
|
|
|
|
] map-with ;
|