Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fltk/fltk/llms.txt
Use this file to discover all available pages before exploring further.
What This Example Demonstrates
This example shows FLTK’s modern callback system using callback macros:- Function callbacks with 0-5 custom parameters (not limited to void*)
- Non-static method callbacks
- Inline callbacks (lambda-style without C++11)
- Type-safe parameter passing
- Dynamic widget creation with independent callbacks
Complete Source Code
Source file:examples/callbacks.cxx
Compilation Command
Expected Behavior
The program creates a window with three columns of buttons:- Function Callbacks: Regular C functions with custom parameters
- Method Callbacks: Non-static class methods with access to instance data
- Inline Callbacks: Code blocks executed directly (like lambdas)
Key Concepts
Traditional FLTK Callbacks (Limited)
Traditional callbacks are limited tovoid* or long for user data:
Modern Callback Macros (Flexible)
New macros allow type-safe parameters:Function Callback Macros
Available macros:FL_FUNCTION_CALLBACK_0 through FL_FUNCTION_CALLBACK_5
Method Callback Macros
Call non-static methods with access to instance variables:Inline Callbacks
Like lambdas but C++98 compatible:Variations and Extensions
Comparing Old vs New Style
Old Style (Limited):Dynamic Callbacks with Loops
Complex Data Types
Combining with Traditional Callbacks
You can mix old and new styles:Accessing Widget in Callback
Inline callbacks can access the widget:Best Practices
- Use type-safe macros instead of void* when possible
- Inline callbacks are great for simple, widget-specific code
- Method callbacks work well for object-oriented designs
- Function callbacks are best for reusable logic
- Parameters are copied - use pointers/references for large objects
Next Steps
- Learn about threading
- Explore custom widgets
- See layout management