Loading...
Searching...
No Matches
juce::AnimatedPosition< Behaviour > Class Template Reference

## Detailed Description

template<typename Behaviour>
class juce::AnimatedPosition< Behaviour >

Models a 1-dimensional position that can be dragged around by the user, and which will then continue moving with a customisable physics behaviour when released.

This is useful for things like scrollable views or objects that can be dragged and thrown around with the mouse/touch, and by writing your own behaviour class, you can customise the trajectory that it follows when released.

The class uses its own Timer to continuously change its value when a drag ends, and Listener objects can be registered to receive callbacks whenever the value changes.

The value is stored as a double, and can be used to represent whatever units you need.

The template parameter Behaviour must be a class that implements various methods to return the physics of the value's movement - you can use the classes provided for this in the AnimatedPositionBehaviours namespace, or write your own custom behaviour.

See also
  AnimatedPositionBehaviours::ContinuousWithMomentum, AnimatedPositionBehaviours::SnapToPageBoundaries

The documentation for this class was generated from the following file:

- juce_gui_basics/layout/juce_AnimatedPosition.h

Inheritance diagram for juce::AnimatedPosition< Behaviour >:

## Classes

class | Listener
| Implement this class if you need to receive callbacks when the value of an AnimatedPosition changes. More...

## Public Member Functions

| AnimatedPosition ()
void | setLimits (Range< double > newRange) noexcept
| Sets a range within which the value will be constrained.
void | beginDrag ()
| Called to indicate that the object is now being controlled by a mouse-drag or similar operation.
void | drag (double deltaFromStartOfDrag)
| Called during a mouse-drag operation, to indicate that the mouse has moved.
void | endDrag ()
| Called after beginDrag() and drag() to indicate that the drag operation has now finished.
void | nudge (double deltaFromCurrentPosition)
| Called outside of a drag operation to cause a nudge in the specified direction.
double | getPosition () const noexcept
| Returns the current position.
void | setPosition (double newPosition)
| Explicitly sets the position and stops any further movement.
void | addListener (Listener *listener)
| Adds a listener to be called when the value changes.
void | removeListener (Listener *listener)
| Removes a previously-registered listener.

## Public Attributes

Behaviour | behaviour
| The behaviour object.

## Constructors and Destructors

## AnimatedPosition()

template<typename Behaviour>

juce::AnimatedPosition< Behaviour >::AnimatedPosition | ( |  | ) |

inline

Referenced by juce::AnimatedPosition< Behaviour >::Listener::positionChanged().

## Member Functions

## setLimits()

template<typename Behaviour>

void juce::AnimatedPosition< Behaviour >::setLimits | ( | Range< double > | newRange | ) |

inline noexcept

Sets a range within which the value will be constrained.

## beginDrag()

template<typename Behaviour>

void juce::AnimatedPosition< Behaviour >::beginDrag | ( |  | ) |

inline

Called to indicate that the object is now being controlled by a mouse-drag or similar operation.

After calling this method, you should make calls to the drag() method each time the mouse drags the position around, and always be sure to finish with a call to endDrag() when the mouse is released, which allows the position to continue moving freely according to the specified behaviour.

References juce::Timer::stopTimer().

## drag()

template<typename Behaviour>

void juce::AnimatedPosition< Behaviour >::drag | ( | double | deltaFromStartOfDrag | ) |

inline

Called during a mouse-drag operation, to indicate that the mouse has moved.

The delta is the difference between the position when beginDrag() was called and the new position that's required.

## endDrag()

template<typename Behaviour>

void juce::AnimatedPosition< Behaviour >::endDrag | ( |  | ) |

inline

Called after beginDrag() and drag() to indicate that the drag operation has now finished.

References juce::Timer::startTimerHz().

## nudge()

template<typename Behaviour>

void juce::AnimatedPosition< Behaviour >::nudge | ( | double | deltaFromCurrentPosition | ) |

inline

Called outside of a drag operation to cause a nudge in the specified direction.

This is intended for use by e.g. mouse-wheel events.

References juce::Timer::startTimerHz().

## getPosition()

template<typename Behaviour>

double juce::AnimatedPosition< Behaviour >::getPosition | ( |  | ) | const

inline noexcept

Returns the current position.

## setPosition()

template<typename Behaviour>

void juce::AnimatedPosition< Behaviour >::setPosition | ( | double | newPosition | ) |

inline

Explicitly sets the position and stops any further movement.

This will cause a synchronous call to any listeners if the position actually changes.

References juce::Timer::stopTimer().

## addListener()

template<typename Behaviour>

void juce::AnimatedPosition< Behaviour >::addListener | ( | Listener * | listener | ) |

inline

Adds a listener to be called when the value changes.

## removeListener()

template<typename Behaviour>

void juce::AnimatedPosition< Behaviour >::removeListener | ( | Listener * | listener | ) |

inline

Removes a previously-registered listener.

## Member Data Documentation

## behaviour

template<typename Behaviour>

Behaviour juce::AnimatedPosition< Behaviour >::behaviour

The behaviour object.

This is public to let you tweak any parameters that it provides.

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited