FLTK is a lightweight GUI toolkit which I use for my music player. It’s great due to its simplicity and it can also be statically linked.
Unfortunately the project development is mostly stalled after two failed attempts to rewrite/redesign it (FLTK 2.x and FLTK 3.x).
Nevertheless, the library is still useful, somewhat maintained and the community is also active, so I can still rely on it.
Not long ago I started refactoring my music player, basically decoupling some of its components, removing globals and
making use of libsigc++ for signals and C++ 11 Lambdas. Just for comparison, this is the default approach to handle FLTK events with callbacks:
Seemingly simple, but doesn’t scale well when you have several small callbacks. It gets more awkward when you’re using classes.
Thanks to C++ Lambdas that can be reworked into this:
Notice that this is a non-capturing lambda. As I wanted to decouple the components using signals, I didn’t bother to
make capturing lambdas work as a Fl_Callback. So here is how things can be handled with Lambdas and Signals:
That’s it, this combination makes possible to decouple the code across other classes and avoid tens or hundred of dangling callbacks.