The Slate supports bindings in exactly the same way as the
Tk canvas. These can be used to implement moving of items and other
forms of interaction. The Slate also provides a higher-level
mechanism, based on the concept of interactors, as described by
Brad Myers and used in the Garnet system.
set slate [::tycho::Slate::demoslate]
set r [$slate create rectangle 60 20 80 40 -fill red]
set f [$slate create Frame 120 120 150 140 \
-borderwidth 4 -color green -tags fred]
Each interactor is an object that inherits from the Interactor
class. The most basic kind of interactor is the Follower, which
"follows" the mouse. Assuming you still have the Slate from earlier in
this tutorial (if not, you will need to go back and re-execute
the code), you can create an interactor with the interact
method:
set follower [$slate interactor Follower]
An interactor is "bound" to one or more objects with the
bind
command. For example, this will bind the follower
you just created to the items tagged with fred
(the
Frame):
$follower bind fred -button 1
You can now drag the frame, but not the rectangle, with the mouse!
To turn this off again, use unbind
:
$follower unbind fred -button 1
There are several other kinds of interactor. Bounder moves
an object within a specified region of the Slate. We'll create a
rectangle so you can see the region:
$slate create rectangle 50 50 200 200 -outline red
set bounder [$slate interactor Bounder -bounds {50 50 200 200}]
$bounder bind $r -button 1
-bounds
option is not given, the Bounder interactor keeps the object within the
bounds of the Slate. Bounder can be used constrain movement along
one axis:
$bounder configure -constrain x
Interactors can be cascaded, to make more complex interactions. For
example, we can create a Stepper interactor that quantizes
movement to a certain size, and cascade it with the bounder:
set stepper [$slate interactor Stepper -stepsize 10]
$bounder configure -constrain none
$bounder cascade $stepper