@MatthiasWM Please, explain how to use the new code to create a timeout callback with several arguments transmitted as captures of a lambda, if that is indeed possible.
I created PR #1600 to test this out. It's not fully implemented, but good enough for testing. So here is a silly code change for test/button.cxx that shows a timeout lambda inside a callback lambda with captures:
Fl_Button *b2 = new Fl_Button(120,20, 80, 25, "&no op");
b2->callback(
[b1, b2]() {
Fl::add_timeout(1.0, [b1, b2]() {
fl_message("The label of b1 is currently '%s'", b1->label());
b2->deactivate();
});
}
);
I think the code is very readable. Better than spreading it across multiple callback functions and global variables.
An alternative syntax that can capture as well and avoids creating a lambda is std::bind(), (here we capture b1) for example:
Fl::add_timeout(
1.0,
std::bind(
fl_message,
"The label of b1 is currently '%s'",
b1->label())
);
This can also bind C++ member functions if needed.
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <fltk/fltk/pull/1597/c5543191035@github.com>
Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.