factor/basis/ui/gadgets/menus/menus.factor

71 lines
1.9 KiB
Factor
Raw Normal View History

! Copyright (C) 2005, 2009 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
2015-01-29 14:41:18 -05:00
USING: accessors colors.constants kernel locals math.rectangles
math.vectors namespaces opengl sequences sorting ui.commands
2015-07-20 16:58:32 -04:00
ui.gadgets ui.gadgets.borders ui.gadgets.buttons ui.gadgets.corners
2015-01-29 14:41:18 -05:00
ui.gadgets.frames ui.gadgets.glass ui.gadgets.packs
2015-07-22 15:54:31 -04:00
ui.gadgets.worlds ui.tools.common ui.gestures ui.operations ui.pens
2015-01-29 14:41:18 -05:00
ui.pens.solid ui.render ;
2007-09-20 18:09:08 -04:00
IN: ui.gadgets.menus
: show-menu ( owner menu -- )
[ find-world ] dip hand-loc get-global { 0 0 } <rect> show-glass ;
2007-09-20 18:09:08 -04:00
GENERIC: <menu-item> ( target hook command -- button )
M:: object <menu-item> ( target hook command -- button )
command command-name [
hook call
target command command-button-quot call
hide-glass
] <roll-button> ;
2007-09-20 18:09:08 -04:00
<PRIVATE
2015-07-22 15:54:31 -04:00
CONSTANT: menu-background-color COLOR: grey95
CONSTANT: menu-border-color COLOR: grey75
TUPLE: separator-pen color ;
C: <separator-pen> separator-pen
M: separator-pen draw-interior
color>> gl-color
dim>> [ { 0 0.5 } v* ] [ { 1 0.5 } v* ] bi
[ v>integer ] bi@ gl-line ;
2009-03-14 00:49:16 -04:00
: <menu-items> ( items -- gadget )
2015-07-22 15:54:31 -04:00
[ <filled-pile> ] dip add-gadgets ;
2009-03-14 00:49:16 -04:00
PRIVATE>
SINGLETON: ----
M: ---- <menu-item>
3drop
<gadget>
{ 0 5 } >>dim
2015-07-22 15:54:31 -04:00
menu-border-color <separator-pen> >>interior ;
2007-09-20 18:09:08 -04:00
2009-03-14 00:49:16 -04:00
: <menu> ( gadgets -- menu )
<menu-items>
2015-07-22 15:54:31 -04:00
{ 0 3 } >>gap
margins
menu-border-color <solid> >>boundary
menu-background-color <solid> >>interior ;
2009-03-14 00:49:16 -04:00
: <commands-menu> ( target hook commands -- menu )
[ <menu-item> ] 2with map <menu> ;
: show-commands-menu ( target commands -- )
[ dup [ ] ] dip <commands-menu> show-menu ;
: <operations-menu> ( target hook -- menu )
over object-operations
[ primary-operation? ] partition
[ reverse ] [ [ command-name ] sort-with ] bi*
{ ---- } glue <commands-menu> ;
2009-01-16 17:39:32 -05:00
: show-operations-menu ( gadget target hook -- )
<operations-menu> show-menu ;