Skip to content

add newListener() method to ofParameter#4784

Merged
arturoc merged 1 commit intoopenframeworks:masterfrom
tgfrerer:feature-ofParam-newListener
Feb 5, 2016
Merged

add newListener() method to ofParameter#4784
arturoc merged 1 commit intoopenframeworks:masterfrom
tgfrerer:feature-ofParam-newListener

Conversation

@tgfrerer
Copy link
Member

@tgfrerer tgfrerer commented Feb 5, 2016

If you want to use an ofEventListener to respond to an ofEvent, you best create one using a templated factory method which is part of ofEvent<T>.

Since ofParameter shields users from accessing its data directly by holding it inside a private data obj, there is no way to call the newListener factory method on a parameter changed event (changedE) which you want to observe.

This PR proposes to add a newListener method to ofParameter, which will, based on dark templating magick, forward any of its parameters to the ofEvent object held by the private ofParameter::obj.

I wish there was a simpler way, but this seems to me the best way to observe an ofParameter and responding to any changes using a lambda.

Minimal testcase:
https://gist.github.com/tgfrerer/f9fc6e3b2ebe88633ab5

if you want to use an ofEventListener to respond to an ofEvent, you have
to create one using a templated factory method which is part of
ofEvent<T>.

Since ofParameter shields users from accessing its data directly by
holding it inside a private data `obj`, there is no way to call the
`newListener` factory method on a parameter changed event which you want
to observe.

This PR proposes to add a `newListener` method to `ofParameter`, which
will, based on dark templating magick, forward any of its parameters to
the `ofEvent` object held by the private `ofParameter::obj`.

I wish there was a simpler way, but this seems to me the best way to
observe an ofParameter and responding to any changes using a lambda.

Minimal testcase:
<https://gist.github.com/tgfrerer/f9fc6e3b2ebe88633ab5>
arturoc added a commit that referenced this pull request Feb 5, 2016
add newListener() method to ofParameter
@arturoc arturoc merged commit 57c4d9a into openframeworks:master Feb 5, 2016
@arturoc
Copy link
Member

arturoc commented Feb 5, 2016

thanks!

@tgfrerer tgfrerer deleted the feature-ofParam-newListener branch March 9, 2016 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants