basic notion of keyboard focus
parent
b05ad02a1d
commit
8d565b6968
|
@ -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 ( -- )
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 ;
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue