class new in Git master
#include <Magnum/Ui/GenericAnimator.h>
GenericNodeAnimator Generic animator with animations attached to nodes.
Each animation is a function that gets called with an associated node handle and an animation factor in the range. The function can then call arbitrary node-related setters on the UI instance or elsewhere. Use GenericDataAnimator for animations associated with a particular layer data, GenericAnimator is then for animations not tied to either.
Setting up an animator instance
The animator doesn't have any shared state or configuration, so it's just about constructing it from a fresh AbstractUserInterface::
Ui::GenericNodeAnimator& animator = ui.setGenericAnimatorInstance( Containers::pointer<Ui::GenericNodeAnimator>(ui.createAnimator()));
Unlike builtin layers or layouters, the default UserInterface implementation doesn't implicitly provide a GenericNodeAnimator instance.
Creating animations
An animation is created by calling create() with an appropriate function taking the node handle and interpolation factor as arguments, an easing function from Animation::
Ui::NodeHandle dropdown = …; animator.create([&ui](Ui::NodeHandle dropdown, Float factor) { ui.setNodeSize(dropdown, {ui.nodeSize(dropdown).x(), 150.0f*factor}); ui.setNodeOpacity(dropdown, 1.0f*factor); }, Animation::Easing::cubicIn, now, 0.5_sec, dropdown);
If the function performs easing on its own, pass Animation::
animator.create([&ui](Ui::NodeHandle dropdown, Float factor, Ui::GenericAnimationStates state) { if(state & Ui::GenericAnimationState::Started) { ui.clearNodeFlags(dropdown, Ui::NodeFlag::Hidden); ui.setNodeFlags(dropdown, Ui::NodeFlag::NoEvents); } ui.setNodeSize(dropdown, {ui.nodeSize(dropdown).x(), 150.0f*factor}); ui.setNodeOpacity(dropdown, 1.0f*factor); if(state & Ui::GenericAnimationState::Stopped) { ui.clearNodeFlags(dropdown, Ui::NodeFlag::NoEvents); } }, Animation::Easing::cubicIn, now, 0.5_sec, dropdown);
The animation function is free to do anything except for touching state related to the animations or associated nodes, such as playing or stopping the animations, or creating, removing animations or nodes. This isn't checked or enforced in any way, but the behavior of doing so is undefined.
Calling a function once at specified time
The callOnce() function is a special case of create() that causes given function to be called exactly once at specified time, which is useful for triggering delayed operations. Internally this is an animation with a zero duration, so you can pause or restart it like any other. For example, hiding a notification after a ten-second timeout:
Ui::NodeHandle tooltip = …; animator.callOnce([&ui](Ui::NodeHandle tooltip) { ui.setNodeFlags(tooltip, Ui::NodeFlag::Hidden); }, now + 10.0_sec, tooltip);
Animation lifetime and node attachment
As with all other animations, they're implicitly removed once they're played. Pass AnimationFlag::
As the animations are associated with nodes they animate, when the node the animation is attached to is removed, the animation gets removed as well. If you want to preserve the animation when the node is removed, call attach(AnimationHandle, NodeHandle) with NodeHandle::
Base classes
- class AbstractGenericAnimator new in Git master
- Base for generic animators.
Constructors, destructors, conversion operators
- GenericNodeAnimator(AnimatorHandle handle) explicit
- Constructor.
- GenericNodeAnimator(const GenericNodeAnimator&) deleted
- Copying is not allowed.
- GenericNodeAnimator(GenericNodeAnimator&&) noexcept
- Move constructor.
Public functions
- auto operator=(const GenericNodeAnimator&) -> GenericNodeAnimator& deleted
- Copying is not allowed.
- auto operator=(GenericNodeAnimator&&) -> GenericNodeAnimator& noexcept
- Move assignment.
- auto usedAllocatedAnimationCount() const -> UnsignedInt
- Count of allocated animation functions.
-
auto create(Containers::
Function<void(NodeHandle node, Float factor)>&& animation, Float(*)(Float) easing, Nanoseconds start, Nanoseconds duration, NodeHandle node, UnsignedInt repeatCount = 1, AnimationFlags flags = {}) -> AnimationHandle - Create an animation.
-
auto create(Containers::
Function<void(NodeHandle node, Float factor, GenericAnimationStates state)>&& animation, Float(*)(Float) easing, Nanoseconds start, Nanoseconds duration, NodeHandle node, UnsignedInt repeatCount = 1, AnimationFlags flags = {}) -> AnimationHandle - Create an animation with an extra state input.
-
auto callOnce(Containers::
Function<void(NodeHandle node)>&& callback, Nanoseconds at, NodeHandle node, AnimationFlags flags = {}) -> AnimationHandle - Call a function once at specified time.
- void remove(AnimationHandle handle)
- Remove an animation.
- void remove(AnimatorDataHandle handle)
- Remove an animation assuming it belongs to this animator.
- auto easing(AnimationHandle handle) -> auto
- Animation easing function.
- auto easing(AnimatorDataHandle handle) -> auto
- Animation easing function assuming it belongs to this animator.
Function documentation
Magnum:: Ui:: GenericNodeAnimator:: GenericNodeAnimator(AnimatorHandle handle) explicit
Constructor.
Parameters | |
---|---|
handle | Handle returned by AbstractUserInterface:: |
Magnum:: Ui:: GenericNodeAnimator:: GenericNodeAnimator(GenericNodeAnimator&&) noexcept
Move constructor.
Performs a destructive move, i.e. the original object isn't usable afterwards anymore.
UnsignedInt Magnum:: Ui:: GenericNodeAnimator:: usedAllocatedAnimationCount() const
Count of allocated animation functions.
Always at most usedCount(). Counts all animation functions that capture non-trivially-destructible state or state that's too large to be stored in-place. The operation is done with a complexity where is capacity().
AnimationHandle Magnum:: Ui:: GenericNodeAnimator:: create(Containers:: Function<void(NodeHandle node, Float factor)>&& animation,
Float(*)(Float) easing,
Nanoseconds start,
Nanoseconds duration,
NodeHandle node,
UnsignedInt repeatCount = 1,
AnimationFlags flags = {})
Create an animation.
Parameters | |
---|---|
animation | Animation function |
easing | Easing function between 0.0f and 1.0f , applied to the factor passed to animation . Pick one from Animation:: |
start | Time at which the animation starts. Use Nanoseconds:: |
duration | Duration of a single play of the animation |
node | Node the animation is attached to. Use NodeHandle:: |
repeatCount | Repeat count. Use 0 for an indefinitely repeating animation. |
flags | Flags |
Expects that both animation
and easing
are not nullptr
. Delegates to AbstractAnimator::
Assuming the easing
function correctly maps 0.0f
and 1.0f
to themselves, the animation function is guaranteed to be called with factor
being exactly 1.0f
once the animation is stopped. Other than that, it may be an arbitrary value based on how the easing
function is implemented. You can also use the GenericAnimationStates overload below to hook directly to the start and stop.
AnimationHandle Magnum:: Ui:: GenericNodeAnimator:: create(Containers:: Function<void(NodeHandle node, Float factor, GenericAnimationStates state)>&& animation,
Float(*)(Float) easing,
Nanoseconds start,
Nanoseconds duration,
NodeHandle node,
UnsignedInt repeatCount = 1,
AnimationFlags flags = {})
Create an animation with an extra state input.
Like create(Containers::state
argument that you can use to perform an operation exactly once at animation start or stop. See documentation of particular GenericAnimationState values for detailed behavior description.
AnimationHandle Magnum:: Ui:: GenericNodeAnimator:: callOnce(Containers:: Function<void(NodeHandle node)>&& callback,
Nanoseconds at,
NodeHandle node,
AnimationFlags flags = {})
Call a function once at specified time.
Parameters | |
---|---|
callback | Function to call |
at | Time at which the callback gets called. Use Nanoseconds:: |
node | Node the animation is attached to. Use NodeHandle:: |
flags | Flags |
Expects that callback
is not nullptr
. Delegates to AbstractAnimator::duration
set to 0_nsec
, see its documentation for more information.
void Magnum:: Ui:: GenericNodeAnimator:: remove(AnimationHandle handle)
Remove an animation.
Expects that handle
is valid. Delegates to AbstractAnimator::
void Magnum:: Ui:: GenericNodeAnimator:: remove(AnimatorDataHandle handle)
Remove an animation assuming it belongs to this animator.
Compared to remove(AnimationHandle) delegates to AbstractAnimator::
auto Magnum:: Ui:: GenericNodeAnimator:: easing(AnimationHandle handle)
Animation easing function.
Expects that handle
is valid. The returned pointer is never nullptr
for animations created with create(), and always nullptr
for animations created with callOnce().
auto Magnum:: Ui:: GenericNodeAnimator:: easing(AnimatorDataHandle handle)
Animation easing function assuming it belongs to this animator.
Like easing(AnimationHandle) const but without checking that handle
indeed belongs to this animator. See its documentation for more information.