factor/library/ui/menus.factor

47 lines
1.5 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
2005-09-28 23:29:00 -04:00
gadgets-labels gadgets-theme generic kernel lists math
namespaces sequences ;
2005-03-01 22:11:08 -05:00
2005-09-01 18:28:46 -04:00
: retarget-drag ( -- )
2005-10-09 21:27:14 -04:00
hand get [ hand-gadget ] keep 2dup hand-clicked eq?
[ 2dup set-hand-clicked update-hand ] unless 2drop ;
2005-09-01 18:28:46 -04:00
2005-11-14 01:54:40 -05:00
: retarget-click ( -- )
update-hand-gadget update-clicked ;
2005-08-26 22:22:00 -04:00
: menu-actions ( glass -- )
2005-09-01 18:28:46 -04:00
dup [ drop retarget-drag ] [ drag 1 ] set-action
2005-11-14 01:54:40 -05:00
[ drop hide-glass retarget-click ] [ button-down 1 ] set-action ;
2005-08-26 22:22:00 -04:00
: fit-bounds ( loc dim max -- loc )
#! Adjust loc to fit inside max.
2005-09-27 00:24:42 -04:00
swap |v-| vmin ;
2005-08-26 22:22:00 -04:00
2005-10-01 01:44:49 -04:00
: menu-loc ( menu loc -- loc )
swap rect-dim world get rect-dim fit-bounds ;
2005-08-26 22:22:00 -04:00
2005-10-01 01:44:49 -04:00
: show-menu ( menu loc -- )
>r dup dup show-glass r>
menu-loc swap set-rect-loc
2005-09-01 18:28:46 -04:00
world get world-glass dup menu-actions
2005-10-07 20:26:21 -04:00
hand get set-hand-clicked ;
2005-03-01 22:11:08 -05:00
2005-10-07 20:26:21 -04:00
: show-hand-menu ( menu -- ) hand get rect-loc show-menu ;
2005-10-01 01:44:49 -04: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
2005-09-27 00:24:42 -04:00
make-pile 1 over set-pack-fill ;
2005-03-01 22:11:08 -05: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-10-13 00:23:17 -04:00
menu-items <border> dup menu-theme ;
2005-09-24 23:21:09 -04:00
2005-10-09 21:27:14 -04:00
: menu-button-actions ( gadget -- )
2005-09-24 23:21:09 -04:00
dup [ button-clicked ] [ button-down 1 ] set-action
2005-10-09 21:27:14 -04:00
[ button-update ] [ button-up 1 ] set-action ;