From 9a351fce2209f4038a5e43e0255c2db1ea71ec8c Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 13 Feb 2009 00:59:28 -0600 Subject: [PATCH] Refactor ui.gadgets.glass to correctly position debugger popup --- basis/ui/gadgets/glass/glass.factor | 51 ++++++++++++++------ basis/ui/gadgets/menus/menus.factor | 15 ++---- basis/ui/tools/listener/popups/popups.factor | 18 +++---- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/basis/ui/gadgets/glass/glass.factor b/basis/ui/gadgets/glass/glass.factor index 17b3478391..52daa2ba7d 100644 --- a/basis/ui/gadgets/glass/glass.factor +++ b/basis/ui/gadgets/glass/glass.factor @@ -1,32 +1,51 @@ ! Copyright (C) 2005, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel namespaces ui.gadgets ui.gadgets.worlds -ui.gestures ; +ui.gestures math.rectangles math.rectangles.positioning +combinators ; IN: ui.gadgets.glass GENERIC: hide-glass-hook ( gadget -- ) M: gadget hide-glass-hook drop ; -TUPLE: glass < gadget ; - -: ( child loc -- glass ) - >>loc glass new-gadget swap add-gadget ; - -M: glass layout* gadget-child prefer ; - -M: glass ungraft* gadget-child hide-glass-hook ; - : hide-glass ( world -- ) [ [ unparent ] when* f ] change-glass drop ; -: show-glass ( world child loc -- ) - - [ [ hide-glass ] [ hand-clicked set-global ] bi* ] - [ [ add-gadget ] [ >>glass ] bi drop ] - 2bi ; + ( owner child visible-rect -- glass ) + glass new-gadget + swap >>visible-rect + swap add-gadget + swap >>owner ; + +: visible-rect ( glass -- rect ) + [ visible-rect>> ] [ owner>> ] bi screen-loc offset-rect ; + +M: glass layout* + { + [ gadget-child ] + [ visible-rect ] + [ gadget-child pref-dim ] + [ find-world dim>> ] + } cleave popup-loc >>loc prefer ; + +M: glass ungraft* gadget-child hide-glass-hook ; + +: add-glass ( glass world -- ) + dup hide-glass swap [ add-gadget ] [ >>glass ] bi drop ; \ glass H{ { T{ button-down } [ find-world [ hide-glass ] when* ] } { T{ drag } [ update-clicked drop ] } -} set-gestures \ No newline at end of file +} set-gestures + +PRIVATE> + +: show-glass ( owner child visible-rect -- ) + + dup gadget-child hand-clicked set + dup owner>> find-world add-glass ; \ No newline at end of file diff --git a/basis/ui/gadgets/menus/menus.factor b/basis/ui/gadgets/menus/menus.factor index 3c2caf6520..de777517c5 100644 --- a/basis/ui/gadgets/menus/menus.factor +++ b/basis/ui/gadgets/menus/menus.factor @@ -1,18 +1,13 @@ ! Copyright (C) 2005, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: locals accessors kernel math namespaces sequences math.vectors -math.rectangles.positioning colors colors.constants math.rectangles -ui.commands ui.operations ui.gadgets ui.gadgets.buttons -ui.gadgets.worlds ui.gestures ui.gadgets.theme ui.gadgets.packs -ui.gadgets.glass ui.gadgets.borders ; +USING: colors.constants kernel locals math.rectangles +namespaces sequences ui.commands ui.gadgets ui.gadgets.borders +ui.gadgets.buttons ui.gadgets.glass ui.gadgets.packs +ui.gadgets.theme ui.gadgets.worlds ui.gestures ui.operations ; IN: ui.gadgets.menus -: menu-loc ( world menu -- loc ) - [ hand-loc get { 0 0 } ] 2dip - pref-dim swap dim>> popup-loc ; - : show-menu ( owner menu -- ) - [ find-world ] dip 2dup menu-loc show-glass ; + [ find-world ] dip hand-loc get { 0 0 } show-glass ; :: ( target hook command -- button ) command command-name [ diff --git a/basis/ui/tools/listener/popups/popups.factor b/basis/ui/tools/listener/popups/popups.factor index 18415f34c3..6bb23e41a8 100644 --- a/basis/ui/tools/listener/popups/popups.factor +++ b/basis/ui/tools/listener/popups/popups.factor @@ -26,25 +26,19 @@ popup H{ } set-gestures : caret-loc ( interactor element -- loc ) - [ drop screen-loc ] [ - [ - [ [ editor-caret ] [ model>> ] bi ] dip - prev-elt - ] [ drop ] 2bi - loc>point - ] 2bi v+ ; + [ + [ [ editor-caret ] [ model>> ] bi ] dip + prev-elt + ] [ drop ] 2bi + loc>point ; : relevant-rect ( popup -- rect ) [ interactor>> ] [ element>> ] bi [ caret-loc ] [ drop caret-dim { 0 1 } v+ ] 2bi ; -: listener-popup-loc ( popup -- loc ) - [ relevant-rect ] [ pref-dim ] [ interactor>> find-world dim>> ] tri - popup-loc ; - : show-popup ( interactor element popup -- ) [ dup interactor>> (>>popup) ] - [ [ interactor>> find-world ] [ ] [ listener-popup-loc ] tri show-glass ] + [ [ interactor>> ] [ ] [ relevant-rect ] tri show-glass ] bi ; \ No newline at end of file