2 USING: kernel models namespaces math sequences arrays hashtables gadgets
3 gadgets-text gadgets-buttons ;
6 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8 TUPLE: action-field quot ;
10 C: action-field ( quot -- action-field )
11 tuck set-action-field-quot f <model> [ add-connection ] 2keep
12 <field> over set-gadget-delegate ;
14 M: action-field model-changed ( action-field -- ) dup action-field-quot call ;
16 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
18 : variable-field ( var -- action-field )
19 unit [ editor-text ] swap append [ set ] append <action-field> ;
21 : number-field ( var -- action-field )
22 unit [ editor-text string>number ] swap append [ set ] append <action-field> ;
24 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25 ! [bind] [unbind] and [bound?] should probably be in a separate
26 ! file. But right now boids and automata are the only programs which
27 ! use this, and I don't want to add a new contrib file just for
28 ! this. For now they'll live here. Maybe bind-button and
29 ! bind-action-field should go into a gadgets-utils file eventually.
30 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
32 : [bind] ( ns quot -- quot ) \ bind 3array >quotation ;
34 : [unbind] ( quot -- quot ) second ;
36 : [bound?] ( quot -- ? )
37 dup length 3 = [ dup first hashtable? swap third \ bind = and ] [ f ] if ;
39 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41 : bind-button ( ns button -- ) tuck button-quot [bind] swap set-button-quot ;
43 : bind-action-field ( ns action-field -- )
44 tuck action-field-quot [bind] swap set-action-field-quot ;
46 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
48 PROVIDE: contrib/action-field ;