Allow disabling new animations.

This commit is contained in:
John Preston 2019-04-02 13:21:14 +04:00
parent 99bb09374d
commit 74dc4e0c62
2 changed files with 19 additions and 11 deletions

View File

@ -59,12 +59,11 @@ Manager::Manager() {
} }
void Manager::start(not_null<Basic*> animation) { void Manager::start(not_null<Basic*> animation) {
_forceImmediateUpdate = true;
if (_updating) { if (_updating) {
_starting.emplace_back(animation.get()); _starting.emplace_back(animation.get());
} else { } else {
if (empty(_active)) { schedule();
updateQueued();
}
_active.emplace_back(animation.get()); _active.emplace_back(animation.get());
} }
} }
@ -93,9 +92,11 @@ void Manager::update() {
return; return;
} }
const auto now = crl::now(); const auto now = crl::now();
if (_lastUpdateTime + kIgnoreUpdatesTimeout >= now) { if (!_forceImmediateUpdate
&& (_lastUpdateTime + kIgnoreUpdatesTimeout >= now)) {
return; return;
} }
_forceImmediateUpdate = false;
schedule(); schedule();
_updating = true; _updating = true;
@ -129,13 +130,17 @@ void Manager::schedule() {
_scheduled = true; _scheduled = true;
Ui::PostponeCall([=] { Ui::PostponeCall([=] {
_scheduled = false; _scheduled = false;
if (_forceImmediateUpdate) {
const auto next = _lastUpdateTime + kAnimationTimeout; _forceImmediateUpdate = false;
const auto now = crl::now();
if (now < next) {
_timerId = startTimer(next - now, Qt::PreciseTimer);
} else {
updateQueued(); updateQueued();
} else {
const auto next = _lastUpdateTime + kAnimationTimeout;
const auto now = crl::now();
if (now < next) {
_timerId = startTimer(next - now, Qt::PreciseTimer);
} else {
updateQueued();
}
} }
}); });
} }

View File

@ -161,6 +161,7 @@ private:
int _timerId = 0; int _timerId = 0;
bool _updating = false; bool _updating = false;
bool _scheduled = false; bool _scheduled = false;
bool _forceImmediateUpdate = false;
std::vector<ActiveBasicPointer> _active; std::vector<ActiveBasicPointer> _active;
std::vector<ActiveBasicPointer> _starting; std::vector<ActiveBasicPointer> _starting;
rpl::lifetime _lifetime; rpl::lifetime _lifetime;
@ -274,7 +275,9 @@ inline void Simple::start(
that = _data.get(), that = _data.get(),
callback = Prepare(std::forward<Callback>(callback)) callback = Prepare(std::forward<Callback>(callback))
](crl::time now) { ](crl::time now) {
const auto time = (now - that->animation.started()); const auto time = anim::Disabled()
? that->duration
: (now - that->animation.started());
const auto finished = (time >= that->duration); const auto finished = (time >= that->duration);
const auto progress = finished const auto progress = finished
? that->delta ? that->delta