> On Aug 30, 2018, at 19:57, david allen <
david...@uky.edu> wrote:
>
> That a function is passed as an argument to another function sufficient to call it a callback function? Or, is it also required that the function must be evoked in response to some signal or event?
Passing functions is one thing. You can pass functions as arguments any time. In C/C++, "passing a function" is a nice way of saying, "here is a pointer to something, I hope you know what you are doing". C/C++ only "knows" that something is a pointer to a function during compile time. After that, it's just a pointer. That's why function pointers can be used in arrays, as class members, or whatever other case you think of.
In FLTK specifically, function pointers are used exclusively in callbacks. Callbacks are a way to defer execution of code to a later point in time. You know the code that needs be run when a button is pressed, but you don't want to run it now, but later, when the button is actually pressed, so you set it as a callback.
Not all callbacks are directly related to user interaction. There are timer callbacks that are called after some time elapsed, or idle callbacks, that are called whenever there is nothing else to do.
FLTK uses callbacks for everything that is needed for a basic User Interface. The idea in UI programming is, that anything can happen at any time. So when constructing a UI, you give FLTK all those callbacks, so that FLTK can call any of those at any time, depending on what the user does.
The other method is to override the handle() method, but that is an advanced topic and less of a UI user thing, more a library developer item.