-
Notifications
You must be signed in to change notification settings - Fork 939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InterfaceGl: named params + callbacks #419
Conversation
Added precision.
…rivate anonymous methods
…onal val's as they are called so they can be re-added
… of list of callbacks, removing old callbacks
…name, setter, getter ). Is still routed through the other addParam<T> method.
I agree, the whole point of having a setter/getter is to avoid exposing a variable (target). The only problem (which my solution also suffered from and had been solved by your previous templated Param approach) is that you can't pass the std::bind setter/getter functions directly without typecasting them. Similarly, you couldn't write I'd move forward with this regardless. It's very much needed! |
You can simplify it a bit, although you need to specify the type in the method template since it can't be inferred: auto setter = std::bind( &TweakBarApp::setLightDirection, this, std::placeholders::_1 );
auto getter = std::bind( &TweakBarApp::getLightDirection, this );
mParams->addParam<Vec3f>( "Light Direction", setter, getter ); You actually had to do this with my previous approach as well, which looked like: mParams->addParam<Vec3f>( "Light Direction" ).accessors( setter, getter ); Here, the target param defaulted to nullptr, which also doesn't allow the type to be inferred by the compiler. But there are two weaknesses: a) the auto-completion makes the user think there is only one required parameter, and So yea for the case of setter + getter, I think this is fitting. However, in the case of an update callback, I prefer the way it feels with it chained. |
I was referring to your first test with Param< T > but I forgot you could specify the type yourself, ding, ding! Nice. |
InterfaceGl: named params + callbacks
This supersedes #387. @Numeric thanks for the initiative continued work on this.
This adds some missing functionality to
params::InterfaceGl
, as well as missing doxygen docs. List of source changes:Options can now be added using the named parameter idiom:
You can add an update callback as an option that is fired after a target is updated by ATB:
You can also add a setter + getter, which does not require a target to bind to:
Andrew, note that this is different from what you reviewed the other day; while you could also manage this with the other addParam function (and passing in null for the target pointer), that way is a bit confusing interface wise. This method is clearer IMO: you don't need a target, you need two std::function's instead.
I've added all possible types that ATB supports, there were a couple left out before like uint8_t, uint16_t, etc.
The old addParam() methods that take an optionsStr are still in there, though marked deprecated.
Sample has been updated, a few more usage examples were added for the callback stuff.