mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-05-12 21:30:36 +01:00
animation: fix end callbacks readding the animation var
This commit is contained in:
parent
6a8bc9d2a4
commit
7627d76c7b
3 changed files with 28 additions and 10 deletions
|
@ -160,11 +160,11 @@ namespace Hyprutils {
|
|||
|
||||
m_bIsBeingAnimated = false;
|
||||
|
||||
if (endCallback)
|
||||
onAnimationEnd();
|
||||
|
||||
if (forceDisconnect)
|
||||
disconnectFromActive();
|
||||
|
||||
if (endCallback)
|
||||
onAnimationEnd();
|
||||
}
|
||||
|
||||
const VarType& value() const {
|
||||
|
|
|
@ -13,8 +13,8 @@ void CBaseAnimatedVariable::create(CAnimationManager* pManager, int typeInfo, SP
|
|||
m_pSelf = pSelf;
|
||||
|
||||
m_pAnimationManager = pManager;
|
||||
m_pSignals = pManager->getSignals();
|
||||
m_bDummy = false;
|
||||
m_pSignals = pManager->getSignals();
|
||||
m_bDummy = false;
|
||||
}
|
||||
|
||||
void CBaseAnimatedVariable::connectToActive() {
|
||||
|
@ -136,11 +136,12 @@ void CBaseAnimatedVariable::onAnimationEnd() {
|
|||
/* We do not call disconnectFromActive here. The animation manager will remove it on a call to tickDone. */
|
||||
|
||||
if (m_fEndCallback) {
|
||||
/* loading m_bRemoveEndAfterRan before calling the callback allows the callback to delete this animation safely if it is false. */
|
||||
auto removeEndCallback = m_bRemoveEndAfterRan;
|
||||
m_fEndCallback(m_pSelf);
|
||||
if (removeEndCallback)
|
||||
m_fEndCallback = nullptr; // reset
|
||||
CallbackFun cb = nullptr;
|
||||
m_fEndCallback.swap(cb);
|
||||
|
||||
cb(m_pSelf);
|
||||
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(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
|
||||
{
|
||||
EXPECT(pAnimationManager->m_vActiveAnimatedVariables.size(), 0);
|
||||
|
|
Loading…
Reference in a new issue