mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-05-13 05:40:40 +01:00
animation: fix end callbacks readding the animation var (#43)
* animation: fix end callbacks readding the animation var * include fix
This commit is contained in:
parent
6a8bc9d2a4
commit
dd790b90d7
4 changed files with 28 additions and 11 deletions
|
@ -160,11 +160,11 @@ namespace Hyprutils {
|
||||||
|
|
||||||
m_bIsBeingAnimated = false;
|
m_bIsBeingAnimated = false;
|
||||||
|
|
||||||
if (endCallback)
|
|
||||||
onAnimationEnd();
|
|
||||||
|
|
||||||
if (forceDisconnect)
|
if (forceDisconnect)
|
||||||
disconnectFromActive();
|
disconnectFromActive();
|
||||||
|
|
||||||
|
if (endCallback)
|
||||||
|
onAnimationEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
const VarType& value() const {
|
const VarType& value() const {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../memory/WeakPtr.hpp"
|
#include "../memory/WeakPtr.hpp"
|
||||||
#include "hyprutils/memory/WeakPtr.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
|
@ -136,11 +136,12 @@ void CBaseAnimatedVariable::onAnimationEnd() {
|
||||||
/* We do not call disconnectFromActive here. The animation manager will remove it on a call to tickDone. */
|
/* We do not call disconnectFromActive here. The animation manager will remove it on a call to tickDone. */
|
||||||
|
|
||||||
if (m_fEndCallback) {
|
if (m_fEndCallback) {
|
||||||
/* loading m_bRemoveEndAfterRan before calling the callback allows the callback to delete this animation safely if it is false. */
|
CallbackFun cb = nullptr;
|
||||||
auto removeEndCallback = m_bRemoveEndAfterRan;
|
m_fEndCallback.swap(cb);
|
||||||
m_fEndCallback(m_pSelf);
|
|
||||||
if (removeEndCallback)
|
cb(m_pSelf);
|
||||||
m_fEndCallback = nullptr; // reset
|
if (!m_bRemoveEndAfterRan && /* callback did not set a new one by itself */ !m_fEndCallback)
|
||||||
|
m_fEndCallback = cb; // restore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -344,6 +344,23 @@ int main(int argc, char** argv, char** envp) {
|
||||||
EXPECT(s.m_iA->getCurveValue(), 1.f);
|
EXPECT(s.m_iA->getCurveValue(), 1.f);
|
||||||
EXPECT(endCallbackRan, 6);
|
EXPECT(endCallbackRan, 6);
|
||||||
|
|
||||||
|
// test end callback readding the var
|
||||||
|
*s.m_iA = 5;
|
||||||
|
s.m_iA->setCallbackOnEnd([&endCallbackRan](WP<CBaseAnimatedVariable> v) {
|
||||||
|
endCallbackRan++;
|
||||||
|
const auto PAV = dynamic_cast<CAnimatedVariable<int>*>(v.lock().get());
|
||||||
|
|
||||||
|
*PAV = 10;
|
||||||
|
PAV->setCallbackOnEnd([&endCallbackRan](WP<CBaseAnimatedVariable> v) { endCallbackRan++; });
|
||||||
|
});
|
||||||
|
|
||||||
|
while (pAnimationManager->shouldTickForNext()) {
|
||||||
|
pAnimationManager->tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT(endCallbackRan, 8);
|
||||||
|
EXPECT(s.m_iA->value(), 10);
|
||||||
|
|
||||||
// Test duplicate active anim vars are not allowed
|
// Test duplicate active anim vars are not allowed
|
||||||
{
|
{
|
||||||
EXPECT(pAnimationManager->m_vActiveAnimatedVariables.size(), 0);
|
EXPECT(pAnimationManager->m_vActiveAnimatedVariables.size(), 0);
|
||||||
|
|
Loading…
Reference in a new issue