Trait that adds time-based alpha animation to any component. More...
#include <Fadeable.h>
Public Member Functions | |
| Fadeable () | |
| virtual | ~Fadeable () |
| void | fadeIn (float duration=0.5f, Tween tween=LINEAR, std::function< void()> onComplete=nullptr) |
| Animate alpha from 0 to 255 (fully opaque). | |
| void | fadeOut (float duration=0.5f, Tween tween=LINEAR, std::function< void()> onComplete=nullptr) |
| Animate alpha from its current value to 0 (fully transparent). | |
| void | fadeTo (uint8_t targetAlpha, float duration=0.5f, Tween tween=LINEAR, std::function< void()> onComplete=nullptr) |
Animate alpha from its current value to targetAlpha. | |
| uint8_t | getAlpha () const |
Return the current alpha as a uint8_t (0–255). | |
| void | holdFor (float duration, std::function< void()> onComplete=nullptr) |
Hold at the current alpha for duration seconds, then fire onComplete. | |
| bool | isFading () const |
Return true while a fade or hold animation is running. | |
| void | setAlpha (uint8_t alpha) |
| Set alpha immediately with no animation. | |
Trait that adds time-based alpha animation to any component.
Fadeable manages a float alpha value (0.0–255.0) and animates it toward a target over a specified duration using linear or exponential easing. The animation tick is driven automatically by the framework's update event — no manual onUpdate call is needed in the component.
An optional completion callback fires exactly once when the animation reaches its target, enabling chained sequences:
Fadeable does not modify any drawable automatically — call getAlpha() in your draw() override and apply the value to whatever you are drawing:
Definition at line 51 of file Fadeable.h.
| ml::Fadeable::Fadeable | ( | ) |
|
virtual |
| void ml::Fadeable::fadeIn | ( | float | duration = 0.5f, |
| Tween | tween = LINEAR, | ||
| std::function< void()> | onComplete = nullptr ) |
Animate alpha from 0 to 255 (fully opaque).
Shorthand for fadeTo(255, duration, tween, onComplete).
| duration | Animation duration in seconds. Defaults to 0.5s. |
| tween | Easing curve. Defaults to LINEAR. |
| onComplete | Optional callback fired once when the animation ends. |
| void ml::Fadeable::fadeOut | ( | float | duration = 0.5f, |
| Tween | tween = LINEAR, | ||
| std::function< void()> | onComplete = nullptr ) |
Animate alpha from its current value to 0 (fully transparent).
Shorthand for fadeTo(0, duration, tween, onComplete).
| duration | Animation duration in seconds. Defaults to 0.5s. |
| tween | Easing curve. Defaults to LINEAR. |
| onComplete | Optional callback fired once when the animation ends. |
| void ml::Fadeable::fadeTo | ( | uint8_t | targetAlpha, |
| float | duration = 0.5f, | ||
| Tween | tween = LINEAR, | ||
| std::function< void()> | onComplete = nullptr ) |
Animate alpha from its current value to targetAlpha.
| targetAlpha | Target alpha (0–255). |
| duration | Animation duration in seconds. Defaults to 0.5s. |
| tween | Easing curve. Defaults to LINEAR. |
| onComplete | Optional callback fired once when the animation ends. |
| uint8_t ml::Fadeable::getAlpha | ( | ) | const |
Return the current alpha as a uint8_t (0–255).
Call this in your draw() override to apply the animated value to your drawable's color.
| void ml::Fadeable::holdFor | ( | float | duration, |
| std::function< void()> | onComplete = nullptr ) |
| bool ml::Fadeable::isFading | ( | ) | const |
Return true while a fade or hold animation is running.
true if an animation or hold is currently in progress. | void ml::Fadeable::setAlpha | ( | uint8_t | alpha | ) |
Set alpha immediately with no animation.
Cancels any animation in progress.
| alpha | The new alpha value (0–255). |