USE: prettyprint
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
{{
- [[ [ button-down 1 ] [ 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 ] ]]
+ [[ [ button-down 1 ] [ my-hand grab ] ]]
+ [[ [ button-up 1 ] [ world get release ] ]]
}} swap set-gadget-gestures ;
: filled? "filled" get checkbox-selected? ;
"Filled?" <checkbox> dup "filled" set "shelf" 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> <field> "pile" get add-gadget
+ "Welcome to Factor " version cat2 <label> <field> "pile" get add-gadget
"pile" get bevel-border dup "dialog" set dup
- {{
- [[ [ 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
+ moving-actions
world get add-gadget ;
: gadget-demo ( -- )
"/library/ui/world.factor"\r
"/library/ui/labels.factor"\r
"/library/ui/buttons.factor"\r
+ "/library/ui/fields.factor"\r
"/library/ui/events.factor"\r
] [\r
dup print\r
global [
{{
[[ "Monospaced" "/fonts/VeraMono.ttf" ]]
+ [[ "Serif" "/fonts/VeraSe.ttf" ]]
+ [[ "Sans Serif" "/fonts/Vera.ttf" ]]
}} logical-fonts set
] bind
: each-parent ( gadget quot -- )
#! Apply quotation to each parent of the gadget in turn,
#! stopping when the quotation returns f.
- [ call ] 2keep rot [
- >r gadget-parent dup [
- r> each-parent
+ over [
+ [ call ] 2keep rot [
+ >r gadget-parent r> each-parent
] [
- r> 2drop
+ 2drop
] ifte
- ] [
+ ] [
2drop
] ifte ; inline
2dup inside? [ mouse-leave ] hierarchy-gesture
] each-parent drop ;
-: lose-focus ( old new -- )
+: lose-focus ( new old -- )
#! If the old focus owner is a child of the new owner, do
#! not fire a focus lost gesture, since the focus was not
#! lost. Otherwise, fire a focus lost gesture and go to the
r> swap fire-enter ;
: request-focus ( gadget -- )
- my-hand hand-focus swap
+ my-hand hand-focus
2dup lose-focus
- 2dup my-hand set-hand-focus
+ swap dup my-hand set-hand-focus
gain-focus ;
global [
<world> world set
- 640 480 world get resize-gadget
+ 1024 768 world get resize-gadget
{{
- [[ background [ 216 216 216 ] ]]
- [[ foreground [ 0 0 0 ] ]]
- [[ bevel-1 [ 240 240 240 ] ]]
- [[ bevel-2 [ 192 192 192 ] ]]
+ [[ background [ 255 255 255 ] ]]
+ [[ foreground [ 0 0 102 ] ]]
+ [[ bevel-1 [ 224 224 255 ] ]]
+ [[ bevel-2 [ 192 192 216 ] ]]
[[ bevel-up? t ]]
- [[ font [[ "Monospaced" 12 ]] ]]
+ [[ font [[ "Sans Serif" 14 ]] ]]
}} world get set-gadget-paint
] bind