Interactors

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 Meyer and used in the Garnet system (I think -- CHECK!).

Note: The interactor hierarchy is still undergoing active development.

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 interact create 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":

$follower bind fred -button 1

You can now drag the arrow and the line with the mouse! To turn this off again, use unbind:

$follower unbind fred -button 1

There are several other kinds of interactor. Alonger moves an object along a horizontal or vertical axis:

set alonger [$slate interact create Alonger]
$alonger bind $f -button 1
(Try moving the Frame with the mouse.)

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 interact create Bounder -bounds {50 50 200 200}]
$bounder bind $r -button 1
(Try moving the red rectangle with the mouse.) If the -bounds option is not given, the Bounder interactor keeps the object within the bounds of the Slate.

Interactors can be cascaded, to make more complex interactions. For example, we can create a Gridder interactor that quantizes movement to a certain grid size, and cascade it with the bounder:

set stepper [$slate interact create Stepper -gridsize 10]
$bounder cascade $stepper
(Try moving the red rectangle with the mouse now.)

The next section of this tutorial gives a concrete example of the use of interactors to rapidly create a custom widget.

Next
Back up
Tycho Home Page


Copyright © 1996, The Regents of the University of California. All rights reserved.
Last updated: 96/12/11, comments to: johnr@eecs.berkeley.edu