跳转至

ui/components/spring_animation.h

Spring-based Animation Interface. More...

Namespaces

Name
cf
cf::ui
cf::ui::components

Classes

Name
class cf::ui::components::ICFSpringAnimation
Spring-based animation interface.

Detailed Description

Spring-based Animation Interface.

Author: Charliechen114514 (chengh1922@mails.jlu.edu.cn)

Version: 0.1

Date: 2026-02-28

Copyright: Copyright © 2026

Defines the spring-based animation interface that uses spring physics for natural motion. This provides animations that follow spring dynamics rather than fixed timing curves.

Source code

#pragma once

#include "animation.h"
#include "base/easing.h"
#include <QObject>

namespace cf::ui::components {

class CF_UI_EXPORT ICFSpringAnimation : public ICFAbstractAnimation {
    Q_OBJECT
  public:
    ICFSpringAnimation(const base::Easing::SpringPreset& easing, QObject* parent = nullptr)
        : ICFAbstractAnimation(parent) {
        easing_ = easing;
    }

    virtual void setTarget(float target) { m_target = target; }

    virtual void setInitialVelocity(float velocity) { m_velocity = velocity; }

    virtual float currentValue() const = 0;

    bool tick(int dt) override; // Using springStep

  protected:
    base::Easing::SpringPreset easing_;

    float m_position = 0.0f;

    float m_velocity = 0.0f;

    float m_target = 1.0f;
};

} // namespace cf::ui::components

Updated on 2026-03-09 at 10:14:01 +0000