A simple, small, dependency-free single header-file tweening\animation extension for dear imgui.
ImTween aims to implement Tweening concept in under a simple and easy to use template class, for dear imgui.
If you are not familiar with Tweening, it is a concept of interpolating between two values over time. It is used in many places but the most common use case is animation.
Download the ImTween.h file and include it in your project.
-
ImTween::Tween<T>
: returns a tween object that can be used to animate an undefined number ofstd::tuple<T, T, T*>
in the form ofstd::tuple { min, max, &value }
, supports all types that have+=
and-=
operators defined.- Note: T of the tween object is the T of the tuple so for example if your tween is of type
float
then your values must be of typestd::tuple<float, float, float*>)
.
- Note: T of the tween object is the T of the tuple so for example if your tween is of type
-
OfType
: sets the type of the tween object, currently there's only one possible type that isPingPong
which returns the value to it'smin
state when the condition is no longer met. -
Speed
: sets the speed of how much the value is increased on each tick. -
When
: sets the condition of the tween object. -
OnComplete
: sets the callback function that is called when thevalue
is equal tomax
. -
Tick
: ticks the tween object, has to be called every frame.
ImTween<float>::Tween(
std::tuple { 50.0f, 100.0f, &settingsButtonWidth },
std::tuple { 50.0f, 100.0f, &closeButtonWidth },
std::tuple { 65.f, 115.f, &rectwidth })
.OfType(ImTween<>::TweenType::PingPong)
.Speed(8.0f)
.When(
[&]()
{
return settingsButtonIsHovered || closeButtonIsHovered;
})
.OnComplete( //Optional
[&]()
{
// Do something when tween completes
})
.Tick();
ImTween is licensed under the MIT License, see LICENSE for more information.
Credits are appreciated but not required.