1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel namespaces ui.gadgets ui.gadgets.worlds
4 ui.gadgets.wrappers ui.gestures math.rectangles
5 math.rectangles.positioning combinators vectors ;
8 GENERIC: hide-glass-hook ( gadget -- )
10 M: gadget hide-glass-hook drop ;
14 TUPLE: glass < gadget visible-rect owner ;
16 : <glass> ( owner child visible-rect -- glass )
22 : visible-rect ( glass -- rect )
23 [ visible-rect>> ] [ owner>> ] bi screen-loc offset-rect ;
28 [ gadget-child pref-dim ]
31 ] [ gadget-child ] bi set-rect-bounds ;
33 M: glass ungraft* gadget-child hide-glass-hook ;
35 : add-glass ( glass world -- )
36 [ swap add-gadget drop ] [ [ ?push ] change-layers drop ] 2bi ;
40 : hide-glass ( child -- )
41 [ glass? ] find-parent
42 [ dup find-world [ unparent ] dip request-focus ]
45 : show-glass ( owner child visible-rect -- )
47 dup gadget-child hand-clicked set
48 dup owner>> find-world add-glass ;
51 { T{ button-down } [ hide-glass ] }
52 { T{ drag } [ update-clicked drop ] }
59 TUPLE: popup < wrapper owner ;
61 : <popup> ( owner gadget -- popup )
65 M: popup hide-glass-hook
66 owner>> f >>popup request-focus ;
71 { T{ key-down f f "ESC" } [ hide-glass ] }
74 : pass-to-popup ( gesture interactor -- ? )
75 popup>> focusable-child resend-gesture ;
77 : show-popup ( owner popup visible-rect -- )
79 [ drop dup owner>> (>>popup) ]
80 [ [ [ owner>> ] keep ] dip show-glass ]