Difference between ComponentDragger and AnimatedPosition?


#1

I am working on a simple audio application, where a component (a circle graphically) needs to be draggable within the window and the position needs to be accessible. I had implemented the draggability with a ComponentDragger, however when looking into how to get the position of the circle, I discovered the AnimatedPosition class which looks like it is made for exactly what I am trying to do. Is this assumption, in fact, correct? Are there any examples out there about how to use the AnimatedPosition class?

Also, any general resources for learning Juce would be appreciated, I have done all of the tutorials and looking to take the next step in learning Juce.

Thanks!


#2

Well, they’re very different things - ComponentDragger is just for window-like dragging, AnimatedPosition is for doing the physics involved in giving things momentum.

But neither is appropriate if what you’re doing is controlling some kind of value.
In the situation where dragging something changes a value in your data model then you need to decouple the UI and model. When the mouse drags, you change the model, you don’t move the UI component directly. And whenever the model changes, it updates the UI component’s position.


#3

@jules, thanks so much for the help.

That makes great sense. Storing the position in the model, not the UI makes for a much less error-prone application, and simplifies accessing the position.