1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel math.rectangles
4 math.rectangles.positioning math.vectors namespaces ui.gadgets
5 ui.gadgets.viewports ui.gadgets.worlds ui.gadgets.wrappers
7 FROM: ui.gadgets.wrappers => wrapper ;
10 GENERIC: hide-glass-hook ( gadget -- )
12 M: gadget hide-glass-hook drop ;
16 TUPLE: glass < gadget visible-rect owner ;
18 : <glass> ( owner child visible-rect -- glass )
24 : visible-rect ( glass -- rect )
25 [ visible-rect>> ] [ owner>> ] bi
26 [ screen-loc ] [ [ viewport? ] find-parent [ screen-loc vmax ] when* ] bi
32 [ gadget-child pref-dim ]
35 ] [ gadget-child ] bi set-rect-bounds ;
37 M: glass ungraft* gadget-child hide-glass-hook ;
39 : add-glass ( glass world -- )
40 [ swap add-gadget drop ] [ [ ?push ] change-layers drop ] 2bi ;
44 : hide-glass ( child -- )
45 [ glass? ] find-parent
46 [ dup find-world [ unparent ] dip request-focus ]
49 : show-glass ( owner child visible-rect -- )
51 dup gadget-child hand-clicked set-global
52 dup owner>> find-world add-glass ;
55 { T{ button-down } [ hide-glass ] }
56 { T{ drag } [ update-clicked drop ] }
63 TUPLE: popup < wrapper owner ;
65 : <popup> ( owner gadget -- popup )
69 M: popup hide-glass-hook
70 dup owner>> 2dup popup>> eq?
71 [ f >>popup request-focus drop ] [ 2drop ] if ;
76 { T{ key-down f f "ESC" } [ hide-glass ] }
79 : pass-to-popup ( gesture owner -- ? )
80 popup>> focusable-child resend-gesture ;
82 : show-popup ( owner popup visible-rect -- )
83 [ [ dup dup popup>> [ hide-glass ] when* ] dip <popup> ] dip
84 [ drop >>popup drop ] [ show-glass ] 3bi ;