Loading...
Searching...
No Matches
Fadeable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith. All rights reserved.
2// Malena Framework — Proprietary Software. See LICENSE for terms.
3
4#pragma once
5
6#ifndef MALENA_FADEABLE_H
7#define MALENA_FADEABLE_H
12#include <functional>
13
14
15namespace ml
16{
56 class MALENA_API Fadeable : public Trait
57 {
58 public:
60 virtual ~Fadeable();
61
62 // ── Fade API ──────────────────────────────────────────────────────────
63
72 void fadeTo(uint8_t targetAlpha,
73 float duration = 0.5f,
74 Tween tween = LINEAR,
75 std::function<void()> onComplete = nullptr);
76
86 void fadeIn(float duration = 0.5f,
87 Tween tween = LINEAR,
88 std::function<void()> onComplete = nullptr);
89
99 void fadeOut(float duration = 0.5f,
100 Tween tween = LINEAR,
101 std::function<void()> onComplete = nullptr);
102
117 void holdFor(float duration,
118 std::function<void()> onComplete = nullptr);
119
127 void setAlpha(uint8_t alpha);
128
137 uint8_t getAlpha() const;
138
144 bool isFading() const;
145
146 private:
148 void tick();
149
150 float _alpha = 255.f;
151 float _startAlpha = 255.f;
152 float _targetAlpha = 255.f;
153 float _elapsed = 0.f;
154 float _duration = 0.f;
155 bool _active = false;
156 bool _holding = false;
157 Tween _tween = LINEAR;
158
159 std::function<void()> _onComplete;
160
161 static float applyTween(float t, Tween tween);
163 };
164
165} // namespace ml
166
167#include "../../../../src/Traits/Visual/Fadeable.cpp"
168#endif
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.
void setAlpha(uint8_t alpha)
Set alpha immediately with no animation.
void fadeOut(float duration=0.5f, Tween tween=LINEAR, std::function< void()> onComplete=nullptr)
Animate alpha from its current value to 0 (fully transparent).
virtual ~Fadeable()
bool isFading() const
Return true while a fade or hold animation is running.
uint8_t getAlpha() const
Return the current alpha as a uint8_t (0–255).
void fadeIn(float duration=0.5f, Tween tween=LINEAR, std::function< void()> onComplete=nullptr)
Animate alpha from 0 to 255 (fully opaque).
void holdFor(float duration, std::function< void()> onComplete=nullptr)
Hold at the current alpha for duration seconds, then fire onComplete.
Empty marker base class for all Malena traits.
Definition Trait.h:35
Tween
Easing curve selection for animated movement.
Definition Tween.h:45
@ LINEAR
Constant-speed interpolation.
Definition Tween.h:46
#define MALENA_API
Definition Component.h:22