fix a few minor menu bugs

cvs
Slava Pestov 2005-07-09 22:32:31 +00:00
parent f12d34448f
commit d4e3075eeb
6 changed files with 22 additions and 24 deletions

View File

@ -9,11 +9,17 @@ sdl sequences strings styles vectors ;
TUPLE: editor line caret ; TUPLE: editor line caret ;
: with-editor ( editor quot -- )
#! Execute a quotation in the line editor scope, then
#! update the display.
swap [ editor-line swap bind ] keep
dup relayout scroll>bottom ; inline
: editor-text ( editor -- text ) : editor-text ( editor -- text )
editor-line [ line-text get ] bind ; editor-line [ line-text get ] bind ;
: set-editor-text ( text editor -- ) : set-editor-text ( text editor -- )
editor-line [ set-line-text ] bind ; [ set-line-text ] with-editor ;
: focus-editor ( editor -- ) : focus-editor ( editor -- )
dup editor-caret swap add-gadget ; dup editor-caret swap add-gadget ;
@ -21,11 +27,6 @@ TUPLE: editor line caret ;
: unfocus-editor ( editor -- ) : unfocus-editor ( editor -- )
editor-caret unparent ; editor-caret unparent ;
: with-editor ( editor quot -- )
#! Execute a quotation in the line editor scope, then
#! update the display.
swap [ editor-line swap bind ] keep relayout ; inline
: run-char-widths ( str -- wlist ) : run-char-widths ( str -- wlist )
#! List of x co-ordinates of each character. #! List of x co-ordinates of each character.
0 swap >list 0 swap >list
@ -84,8 +85,7 @@ C: editor ( text -- )
shape-dim { 0 1 1 } v* { 1 0 0 } v+ ; shape-dim { 0 1 1 } v* { 1 0 0 } v+ ;
M: editor user-input* ( ch editor -- ? ) M: editor user-input* ( ch editor -- ? )
[ [ insert-char ] with-editor ] keep [ insert-char ] with-editor t ;
scroll>bottom t ;
M: editor pref-dim ( editor -- dim ) M: editor pref-dim ( editor -- dim )
dup editor-text label-size { 1 0 0 } v+ ; dup editor-text label-size { 1 0 0 } v+ ;

View File

@ -27,12 +27,12 @@ DEFER: relayout
DEFER: add-invalid DEFER: add-invalid
: invalidate ( gadget -- ) : invalidate ( gadget -- )
t over set-gadget-redraw?
t swap set-gadget-relayout? ; t swap set-gadget-relayout? ;
: relayout ( gadget -- ) : relayout ( gadget -- )
#! Relayout and redraw a gadget and its parent before the #! Relayout and redraw a gadget and its parent before the
#! next iteration of the event loop. #! next iteration of the event loop.
dup redraw
dup gadget-relayout? [ dup gadget-relayout? [
drop drop
] [ ] [

View File

@ -17,13 +17,13 @@ USING: generic kernel lists math namespaces sequences ;
TUPLE: menu ; TUPLE: menu ;
: menu-actions ( menu -- ) : menu-actions ( menu -- )
[ drop world get hide-glass ] [ button-down 1 ] set-action ; [ drop hide-glass ] [ button-down 1 ] set-action ;
: assoc>menu ( assoc menu -- ) : assoc>menu ( assoc menu -- )
#! Given an association list mapping labels to quotations. #! Given an association list mapping labels to quotations.
#! Prepend a call to hide-menu to each quotation. #! Prepend a call to hide-menu to each quotation.
[ [
uncons \ hide-menu swons <menu-item> swap add-gadget uncons \ hide-glass swons <menu-item> swap add-gadget
] each-with ; ] each-with ;
C: menu ( assoc -- gadget ) C: menu ( assoc -- gadget )

View File

@ -7,12 +7,7 @@ io strings sequences ;
: redraw ( gadget -- ) : redraw ( gadget -- )
#! Redraw a gadget before the next iteration of the event #! Redraw a gadget before the next iteration of the event
#! loop. #! loop.
dup gadget-redraw? [ drop t world get set-gadget-redraw? ;
drop
] [
t over set-gadget-redraw?
gadget-parent [ redraw ] when*
] ifte ;
! Clipping ! Clipping

View File

@ -84,6 +84,3 @@ M: pane stream-write-attr ( string style stream -- )
[ rot "\n" split pane-write ] keep scroll>bottom ; [ rot "\n" split pane-write ] keep scroll>bottom ;
M: pane stream-close ( stream -- ) drop ; M: pane stream-close ( stream -- ) drop ;
: <console> ( -- pane )
<pane> <scroller> ;

View File

@ -20,14 +20,20 @@ DEFER: pane-call
: command-menu ( pane -- menu ) : command-menu ( pane -- menu )
presented get dup applicable [ presented get dup applicable [
3dup third [ 3dup third [
[ swap literal, % ] make-list , , \ pane-call , [ swap literal, % ] make-list , ,
[ pane-call drop ] %
] make-list >r second r> cons ] make-list >r second r> cons
] map 2nip ; ] map 2nip ;
: init-commands ( gadget pane -- ) : init-commands ( gadget pane -- )
over presented paint-prop over presented paint-prop [
[ [ command-menu <menu> show-menu ] cons button-gestures ] [ drop ] swap
[ 2drop ] ifte ; unit
[ command-menu <menu> show-menu ] append3
button-gestures
] [
2drop
] ifte ;
: <styled-label> ( style text -- label ) : <styled-label> ( style text -- label )
<label> swap alist>hash over set-gadget-paint ; <label> swap alist>hash over set-gadget-paint ;