Is there a way to pass a parameter to the callback function for a button in InterfaceGl?
Here’s my code (without a param)
void MyApp::setup(){
mParams = ci::params::InterfaceGl::create( ci::app::getWindow(), "App parameters", ci::app::toPixels( ci::ivec2( 200, 400 ) ) );
mParams->addButton( "Click me", bind( &MyApp::button, this ) );
}
void MyApp::button(){
// Can this method receive an int or string parameter ie. the label of the button
// or is there a way to getOptions?
}
Would you like to handle all buttons in one callback function? As far as I know, this is not really the way how Params is designed, but you can work around it. For example, with something like this:
Thanks for the suggestion. This solves it for the moment.
Ideally, I’d like to have a single callback with some parameter indication what the originating button is, without having to duplicate that in the addButton. I just feel that it’d be the most succinct way of creating a lot of buttons with a simple switch/case statement that ideally referenced the labels of the buttons to limit the mystery between the visual display and the code.
Thanks for the recommendation, it’s working perfectly…
In practice, I usually find that using separate callback handlers for each button is easier to follow, especially if you weren’t the original person writing the code. That, and not having to pass an extra argument through the lambda saves a bit of typing in the most common case.