New gesture handling style
parent
5c4f5951b5
commit
126a5186d8
|
@ -90,7 +90,6 @@ listener-gadget-scroller 4 slot ;
|
||||||
- display lists
|
- display lists
|
||||||
- saving the image should save window configuration
|
- saving the image should save window configuration
|
||||||
- variable width word wrap
|
- variable width word wrap
|
||||||
- new gesture style
|
|
||||||
|
|
||||||
+ compiler/ffi:
|
+ compiler/ffi:
|
||||||
|
|
||||||
|
|
|
@ -5,21 +5,20 @@ kernel ;
|
||||||
|
|
||||||
TUPLE: apropos-gadget scroller input ;
|
TUPLE: apropos-gadget scroller input ;
|
||||||
|
|
||||||
: apropos-pane ( gadget -- pane )
|
: apropos-gadget-pane ( apropos -- pane )
|
||||||
[ apropos-gadget? ] find-parent
|
|
||||||
apropos-gadget-scroller scroller-gadget ;
|
apropos-gadget-scroller scroller-gadget ;
|
||||||
|
|
||||||
: <prompt> ( quot -- editor )
|
|
||||||
"" <editor> [
|
|
||||||
swap T{ key-down f f "RETURN" } set-action
|
|
||||||
] keep ;
|
|
||||||
|
|
||||||
: show-apropos ( editor -- )
|
|
||||||
dup commit-editor-text
|
|
||||||
swap apropos-pane [ apropos ] with-pane ;
|
|
||||||
|
|
||||||
: <apropos-prompt> ( -- gadget )
|
: <apropos-prompt> ( -- gadget )
|
||||||
[ show-apropos ] <prompt> dup faint-boundary ;
|
"" <editor> dup faint-boundary ;
|
||||||
|
|
||||||
|
: show-apropos ( apropos -- )
|
||||||
|
dup apropos-gadget-input commit-editor-text
|
||||||
|
swap apropos-gadget-pane [ apropos ] with-pane ;
|
||||||
|
|
||||||
|
M: apropos-gadget gadget-gestures
|
||||||
|
drop H{
|
||||||
|
{ T{ key-down f f "RETURN" } [ show-apropos ] }
|
||||||
|
} ;
|
||||||
|
|
||||||
C: apropos-gadget ( -- )
|
C: apropos-gadget ( -- )
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,16 +27,17 @@ TUPLE: button rollover? pressed? quot ;
|
||||||
: button-clicked ( button -- )
|
: button-clicked ( button -- )
|
||||||
dup button-quot if-clicked ;
|
dup button-quot if-clicked ;
|
||||||
|
|
||||||
: button-gestures ( button quot -- )
|
M: button gadget-gestures
|
||||||
over set-button-quot
|
drop H{
|
||||||
dup [ button-clicked ] T{ button-up } set-action
|
{ T{ button-up } [ button-clicked ] }
|
||||||
dup [ button-update ] T{ button-down } set-action
|
{ T{ button-down } [ button-update ] }
|
||||||
dup [ button-update ] T{ mouse-leave } set-action
|
{ T{ mouse-leave } [ button-update ] }
|
||||||
[ button-update ] T{ mouse-enter } set-action ;
|
{ T{ mouse-enter } [ button-update ] }
|
||||||
|
} ;
|
||||||
|
|
||||||
C: button ( gadget quot -- button )
|
C: button ( gadget quot -- button )
|
||||||
rot <default-border> over set-gadget-delegate
|
rot <default-border> over set-gadget-delegate
|
||||||
[ swap button-gestures ] keep ;
|
[ set-button-quot ] keep ;
|
||||||
|
|
||||||
: <highlight-button> ( gadget quot -- button )
|
: <highlight-button> ( gadget quot -- button )
|
||||||
<button> { 0 0 0 } over set-border-size ;
|
<button> { 0 0 0 } over set-border-size ;
|
||||||
|
@ -53,16 +54,22 @@ C: button ( gadget quot -- button )
|
||||||
: repeat-button-up ( button -- )
|
: repeat-button-up ( button -- )
|
||||||
dup button-update remove-timer ;
|
dup button-update remove-timer ;
|
||||||
|
|
||||||
: repeat-actions ( button -- )
|
TUPLE: repeat-button ;
|
||||||
dup [ repeat-button-down ] T{ button-down } set-action
|
|
||||||
[ repeat-button-up ] T{ button-up } set-action ;
|
|
||||||
|
|
||||||
: <repeat-button> ( gadget quot -- button )
|
M: repeat-button gadget-gestures
|
||||||
|
drop H{
|
||||||
|
{ T{ button-down } [ repeat-button-down ] }
|
||||||
|
{ T{ button-up } [ repeat-button-up ] }
|
||||||
|
{ T{ mouse-leave } [ button-update ] }
|
||||||
|
{ T{ mouse-enter } [ button-update ] }
|
||||||
|
} ;
|
||||||
|
|
||||||
|
C: repeat-button ( gadget quot -- button )
|
||||||
#! Button that calls the quotation every 100ms as long as
|
#! Button that calls the quotation every 100ms as long as
|
||||||
#! the mouse is held down.
|
#! the mouse is held down.
|
||||||
<bevel-button> dup repeat-actions ;
|
[ >r <bevel-button> r> set-gadget-delegate ] keep ;
|
||||||
|
|
||||||
M: button tick ( ms object -- ) nip button-clicked ;
|
M: repeat-button tick ( ms object -- ) nip button-clicked ;
|
||||||
|
|
||||||
TUPLE: button-paint plain rollover pressed ;
|
TUPLE: button-paint plain rollover pressed ;
|
||||||
|
|
||||||
|
|
|
@ -74,35 +74,11 @@ TUPLE: editor line caret font color ;
|
||||||
: click-editor ( editor -- )
|
: click-editor ( editor -- )
|
||||||
dup hand-click-rel first over set-caret-x request-focus ;
|
dup hand-click-rel first over set-caret-x request-focus ;
|
||||||
|
|
||||||
: popup-location ( editor -- loc )
|
M: editor gadget-gestures
|
||||||
dup screen-loc swap editor-caret rect-extent nip v+ ;
|
drop H{
|
||||||
|
{ T{ button-down } [ click-editor ] }
|
||||||
: <completion-item> ( completion editor -- menu-item )
|
|
||||||
dupd [ [ complete ] with-editor drop ] curry curry 2array ;
|
|
||||||
|
|
||||||
! : <completion-menu> ( editor completions -- menu )
|
|
||||||
! [ swap <completion-item> ] map-with <menu> ;
|
|
||||||
|
|
||||||
: completion-menu ( editor completions -- )
|
|
||||||
2drop ;
|
|
||||||
! over popup-location -rot
|
|
||||||
! over >r <completion-menu> r> show-menu ;
|
|
||||||
|
|
||||||
: do-completion-1 ( editor completions -- )
|
|
||||||
swap [ first complete ] with-editor ;
|
|
||||||
|
|
||||||
: do-completion ( editor -- )
|
|
||||||
dup [ line-completions ] with-editor {
|
|
||||||
{ [ dup empty? ] [ 2drop ] }
|
|
||||||
{ [ dup length 1 = ] [ do-completion-1 ] }
|
|
||||||
{ [ t ] [ completion-menu ] }
|
|
||||||
} cond ;
|
|
||||||
|
|
||||||
: editor-actions ( editor -- )
|
|
||||||
H{
|
|
||||||
{ T{ gain-focus } [ focus-editor ] }
|
{ T{ gain-focus } [ focus-editor ] }
|
||||||
{ T{ lose-focus } [ unfocus-editor ] }
|
{ T{ lose-focus } [ unfocus-editor ] }
|
||||||
{ T{ button-down } [ click-editor ] }
|
|
||||||
{ T{ key-down f f "BACKSPACE" } [ [ T{ char-elt } delete-prev-elt ] with-editor ] }
|
{ T{ key-down f f "BACKSPACE" } [ [ T{ char-elt } delete-prev-elt ] with-editor ] }
|
||||||
{ T{ key-down f f "DELETE" } [ [ T{ char-elt } delete-next-elt ] with-editor ] }
|
{ T{ key-down f f "DELETE" } [ [ T{ char-elt } delete-next-elt ] with-editor ] }
|
||||||
{ T{ key-down f { C+ } "BACKSPACE" } [ [ T{ word-elt } delete-prev-elt ] with-editor ] }
|
{ T{ key-down f { C+ } "BACKSPACE" } [ [ T{ word-elt } delete-prev-elt ] with-editor ] }
|
||||||
|
@ -117,15 +93,14 @@ TUPLE: editor line caret font color ;
|
||||||
{ T{ key-down f f "END" } [ [ T{ document-elt } next-elt ] with-editor ] }
|
{ T{ key-down f f "END" } [ [ T{ document-elt } next-elt ] with-editor ] }
|
||||||
{ T{ key-down f { C+ } "k" } [ [ line-clear ] with-editor ] }
|
{ T{ key-down f { C+ } "k" } [ [ line-clear ] with-editor ] }
|
||||||
{ T{ key-down f f "TAB" } [ do-completion ] }
|
{ T{ key-down f f "TAB" } [ do-completion ] }
|
||||||
} add-actions ;
|
} ;
|
||||||
|
|
||||||
C: editor ( text -- )
|
C: editor ( text -- )
|
||||||
dup delegate>gadget
|
dup delegate>gadget
|
||||||
dup editor-theme
|
dup editor-theme
|
||||||
<line-editor> over set-editor-line
|
<line-editor> over set-editor-line
|
||||||
<caret> over set-editor-caret
|
<caret> over set-editor-caret
|
||||||
[ set-editor-text ] keep
|
[ set-editor-text ] keep ;
|
||||||
dup editor-actions ;
|
|
||||||
|
|
||||||
: offset>x ( gadget offset str -- x )
|
: offset>x ( gadget offset str -- x )
|
||||||
head-slice >r label-font* r> string-width ;
|
head-slice >r label-font* r> string-width ;
|
||||||
|
|
|
@ -42,8 +42,7 @@ M: array rect-dim drop { 0 0 0 } ;
|
||||||
|
|
||||||
TUPLE: gadget
|
TUPLE: gadget
|
||||||
pref-dim parent children orientation
|
pref-dim parent children orientation
|
||||||
gestures visible? relayout? root?
|
visible? relayout? root? interior boundary ;
|
||||||
interior boundary ;
|
|
||||||
|
|
||||||
: show-gadget t swap set-gadget-visible? ;
|
: show-gadget t swap set-gadget-visible? ;
|
||||||
|
|
||||||
|
|
|
@ -4,21 +4,12 @@ IN: gadgets
|
||||||
USING: gadgets-labels gadgets-layouts hashtables kernel math
|
USING: gadgets-labels gadgets-layouts hashtables kernel math
|
||||||
namespaces queues sequences threads ;
|
namespaces queues sequences threads ;
|
||||||
|
|
||||||
: action ( gadget gesture -- quot )
|
GENERIC: gadget-gestures ( gadget -- hash )
|
||||||
swap gadget-gestures ?hash ;
|
|
||||||
|
|
||||||
: init-gestures ( gadget -- gestures )
|
M: gadget gadget-gestures drop H{ } ;
|
||||||
dup gadget-gestures
|
|
||||||
[ ] [ H{ } clone dup rot set-gadget-gestures ] ?if ;
|
|
||||||
|
|
||||||
: set-action ( gadget quot gesture -- )
|
: handle-gesture* ( gesture gadget -- )
|
||||||
rot init-gestures set-hash ;
|
tuck gadget-gestures hash [ call f ] [ drop t ] if* ;
|
||||||
|
|
||||||
: add-actions ( gadget hash -- )
|
|
||||||
dup [ >r init-gestures r> hash-update ] [ 2drop ] if ;
|
|
||||||
|
|
||||||
: handle-gesture* ( gesture gadget -- ? )
|
|
||||||
tuck gadget-gestures ?hash dup [ call f ] [ 2drop t ] if ;
|
|
||||||
|
|
||||||
: handle-gesture ( gesture gadget -- ? )
|
: handle-gesture ( gesture gadget -- ? )
|
||||||
#! If a gadget's handle-gesture* generic returns t, the
|
#! If a gadget's handle-gesture* generic returns t, the
|
||||||
|
|
|
@ -12,7 +12,7 @@ prettyprint sequences strings styles threads ;
|
||||||
! current: shelf
|
! current: shelf
|
||||||
! input: editor
|
! input: editor
|
||||||
TUPLE: pane output active current input prototype
|
TUPLE: pane output active current input prototype
|
||||||
continuation scrolls? ;
|
continuation input? ;
|
||||||
|
|
||||||
: add-output 2dup set-pane-output add-gadget ;
|
: add-output 2dup set-pane-output add-gadget ;
|
||||||
|
|
||||||
|
@ -61,24 +61,27 @@ SYMBOL: structured-input
|
||||||
: pane-clear ( pane -- )
|
: pane-clear ( pane -- )
|
||||||
dup pane-output clear-incremental pane-current clear-gadget ;
|
dup pane-output clear-incremental pane-current clear-gadget ;
|
||||||
|
|
||||||
: pane-actions ( line -- )
|
|
||||||
H{
|
|
||||||
{ T{ button-down } [ pane-input click-editor ] }
|
|
||||||
{ T{ key-down f f "RETURN" } [ pane-commit ] }
|
|
||||||
{ T{ key-down f f "UP" } [ pane-input [ history-prev ] with-editor ] }
|
|
||||||
{ T{ key-down f f "DOWN" } [ pane-input [ history-next ] with-editor ] }
|
|
||||||
{ T{ key-down f { C+ } "l" } [ pane-clear ] }
|
|
||||||
} add-actions ;
|
|
||||||
|
|
||||||
C: pane ( -- pane )
|
C: pane ( -- pane )
|
||||||
<pile> over set-delegate
|
<pile> over set-delegate
|
||||||
<shelf> over set-pane-prototype
|
<shelf> over set-pane-prototype
|
||||||
<pile> <incremental> over add-output
|
<pile> <incremental> over add-output
|
||||||
dup prepare-line ;
|
dup prepare-line ;
|
||||||
|
|
||||||
|
M: pane gadget-gestures
|
||||||
|
pane-input [
|
||||||
|
H{
|
||||||
|
{ T{ button-down } [ pane-input click-editor ] }
|
||||||
|
{ T{ key-down f f "RETURN" } [ pane-commit ] }
|
||||||
|
{ T{ key-down f f "UP" } [ pane-input [ history-prev ] with-editor ] }
|
||||||
|
{ T{ key-down f f "DOWN" } [ pane-input [ history-next ] with-editor ] }
|
||||||
|
{ T{ key-down f { C+ } "l" } [ pane-clear ] }
|
||||||
|
}
|
||||||
|
] [
|
||||||
|
H{ }
|
||||||
|
] if ;
|
||||||
|
|
||||||
: <input-pane> ( -- pane )
|
: <input-pane> ( -- pane )
|
||||||
<pane> t over set-pane-scrolls?
|
<pane> "" <editor> over set-pane-input ;
|
||||||
"" <editor> over set-pane-input dup pane-actions ;
|
|
||||||
|
|
||||||
M: pane focusable-child* ( pane -- editor )
|
M: pane focusable-child* ( pane -- editor )
|
||||||
pane-input [ t ] unless* ;
|
pane-input [ t ] unless* ;
|
||||||
|
@ -118,8 +121,7 @@ M: pane stream-flush ( pane -- ) drop ;
|
||||||
M: pane stream-readln ( pane -- line )
|
M: pane stream-readln ( pane -- line )
|
||||||
[ over set-pane-continuation stop ] callcc1 nip ;
|
[ over set-pane-continuation stop ] callcc1 nip ;
|
||||||
|
|
||||||
: scroll-pane ( pane -- )
|
: scroll-pane ( pane -- ) pane-input [ scroll>caret ] when* ;
|
||||||
dup pane-scrolls? [ pane-input scroll>caret ] [ drop ] if ;
|
|
||||||
|
|
||||||
M: pane stream-write1 ( char pane -- )
|
M: pane stream-write1 ( char pane -- )
|
||||||
[ pane-current stream-write1 ] keep scroll-pane ;
|
[ pane-current stream-write1 ] keep scroll-pane ;
|
||||||
|
|
|
@ -25,10 +25,12 @@ TUPLE: scroller viewport x y follows ;
|
||||||
|
|
||||||
: scroll-down-line scroller-y 1 swap slide-by-line ;
|
: scroll-down-line scroller-y 1 swap slide-by-line ;
|
||||||
|
|
||||||
: scroller-actions ( scroller -- )
|
M: scroller gadget-gestures
|
||||||
dup [ scroll-up-line ] T{ wheel-up } set-action
|
drop H{
|
||||||
dup [ scroll-down-line ] T{ wheel-down } set-action
|
{ T{ wheel-up } [ scroll-up-line ] }
|
||||||
[ relayout-1 ] T{ slider-changed } set-action ;
|
{ T{ wheel-down } [ scroll-down-line ] }
|
||||||
|
{ T{ slider-changed } [ relayout-1 ] }
|
||||||
|
} ;
|
||||||
|
|
||||||
C: scroller ( gadget -- scroller )
|
C: scroller ( gadget -- scroller )
|
||||||
#! Wrap a scrolling pane around the gadget.
|
#! Wrap a scrolling pane around the gadget.
|
||||||
|
@ -37,7 +39,6 @@ C: scroller ( gadget -- scroller )
|
||||||
{ [ <x-slider> ] set-scroller-x @bottom }
|
{ [ <x-slider> ] set-scroller-x @bottom }
|
||||||
{ [ <y-slider> ] set-scroller-y @right }
|
{ [ <y-slider> ] set-scroller-y @right }
|
||||||
} make-frame*
|
} make-frame*
|
||||||
dup scroller-actions
|
|
||||||
t over set-gadget-root? ;
|
t over set-gadget-root? ;
|
||||||
|
|
||||||
: set-slider ( value page max slider -- )
|
: set-slider ( value page max slider -- )
|
||||||
|
|
|
@ -52,6 +52,8 @@ TUPLE: slider-changed ;
|
||||||
T{ slider-changed } swap handle-gesture drop
|
T{ slider-changed } swap handle-gesture drop
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
TUPLE: thumb ;
|
||||||
|
|
||||||
: begin-drag ( thumb -- )
|
: begin-drag ( thumb -- )
|
||||||
find-slider dup slider-value swap set-slider-saved ;
|
find-slider dup slider-value swap set-slider-saved ;
|
||||||
|
|
||||||
|
@ -60,16 +62,18 @@ TUPLE: slider-changed ;
|
||||||
over screen>slider swap [ slider-saved + ] keep
|
over screen>slider swap [ slider-saved + ] keep
|
||||||
set-slider-value* ;
|
set-slider-value* ;
|
||||||
|
|
||||||
: thumb-actions ( thumb -- )
|
M: thumb gadget-gestures
|
||||||
dup [ drop ] T{ button-up } set-action
|
drop H{
|
||||||
dup [ begin-drag ] T{ button-down } set-action
|
{ T{ button-down } [ begin-drag ] }
|
||||||
[ do-drag ] T{ drag } set-action ;
|
{ T{ button-up } [ drop ] }
|
||||||
|
{ T{ drag } [ do-drag ] }
|
||||||
|
} ;
|
||||||
|
|
||||||
: <thumb> ( vector -- thumb )
|
C: thumb ( vector -- thumb )
|
||||||
<gadget> [ set-gadget-orientation ] keep
|
dup delegate>gadget
|
||||||
t over set-gadget-root?
|
t over set-gadget-root?
|
||||||
dup thumb-theme
|
dup thumb-theme
|
||||||
dup thumb-actions ;
|
[ set-gadget-orientation ] keep ;
|
||||||
|
|
||||||
: slide-by ( amount gadget -- )
|
: slide-by ( amount gadget -- )
|
||||||
#! The gadget can be any child of a slider.
|
#! The gadget can be any child of a slider.
|
||||||
|
@ -84,12 +88,13 @@ TUPLE: slider-changed ;
|
||||||
over screen>slider over slider-value - sgn
|
over screen>slider over slider-value - sgn
|
||||||
swap slide-by-page ;
|
swap slide-by-page ;
|
||||||
|
|
||||||
: elevator-actions ( elevator -- )
|
M: elevator gadget-gestures
|
||||||
[ elevator-click ] T{ button-down } set-action ;
|
drop H{ { T{ button-down } [ elevator-click ] } } ;
|
||||||
|
|
||||||
C: elevator ( vector -- elevator )
|
C: elevator ( vector -- elevator )
|
||||||
dup delegate>gadget [ set-gadget-orientation ] keep
|
dup delegate>gadget
|
||||||
dup elevator-theme dup elevator-actions ;
|
dup elevator-theme
|
||||||
|
[ set-gadget-orientation ] keep ;
|
||||||
|
|
||||||
: (layout-thumb) ( slider n -- n thumb )
|
: (layout-thumb) ( slider n -- n thumb )
|
||||||
over gadget-orientation n*v swap slider-thumb ;
|
over gadget-orientation n*v swap slider-thumb ;
|
||||||
|
|
|
@ -69,15 +69,15 @@ M: track pref-dim* ( track -- dim )
|
||||||
dup gadget-parent divider-delta
|
dup gadget-parent divider-delta
|
||||||
over divider-# rot gadget-parent change-divider ;
|
over divider-# rot gadget-parent change-divider ;
|
||||||
|
|
||||||
: divider-actions ( divider -- )
|
M: divider gadget-gestures
|
||||||
dup [ gadget-parent save-sizes ] T{ button-down } set-action
|
drop H{
|
||||||
dup [ drop ] T{ button-up } set-action
|
{ T{ button-down } [ gadget-parent save-sizes ] }
|
||||||
[ divider-motion ] T{ drag } set-action ;
|
{ T{ button-up } [ drop ] }
|
||||||
|
{ T{ drag } [ divider-motion ] }
|
||||||
|
} ;
|
||||||
|
|
||||||
C: divider ( -- divider )
|
C: divider ( -- divider )
|
||||||
dup delegate>gadget
|
dup delegate>gadget dup reverse-video-theme ;
|
||||||
dup divider-actions
|
|
||||||
dup reverse-video-theme ;
|
|
||||||
|
|
||||||
: normalize-sizes ( sizes -- sizes )
|
: normalize-sizes ( sizes -- sizes )
|
||||||
dup sum swap [ swap / ] map-with ;
|
dup sum swap [ swap / ] map-with ;
|
||||||
|
|
Loading…
Reference in New Issue