[racket] how to add text-field-style behavior to rectangles drawn on a canvas

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Oct 7 08:17:53 EDT 2011

At Fri, 07 Oct 2011 13:06:23 +0200, Marijn wrote:
> I've prepared a chopped-down attempt which defines an editor, an
> administrator and a display class and instantiates them.
> Unfortunately the editor doesn't appear on the screen where I thought
> I'd let the administrator tell it to appear.
> I'm not sure why it doesn't work. Any help?

All windowing events go to the `canvas%', and the built-in canvas
methods know nothing about your editor admin. You need to override
`on-paint' to pass on the message to the editor, `on-focus' to notify
the editor, `on-event' to send events on to the editor, and so on.

See enclosed.

I changed the direct calls to `refresh' to instead send `refresh' to
the canvas, and then the canvas's `on-paint' calls the editor's
`refresh'. Otherwise, you have to erase the area for the editor before
redrawing the editor, and the windowing system is usually better at
scheduling the refresh.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minimal-editor-admin-sample.rkt
Type: application/octet-stream
Size: 2719 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20111007/4f22a362/attachment.obj>

Posted on the users mailing list.