cf::ui::components::material::AnimationStrategy¶
Abstract strategy interface for animation customization. More...
#include <cfmaterial_animation_strategy.h>
Inherited by cf::ui::components::material::DefaultAnimationStrategy
Public Functions¶
| Name | |
|---|---|
| virtual | ~AnimationStrategy() =default Virtual destructor. |
| virtual AnimationDescriptor | adjust(constAnimationDescriptor & descriptor, QWidget * widget) =0 Adjust animation descriptor for a specific widget. |
| virtual bool | shouldEnable(QWidget * widget) const Check if animations should be enabled for a widget. |
| void | setGlobalEnabled(bool enabled) Set the global enabled state for this strategy. |
| bool | globalEnabled() const Get the global enabled state. |
Protected Attributes¶
| Name | |
|---|---|
| bool | globalEnabled_ Global enabled state for animations using this strategy. |
Detailed Description¶
Abstract strategy interface for animation customization.
Exceptions:
- None (all methods are noexcept safe)
Since: 0.1
Note: Strategies should be stateless and reusable across widgets. Do not store widget pointers in strategies; use only the provided widget parameter during the adjust() call.
Warning: Do not store the widget pointer passed to adjust(); it may become invalid after the call returns.
The Animation Strategy pattern allows different widget types to customize animation behavior without modifying the factory. Each strategy can:
- Adjust animation parameters (duration, easing, values)
- Override animation types for specific widgets
- Enable/disable animations based on conditions
Strategies are applied during animation creation, before the actual animation object is instantiated. This allows for runtime customization based on widget state, system settings, or other contextual factors.
// Custom strategy for buttons
class ButtonStrategy : public AnimationStrategy {
public:
AnimationDescriptor adjust(const AnimationDescriptor& desc,
QWidget* widget) override {
// Buttons use shorter animations
AnimationDescriptor adjusted = desc;
if (strcmp(desc.motionToken, "md.motion.mediumEnter") == 0) {
adjusted.motionToken = "md.motion.shortEnter";
}
return adjusted;
}
};
// Usage
factory->setStrategy(std::make_unique<ButtonStrategy>());
Public Functions Documentation¶
function ~AnimationStrategy¶
Virtual destructor.
Since: 0.1
function adjust¶
Adjust animation descriptor for a specific widget.
Parameters:
- descriptor Original animation descriptor.
- widget Target widget (may be nullptr).
Exceptions:
- None
Return: Adjusted animation descriptor.
Since: 0.1
Note: The default implementation returns the descriptor unchanged.
Warning: Do not store the widget pointer; it may be invalid after this call returns.
Reimplemented by: cf::ui::components::material::DefaultAnimationStrategy::adjust
Called by the factory before creating an animation. Subclasses can modify any field in the descriptor to customize animation behavior.
Common adjustments include:
- Changing motion token (duration/easing)
- Substituting animation type (slide → fade)
- Modifying value ranges
- Adding delays
AnimationDescriptor adjust(const AnimationDescriptor& desc,
QWidget* widget) override {
AnimationDescriptor result = desc;
// Reduce animation duration for small widgets
if (widget && widget->width() < 100) {
result.motionToken = "md.motion.shortEnter";
}
return result;
}
function shouldEnable¶
Check if animations should be enabled for a widget.
Parameters:
- widget Target widget (may be nullptr).
Exceptions:
- None
Return: true if animation should be enabled, false otherwise.
Since: 0.1
Note: The default implementation returns the global enabled state.
Warning: None
Allows strategies to conditionally disable animations based on widget state or system settings. This can be used for accessibility, performance, or user preference.
Common reasons to disable:
- System accessibility setting (reduce motion)
- Low-performance mode
- Widget-specific conditions
bool shouldEnable(QWidget* widget) const override {
// Disable animations in low-performance mode
if (isLowPerformanceMode()) return false;
return globalEnabled_;
}
function setGlobalEnabled¶
Set the global enabled state for this strategy.
Parameters:
- enabled true to enable animations, false to disable.
Exceptions:
- None
Since: 0.1
Note: This affects all subsequent shouldEnable() calls.
Warning: None
This affects all subsequent shouldEnable() calls. Individual widget checks can still override this by returning false in their implementation.
// Disable animations during heavy processing
strategy->setGlobalEnabled(false);
// ... do heavy work ...
strategy->setGlobalEnabled(true);
function globalEnabled¶
Get the global enabled state.
Return: true if globally enabled, false otherwise.
Since: 0.1
Protected Attributes Documentation¶
variable globalEnabled_¶
Global enabled state for animations using this strategy.
Updated on 2026-03-09 at 10:14:00 +0000