basic notion of keyboard focus

cvs
Slava Pestov 2005-02-11 17:45:24 +00:00
parent b05ad02a1d
commit 8d565b6968
13 changed files with 32 additions and 20 deletions

View File

@ -36,10 +36,20 @@ USE: stdio
USE: prettyprint USE: prettyprint
USE: words USE: words
: grab ( gadget hand -- )
[ swap screen-pos swap screen-pos - >rect ] 2keep
>r [ move-gadget ] keep r> add-gadget ;
: release ( gadget world -- )
>r dup screen-pos >r
dup unparent
r> >rect pick move-gadget
r> add-gadget ;
: moving-actions : moving-actions
{{ {{
[[ [ button-down 1 ] [ 0 0 pick move-gadget my-hand add-gadget ] ]] [[ [ button-down 1 ] [ my-hand grab ] ]]
[[ [ button-up 1 ] [ my-hand shape-x my-hand shape-y pick move-gadget world get add-gadget ] ]] [[ [ button-up 1 ] [ world get release ] ]]
}} swap set-gadget-gestures ; }} swap set-gadget-gestures ;
: filled? "filled" get checkbox-selected? ; : filled? "filled" get checkbox-selected? ;
@ -65,12 +75,11 @@ USE: words
"Filled?" <checkbox> dup "filled" set "shelf" get add-gadget "Filled?" <checkbox> dup "filled" set "shelf" get add-gadget
"shelf" get "pile" get add-gadget "shelf" get "pile" get add-gadget
"Welcome to Factor " version cat2 <label> "pile" get add-gadget "Welcome to Factor " version cat2 <label> "pile" get add-gadget
"Welcome to Factor " version cat2 <label> <field> "pile" get add-gadget
"Welcome to Factor " version cat2 <label> <field> "pile" get add-gadget
"pile" get bevel-border dup "dialog" set dup "pile" get bevel-border dup "dialog" set dup
{{ moving-actions
[[ [ button-down 1 ] [ dup unparent 0 0 pick move-gadget my-hand add-gadget ] ]]
[[ [ button-up 1 ] [ my-hand shape-x my-hand shape-y pick move-gadget world get add-gadget ] ]]
}} swap set-gadget-gestures
world get add-gadget ; world get add-gadget ;
: gadget-demo ( -- ) : gadget-demo ( -- )

BIN
fonts/Vera.ttf Normal file

Binary file not shown.

BIN
fonts/VeraBI.ttf Normal file

Binary file not shown.

BIN
fonts/VeraBd.ttf Normal file

Binary file not shown.

BIN
fonts/VeraIt.ttf Normal file

Binary file not shown.

BIN
fonts/VeraSe.ttf Normal file

Binary file not shown.

BIN
fonts/VeraSeBd.ttf Normal file

Binary file not shown.

View File

@ -162,6 +162,7 @@ cpu "x86" = [
"/library/ui/world.factor" "/library/ui/world.factor"
"/library/ui/labels.factor" "/library/ui/labels.factor"
"/library/ui/buttons.factor" "/library/ui/buttons.factor"
"/library/ui/fields.factor"
"/library/ui/events.factor" "/library/ui/events.factor"
] [ ] [
dup print dup print

View File

@ -129,6 +129,8 @@ SYMBOL: logical-fonts
global [ global [
{{ {{
[[ "Monospaced" "/fonts/VeraMono.ttf" ]] [[ "Monospaced" "/fonts/VeraMono.ttf" ]]
[[ "Serif" "/fonts/VeraSe.ttf" ]]
[[ "Sans Serif" "/fonts/Vera.ttf" ]]
}} logical-fonts set }} logical-fonts set
] bind ] bind

View File

@ -59,11 +59,11 @@ C: gadget ( shape -- gadget )
: each-parent ( gadget quot -- ) : each-parent ( gadget quot -- )
#! Apply quotation to each parent of the gadget in turn, #! Apply quotation to each parent of the gadget in turn,
#! stopping when the quotation returns f. #! stopping when the quotation returns f.
over [
[ call ] 2keep rot [ [ call ] 2keep rot [
>r gadget-parent dup [ >r gadget-parent r> each-parent
r> each-parent
] [ ] [
r> 2drop 2drop
] ifte ] ifte
] [ ] [
2drop 2drop

View File

@ -52,7 +52,7 @@ SYMBOL: button-down
2dup inside? [ mouse-leave ] hierarchy-gesture 2dup inside? [ mouse-leave ] hierarchy-gesture
] each-parent drop ; ] each-parent drop ;
: lose-focus ( old new -- ) : lose-focus ( new old -- )
#! If the old focus owner is a child of the new owner, do #! If the old focus owner is a child of the new owner, do
#! not fire a focus lost gesture, since the focus was not #! not fire a focus lost gesture, since the focus was not
#! lost. Otherwise, fire a focus lost gesture and go to the #! lost. Otherwise, fire a focus lost gesture and go to the

View File

@ -86,7 +86,7 @@ C: hand ( world -- hand )
r> swap fire-enter ; r> swap fire-enter ;
: request-focus ( gadget -- ) : request-focus ( gadget -- )
my-hand hand-focus swap my-hand hand-focus
2dup lose-focus 2dup lose-focus
2dup my-hand set-hand-focus swap dup my-hand set-hand-focus
gain-focus ; gain-focus ;

View File

@ -68,13 +68,13 @@ DEFER: handle-event
global [ global [
<world> world set <world> world set
640 480 world get resize-gadget 1024 768 world get resize-gadget
{{ {{
[[ background [ 216 216 216 ] ]] [[ background [ 255 255 255 ] ]]
[[ foreground [ 0 0 0 ] ]] [[ foreground [ 0 0 102 ] ]]
[[ bevel-1 [ 240 240 240 ] ]] [[ bevel-1 [ 224 224 255 ] ]]
[[ bevel-2 [ 192 192 192 ] ]] [[ bevel-2 [ 192 192 216 ] ]]
[[ bevel-up? t ]] [[ bevel-up? t ]]
[[ font [[ "Monospaced" 12 ]] ]] [[ font [[ "Sans Serif" 14 ]] ]]
}} world get set-gadget-paint }} world get set-gadget-paint
] bind ] bind