Skip to content

Instantly share code, notes, and snippets.

@cjameshuff
Created January 2, 2013 21:08
Show Gist options
  • Save cjameshuff/4438069 to your computer and use it in GitHub Desktop.
Save cjameshuff/4438069 to your computer and use it in GitHub Desktop.
static void GenericCallback(Fl_Widget * widget, void * data) {
auto cb = static_cast<std::function<void(Fl_Widget *)> *>(data);
(*cb)(widget);
}
template<typename cb_t>
void cb(Fl_Widget * widget, const cb_t & cb) {
auto wrapped = new std::function<void(Fl_Widget *)>;
*wrapped = cb;
widget->callback(GenericCallback, wrapped);
}
Usage:
button = new Fl_Button(20, 150, 60, 20, "A button");
int times = 0;
cb(button, [&times](Fl_Widget * widget) {
cout << (format("button pressed %d times\n")% ++times);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment