factor/library/ui/menus.factor

34 lines
1.1 KiB
Factor
Raw Normal View History

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-menus
USING: gadgets gadgets-borders gadgets-buttons gadgets-layouts
gadgets-labels generic kernel lists math namespaces sequences ;
2005-03-01 22:11:08 -05:00
2005-08-26 22:22:00 -04:00
: menu-actions ( glass -- )
[ drop hide-glass ] [ button-down 1 ] set-action ;
: fit-bounds ( loc dim max -- loc )
#! Adjust loc to fit inside max.
swap v- { 0 0 0 } vmax vmin ;
: menu-loc ( menu -- loc )
hand rect-loc swap rect-dim world get rect-dim fit-bounds ;
2005-03-01 22:11:08 -05:00
: show-menu ( menu -- )
2005-08-26 22:22:00 -04:00
dup show-glass
dup menu-loc swap set-rect-loc
world get world-glass menu-actions ;
2005-03-01 22:11:08 -05:00
2005-08-26 21:42:43 -04:00
: menu-items ( assoc -- pile )
2005-03-02 21:26:11 -05:00
#! Given an association list mapping labels to quotations.
#! Prepend a call to hide-menu to each quotation.
2005-08-26 21:42:43 -04:00
[ uncons \ hide-glass swons >r <label> r> <roll-button> ] map
<pile> 1 over set-pack-fill [ add-gadgets ] keep ;
2005-03-01 22:11:08 -05:00
2005-08-26 00:55:56 -04:00
: menu-theme ( menu -- )
2005-08-27 15:12:37 -04:00
<< solid f >> interior set-paint-prop ;
2005-08-26 00:55:56 -04:00
2005-08-26 21:42:43 -04:00
: <menu> ( assoc -- gadget )
2005-03-01 22:11:08 -05:00
#! Given an association list mapping labels to quotations.
2005-08-26 21:42:43 -04:00
menu-items line-border dup menu-theme ;