Merge branch 'master' of git://factorcode.org/git/factor

db4
Joe Groff 2009-09-08 17:04:44 -05:00
commit 7be557d100
5 changed files with 42 additions and 10 deletions

View File

@ -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."
} ;

View File

@ -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 } <rect>
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 } <rect>
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 } <rect>
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 } <rect>
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 } <rect>
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 } <rect>
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 } <rect>
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

View File

@ -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
<PRIVATE
: adjust-visible-rect ( visible-rect popup-dim screen-dim -- visible-rect' )
[ drop clone ] dip '[ _ vmin ] change-loc ;
: popup-x ( visible-rect popup-dim screen-dim -- x )
[ loc>> 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 <rect> ;

View File

@ -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>> ;

View File

@ -535,9 +535,13 @@ PRIVATE>
: last-index-from ( obj i seq -- n )
rot [ = ] curry find-last-from drop ;
<PRIVATE
: (indices) ( elt i obj accum -- )
[ swap [ = ] dip ] dip [ push ] 2curry when ; inline
PRIVATE>
: indices ( obj seq -- indices )
swap V{ } clone
[ [ (indices) ] 2curry each-index ] keep ;