diff --git a/basis/math/rectangles/positioning/positioning-docs.factor b/basis/math/rectangles/positioning/positioning-docs.factor new file mode 100644 index 0000000000..f5eb4f079d --- /dev/null +++ b/basis/math/rectangles/positioning/positioning-docs.factor @@ -0,0 +1,13 @@ +USING: help.markup help.syntax math.rectangles ; +IN: math.rectangles.positioning + +HELP: popup-rect +{ $values { "visible-rect" rect } { "popup-dim" "a pair of real numbers" } { "screen-dim" "a pair of real numbers" } { "rect" rect } } +{ $description "Calculates the position of a popup with a heuristic:" + { $list + { "The new rectangle must fit inside " { $snippet "screen-dim" } } + { "The new rectangle must not obscure " { $snippet "visible-rect" } } + { "The child must otherwise be as close as possible to the edges of " { $snippet "visible-rect" } } + } + "For example, when displaying a menu, " { $snippet "visible-rect" } " is a single point at the mouse location, and when displaying a completion popup, " { $snippet "visible-rect" } " contains the bounds of the text element being completed." +} ; diff --git a/basis/math/rectangles/positioning/positioning-tests.factor b/basis/math/rectangles/positioning/positioning-tests.factor index a292775494..55ed7147d8 100644 --- a/basis/math/rectangles/positioning/positioning-tests.factor +++ b/basis/math/rectangles/positioning/positioning-tests.factor @@ -4,50 +4,57 @@ USING: tools.test math.rectangles math.rectangles.positioning ; IN: math.rectangles.positioning.tests [ T{ rect f { 0 1 } { 30 30 } } ] [ - { 0 0 } { 1 1 } + T{ rect f { 0 0 } { 1 1 } } { 30 30 } { 100 100 } popup-rect ] unit-test [ T{ rect f { 10 21 } { 30 30 } } ] [ - { 10 20 } { 1 1 } + T{ rect f { 10 20 } { 1 1 } } { 30 30 } { 100 100 } popup-rect ] unit-test [ T{ rect f { 10 30 } { 30 30 } } ] [ - { 10 20 } { 1 10 } + T{ rect f { 10 20 } { 1 10 } } { 30 30 } { 100 100 } popup-rect ] unit-test [ T{ rect f { 20 20 } { 80 30 } } ] [ - { 40 10 } { 1 10 } + T{ rect f { 40 10 } { 1 10 } } { 80 30 } { 100 100 } popup-rect ] unit-test [ T{ rect f { 50 20 } { 50 50 } } ] [ - { 50 70 } { 0 0 } + T{ rect f { 50 70 } { 0 0 } } { 50 50 } { 100 100 } popup-rect ] unit-test [ T{ rect f { 0 20 } { 50 50 } } ] [ - { -50 70 } { 0 0 } + T{ rect f { -50 70 } { 0 0 } } { 50 50 } { 100 100 } popup-rect ] unit-test [ T{ rect f { 0 50 } { 50 50 } } ] [ - { 0 50 } { 0 0 } + T{ rect f { 0 50 } { 0 0 } } { 50 60 } { 100 100 } popup-rect +] unit-test + +[ T{ rect f { 0 90 } { 10 10 } } ] [ + T{ rect f { 0 1000 } { 0 0 } } + { 10 10 } + { 100 100 } + popup-rect ] unit-test \ No newline at end of file diff --git a/basis/math/rectangles/positioning/positioning.factor b/basis/math/rectangles/positioning/positioning.factor index 4b1a60a627..6b1348ca88 100644 --- a/basis/math/rectangles/positioning/positioning.factor +++ b/basis/math/rectangles/positioning/positioning.factor @@ -1,13 +1,18 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: sequences kernel accessors math math.vectors -math.rectangles math.order arrays locals +math.rectangles math.order arrays locals fry combinators.short-circuit ; IN: math.rectangles.positioning ! Some geometry code for positioning popups and menus ! in a semi-intelligent manner +> first ] 2dip swap [ first ] bi@ - min 0 max ; @@ -33,5 +38,8 @@ IN: math.rectangles.positioning :: popup-dim ( loc popup-dim screen-dim -- dim ) screen-dim loc v- popup-dim vmin ; +PRIVATE> + : popup-rect ( visible-rect popup-dim screen-dim -- rect ) + [ adjust-visible-rect ] 2keep [ popup-loc dup ] 2keep popup-dim ; \ No newline at end of file diff --git a/basis/ui/tools/browser/browser.factor b/basis/ui/tools/browser/browser.factor index d3aa56a694..3d590feb58 100644 --- a/basis/ui/tools/browser/browser.factor +++ b/basis/ui/tools/browser/browser.factor @@ -83,8 +83,8 @@ M: browser-gadget handle-gesture } 2|| ; M: browser-gadget definitions-changed ( assoc browser -- ) - model>> [ value>> swap showing-definition? ] keep - '[ _ notify-connections ] when ; + [ model>> value>> swap showing-definition? ] keep + '[ _ [ history-value ] keep set-history-value ] when ; M: browser-gadget focusable-child* search-field>> ; diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 4accabb8d6..de49a339c9 100755 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -535,9 +535,13 @@ PRIVATE> : last-index-from ( obj i seq -- n ) rot [ = ] curry find-last-from drop ; + + : indices ( obj seq -- indices ) swap V{ } clone [ [ (indices) ] 2curry each-index ] keep ;