when vs. handle

15 views
Skip to first unread message

aditya siram

unread,
Jan 1, 2017, 11:55:40 AM1/1/17
to fltk.general
Hi all,
Can someone explain the difference between when(..) and overriding handle(..)? They seem to similar purposes.
Thanks and Happy New Year!
-deech

Albrecht Schlosser

unread,
Jan 1, 2017, 12:29:12 PM1/1/17
to fltkg...@googlegroups.com
On 01.01.2017 17:55 aditya siram wrote:
> Hi all,
> Can someone explain the difference between when(..) and overriding
> handle(..)? They seem to similar purposes.

Overriding handle() is generally more flexible and powerful, but you can
do this only if you derive your own class. If you need your own class
anyway overriding handle() is optional. It enables you do intercept all
events and decide what to do. One example would be to allow only a set
of valid input characters (e.g. only numbers) in an input widget.

OTOH when() enables you to control when a callback will be called. You
can use this whether you derive your own widget or not.

I'd say: if you can use the standard callback mechanism of a widget you
can fine-tune the behavior by specifying different when() conditions. If
you need more control over the widget's behavior (for instance dragging
etc.) you need to derive your own class and override handle().

Another useful example would be to do button highlighting on FL_ENTER
and revert it on FL_LEAVE which you can obviously only do in handle().

You can see more info in the docs in these chapters:

http://www.fltk.org/doc-1.3/events.html
http://www.fltk.org/doc-1.3/subclassing.html

aditya siram

unread,
Jan 3, 2017, 9:58:31 AM1/3/17
to fltk.general, Albrech...@online.de
Great. That's very helpful. Thanks!
Reply all
Reply to author
Forward
0 new messages