- special completion for USE:/IN:\r
- vectors: ensure its ok with bignum indices\r
- if gadgets are moved, added or deleted, update hand.\r
-- keyboard gestures\r
-- text fields\r
- code gc\r
- type inference fails with some assembler words;\r
displaced, register and other predicates need to inherit from list\r
- ppc register decls\r
- rename f* words to stream-*\r
\r
+- resize window: world not updated until mouse moved\r
+- x>offset\r
+- fix completion invoke in middle of word\r
+- html: word links\r
+- don't hardcode so many colors\r
- ffi unicode strings: null char security hole\r
- utf16 string boxing\r
- slot compile problem\r
"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 <field> "pile" get add-gadget
- "Welcome to Factor " version cat2 <field> "pile" get add-gadget
+ "A field." <field> "pile" get add-gadget
+ "Another field." <field> "pile" get add-gadget
"pile" get bevel-border dup "dialog" set dup
moving-actions
#! fire an action gesture.
dup button-update
dup mouse-over? [
- [ action ] swap handle-gesture
+ [ action ] swap handle-gesture drop
] [
drop
] ifte ;
world get redraw ;
: button-gesture ( button gesture -- [ gesture button ] )
- swap unit append my-hand hand-clicked handle-gesture ;
+ swap unit append my-hand hand-clicked handle-gesture drop ;
M: button-down-event handle-event ( event -- )
button-event-button dup my-hand button/
motion-event-pos my-hand move-hand ;
M: key-down-event handle-event ( event -- )
- keyboard-event>binding my-hand hand-focus handle-gesture ;
+ dup keyboard-event>binding
+ my-hand hand-focus handle-gesture [
+ keyboard-event-unicode dup 0 = [
+ drop
+ ] [
+ my-hand hand-focus user-input drop
+ ] ifte
+ ] [
+ drop
+ ] ifte ;
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
-USING: generic kernel lists math namespaces sdl line-editor ;
+USING: generic kernel lists math namespaces sdl line-editor
+strings ;
-TUPLE: field active? delegate ;
+TUPLE: field active? editor delegate ;
-TUPLE: editor line delegate ;
+TUPLE: editor line caret delegate ;
: editor-text ( editor -- text )
editor-line [ line-text get ] bind ;
: set-editor-text ( text editor -- )
editor-line [ set-line-text ] bind ;
+: <caret> ( -- caret )
+ 0 0 0 0 <plain-rect> <gadget>
+ dup red background set-paint-property ;
+
C: editor ( text -- )
- 0 0 0 0 <rectangle> <gadget> over set-editor-delegate
+ 0 0 0 0 <line> <gadget> over set-editor-delegate
[ <line-editor> swap set-editor-line ] keep
+ [ <caret> swap set-editor-caret ] keep
[ set-editor-text ] keep ;
-M: editor layout* ( label -- )
- [ editor-text dup shape-w swap shape-h ] keep resize-gadget ;
+: focus-editor ( editor -- )
+ dup editor-caret over add-gadget
+ dup blue foreground set-paint-property relayout ;
+
+: unfocus-editor ( editor -- )
+ dup editor-caret unparent
+ dup black foreground set-paint-property relayout ;
+
+: offset>x ( offset editor -- x )
+ editor-line [ line-text get ] bind str-head
+ font get swap
+ size-string drop ;
+
+: caret-pos ( editor -- x y )
+ dup editor-line [ caret get ] bind swap offset>x 0 ;
+
+: caret-size ( editor -- w h )
+ 0 swap shape-h ;
+
+M: editor layout* ( field -- )
+ dup [ editor-text dup shape-w swap shape-h ] keep resize-gadget
+ dup editor-caret over caret-size rot resize-gadget
+ dup editor-caret swap caret-pos rot move-gadget ;
M: editor draw-shape ( label -- )
dup [ editor-text draw-shape ] with-translation ;
: field-border ( gadget -- border )
bevel-border dup f bevel-up? set-paint-property ;
-C: field ( text -- field )
- [ >r <editor> field-border r> set-field-delegate ] keep
+: with-field-editor ( field quot -- )
+ swap field-editor [ editor-line swap bind ] keep relayout ;
+
+M: field user-input* ( ch field -- ? )
+ [ insert-char ] with-field-editor f ;
+
+: click-field ( field -- )
+ my-hand request-focus ;
+
+: field-gestures ( -- hash )
{{
- [[ [ gain-focus ] [ dup blue foreground set-paint-property redraw ] ]]
- [[ [ lose-focus ] [ dup black foreground set-paint-property redraw ] ]]
- [[ [ button-down 1 ] [ my-hand request-focus ] ]]
- [[ [ "RETURN" ] [ drop "foo!" USE: stdio print ] ]]
- [[ [ "BACKSPACE" ] [ dup gadget-children car editor-line [ backspace ] bind redraw ] ]]
- }} over set-gadget-gestures ;
+ [[ [ gain-focus ] [ field-editor focus-editor ] ]]
+ [[ [ lose-focus ] [ field-editor unfocus-editor ] ]]
+ [[ [ button-down 1 ] [ click-field ] ]]
+ [[ [ "BACKSPACE" ] [ [ backspace ] with-field-editor ] ]]
+ [[ [ "LEFT" ] [ [ left ] with-field-editor ] ]]
+ [[ [ "RIGHT" ] [ [ right ] with-field-editor ] ]]
+ [[ [ "CTRL" "k" ] [ [ line-clear ] with-field-editor ] ]]
+ }} ;
+
+C: field ( text -- field )
+ #! Note that we want the editor's parent to be the field,
+ #! not the border.
+ [ f field-border swap set-field-delegate ] keep
+ [ >r <editor> dup r> set-field-editor ] keep
+ [ add-gadget ] keep
+ [ field-gestures swap set-gadget-gestures ] keep ;
tuck (add-gadget)
relayout ;
-: each-parent ( gadget quot -- )
+: each-parent ( gadget quot -- ? )
#! Apply quotation to each parent of the gadget in turn,
- #! stopping when the quotation returns f.
+ #! stopping when the quotation returns f. Return f if a
+ #! quotation somewhere returned f; if the search bottoms
+ #! out, return t.
over [
[ call ] 2keep rot [
>r gadget-parent r> each-parent
] [
- 2drop
+ 2drop f ( quotation returns f )
] ifte
] [
- 2drop
+ 2drop t ( search bottomed out )
] ifte ; inline
: screen-pos ( gadget -- point )
#! The position of the gadget on the screen.
- 0 swap [ shape-pos + t ] each-parent ;
+ 0 swap [ shape-pos + t ] each-parent drop ;
: child? ( parent child -- ? )
dup [
2drop t
] ifte ;
-: handle-gesture ( gesture gadget -- )
+: handle-gesture ( gesture gadget -- ? )
#! If a gadget's handle-gesture* generic returns t, the
#! event was not consumed and is passed on to the gadget's
- #! parent.
- [ dupd handle-gesture* ] each-parent drop ;
+ #! parent. This word returns t if no gadget handled the
+ #! gesture, otherwise returns f.
+ [ dupd handle-gesture* ] each-parent nip ;
+
+GENERIC: user-input* ( ch gadget -- ? )
+M: gadget user-input* 2drop f ;
+
+: user-input ( ch gadget -- ? )
+ [ dupd user-input* ] each-parent nip ;
! Mouse gestures are lists where the first element is one of:
SYMBOL: motion
[
[ shape-pos + ] keep
2dup inside? [ mouse-enter ] hierarchy-gesture
- ] each-parent drop ;
+ ] each-parent 2drop ;
: mouse-leave ( point gadget -- )
#! If the new point is inside the old gadget, do not fire a
[
[ shape-pos + ] keep
2dup inside? [ mouse-leave ] hierarchy-gesture
- ] each-parent drop ;
+ ] each-parent 2drop ;
: lose-focus ( new old -- )
#! If the old focus owner is a child of the new owner, do
#! parent.
[
2dup child? [ lose-focus ] hierarchy-gesture
- ] each-parent drop ;
+ ] each-parent 2drop ;
: gain-focus ( old new -- )
#! If the old focus owner is a child of the new owner, do
#! to the parent.
[
2dup child? [ gain-focus ] hierarchy-gesture
- ] each-parent drop ;
+ ] each-parent 2drop ;
dup world get pick-up swap set-hand-gadget ;
: fire-motion ( hand -- )
- [ motion ] swap hand-gadget handle-gesture ;
+ [ motion ] swap hand-gadget handle-gesture drop ;
: move-hand ( x y hand -- )
dup shape-pos >r