[racket] Can I capture the mouse events of canvas% without sub-classing?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Nov 30 22:42:34 EST 2013

At Sat, 30 Nov 2013 08:18:59 +1100, Daniel Prager wrote:
> Am I right in thinking that while you can add a callback to respond
> the on-paint event of canvas% at construction time, i.e..
> 
> (new canvas% ...
>     [paint-callback (lambda (c e) ...)])
> 
> to respond to other events -- mouse, keyboard, etc. -- it is necessary to
> sub-class?
> 
> E.g.
> 
> (define my-canvas%
>   (class canvas%
>     (define/override (on-event ev)
>       (when (send ev button-down? 'left)
>         ; do something
>     (super-new)))
> 
> Or are there alternatives?

No, that's the only way, currently.


Posted on the users mailing list.