JUCE: AnimatedPosition< Behaviour > Class Template Reference

JUCE

Classes | Public Member Functions | Public Attributes | List of all members
AnimatedPosition< Behaviour > Class Template Reference
juce_gui_basics » layout

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. More...

`#include <juce_AnimatedPosition.h>`

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

## Public Attributes
Behaviour | behaviour
| The behaviour object. More...

## Detailed Description

template<typename Behaviour>
class 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

## Constructor & Destructor Documentation

## ◆ AnimatedPosition()

template<typename Behaviour >

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

## Member Function Documentation

## ◆ setLimits()

template<typename Behaviour >

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

Sets a range within which the value will be constrained.

## ◆ beginDrag()

template<typename Behaviour >

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

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 Timer::stopTimer().

## ◆ drag()

template<typename Behaviour >

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

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 AnimatedPosition< Behaviour >::endDrag | ( |  | ) |

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

References Timer::startTimerHz().

## ◆ nudge()

template<typename Behaviour >

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

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 Timer::startTimerHz().

## ◆ getPosition()

template<typename Behaviour >

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

Returns the current position.

## ◆ setPosition()

template<typename Behaviour >

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

Explicitly sets the position and stops any further movement.

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

References Timer::stopTimer().

## ◆ addListener()

template<typename Behaviour >

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

Adds a listener to be called when the value changes.

## ◆ removeListener()

template<typename Behaviour >

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

Removes a previously-registered listener.

## Member Data Documentation

## ◆ behaviour

template<typename Behaviour >

Behaviour AnimatedPosition< Behaviour >::behaviour

The behaviour object.

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

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

- juce_AnimatedPosition.h