factor/library/ui/menus.factor

38 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
USING: generic kernel lists math namespaces sequences ;
2005-03-01 22:11:08 -05:00
: show-menu ( menu -- )
hand screen-loc over set-rect-loc show-glass ;
2005-03-01 22:11:08 -05:00
: menu-item-border ( child -- border )
<plain-gadget> { 1 1 0 } <border> ;
2005-03-01 22:11:08 -05:00
: <menu-item> ( label quot -- gadget )
2005-08-26 00:55:56 -04:00
>r <label> menu-item-border dup roll-button-theme dup
r> button-gestures ;
2005-03-01 22:11:08 -05:00
TUPLE: menu ;
2005-03-01 22:11:08 -05:00
: menu-actions ( menu -- )
2005-07-09 18:32:31 -04:00
[ drop hide-glass ] [ 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.
[
2005-07-09 18:32:31 -04:00
uncons \ hide-glass swons <menu-item> swap add-gadget
2005-03-02 21:26:11 -05:00
] each-with ;
2005-03-01 22:11:08 -05:00
2005-08-26 00:55:56 -04:00
: menu-theme ( menu -- )
<< gradient f { 1 0 0 } { 240 240 255 } { 216 216 216 } >>
interior set-paint-prop ;
2005-03-01 22:11:08 -05:00
C: menu ( assoc -- gadget )
#! Given an association list mapping labels to quotations.
[ f line-border swap set-delegate ] keep
2005-07-06 03:29:42 -04:00
0 1 <pile> [ swap add-gadget ] 2keep
2005-08-26 00:55:56 -04:00
rot assoc>menu dup menu-actions
dup menu-theme ;