mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +02:00
Respected setting of disabled animation in item highlighter.
This commit is contained in:
parent
c9ef5e47fe
commit
ea955a2c66
3 changed files with 46 additions and 26 deletions
|
@ -13,6 +13,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
|
|
||||||
|
constexpr auto kAnimationFirstPart = st::activeFadeInDuration
|
||||||
|
/ float64(st::activeFadeInDuration + st::activeFadeOutDuration);
|
||||||
|
|
||||||
ElementHighlighter::ElementHighlighter(
|
ElementHighlighter::ElementHighlighter(
|
||||||
not_null<Data::Session*> data,
|
not_null<Data::Session*> data,
|
||||||
ViewForItem viewForItem,
|
ViewForItem viewForItem,
|
||||||
|
@ -20,7 +23,6 @@ ElementHighlighter::ElementHighlighter(
|
||||||
: _data(data)
|
: _data(data)
|
||||||
, _viewForItem(std::move(viewForItem))
|
, _viewForItem(std::move(viewForItem))
|
||||||
, _repaintView(std::move(repaintView))
|
, _repaintView(std::move(repaintView))
|
||||||
, _timer([=] { updateMessage(); })
|
|
||||||
, _animation(*this) {
|
, _animation(*this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,10 +64,8 @@ float64 ElementHighlighter::progress(
|
||||||
not_null<const HistoryItem*> item) const {
|
not_null<const HistoryItem*> item) const {
|
||||||
if (item->fullId() == _highlightedMessageId) {
|
if (item->fullId() == _highlightedMessageId) {
|
||||||
const auto progress = _animation.progress();
|
const auto progress = _animation.progress();
|
||||||
const auto firstPart = st::activeFadeInDuration
|
return std::min(progress / kAnimationFirstPart, 1.)
|
||||||
/ float64(st::activeFadeInDuration + st::activeFadeOutDuration);
|
- ((progress - kAnimationFirstPart) / (1. - kAnimationFirstPart));
|
||||||
return std::min(progress / firstPart, 1.)
|
|
||||||
- ((progress - firstPart) / (1. - firstPart));
|
|
||||||
}
|
}
|
||||||
return 0.;
|
return 0.;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,6 @@ float64 ElementHighlighter::progress(
|
||||||
void ElementHighlighter::highlight(FullMsgId itemId) {
|
void ElementHighlighter::highlight(FullMsgId itemId) {
|
||||||
if (const auto item = _data->message(itemId)) {
|
if (const auto item = _data->message(itemId)) {
|
||||||
if (const auto view = _viewForItem(item)) {
|
if (const auto view = _viewForItem(item)) {
|
||||||
_highlightStart = crl::now();
|
|
||||||
_highlightedMessageId = itemId;
|
_highlightedMessageId = itemId;
|
||||||
_animation.start();
|
_animation.start();
|
||||||
|
|
||||||
|
@ -101,21 +100,14 @@ void ElementHighlighter::updateMessage() {
|
||||||
if (const auto item = _data->message(_highlightedMessageId)) {
|
if (const auto item = _data->message(_highlightedMessageId)) {
|
||||||
if (const auto view = _viewForItem(item)) {
|
if (const auto view = _viewForItem(item)) {
|
||||||
repaintHighlightedItem(view);
|
repaintHighlightedItem(view);
|
||||||
const auto duration = st::activeFadeInDuration
|
|
||||||
+ st::activeFadeOutDuration;
|
|
||||||
if (crl::now() - _highlightStart <= duration) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_animation.cancel();
|
|
||||||
_highlightedMessageId = FullMsgId();
|
|
||||||
checkNextHighlight();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElementHighlighter::clear() {
|
void ElementHighlighter::clear() {
|
||||||
|
_animation.cancel();
|
||||||
_highlightedMessageId = FullMsgId();
|
_highlightedMessageId = FullMsgId();
|
||||||
updateMessage();
|
_queue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementHighlighter::AnimationManager::AnimationManager(
|
ElementHighlighter::AnimationManager::AnimationManager(
|
||||||
|
@ -124,24 +116,53 @@ ElementHighlighter::AnimationManager::AnimationManager(
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ElementHighlighter::AnimationManager::animating() const {
|
bool ElementHighlighter::AnimationManager::animating() const {
|
||||||
return _simple.animating();
|
if (anim::Disabled()) {
|
||||||
|
return (_timer && _timer->isActive());
|
||||||
|
} else {
|
||||||
|
return _simple.animating();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float64 ElementHighlighter::AnimationManager::progress() const {
|
float64 ElementHighlighter::AnimationManager::progress() const {
|
||||||
return _simple.value(0.);
|
if (anim::Disabled()) {
|
||||||
|
return (_timer && _timer->isActive()) ? kAnimationFirstPart : 0.;
|
||||||
|
} else {
|
||||||
|
return _simple.value(0.);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElementHighlighter::AnimationManager::start() {
|
void ElementHighlighter::AnimationManager::start() {
|
||||||
_simple.stop();
|
const auto finish = [=] {
|
||||||
_simple.start(
|
cancel();
|
||||||
[=] { _parent.updateMessage(); },
|
_parent._highlightedMessageId = FullMsgId();
|
||||||
0.,
|
_parent.checkNextHighlight();
|
||||||
1.,
|
};
|
||||||
st::activeFadeInDuration + st::activeFadeOutDuration);
|
cancel();
|
||||||
|
if (anim::Disabled()) {
|
||||||
|
_timer.emplace([=] {
|
||||||
|
_parent.updateMessage();
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
_timer->callOnce(st::activeFadeOutDuration);
|
||||||
|
_parent.updateMessage();
|
||||||
|
} else {
|
||||||
|
const auto to = 1.;
|
||||||
|
_simple.start(
|
||||||
|
[=](float64 value) {
|
||||||
|
_parent.updateMessage();
|
||||||
|
if (value == to) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
0.,
|
||||||
|
to,
|
||||||
|
st::activeFadeInDuration + st::activeFadeOutDuration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElementHighlighter::AnimationManager::cancel() {
|
void ElementHighlighter::AnimationManager::cancel() {
|
||||||
_simple.stop();
|
_simple.stop();
|
||||||
|
_timer.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
|
@ -50,6 +50,7 @@ private:
|
||||||
private:
|
private:
|
||||||
ElementHighlighter &_parent;
|
ElementHighlighter &_parent;
|
||||||
Ui::Animations::Simple _simple;
|
Ui::Animations::Simple _simple;
|
||||||
|
std::optional<base::Timer> _timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
const not_null<Data::Session*> _data;
|
const not_null<Data::Session*> _data;
|
||||||
|
@ -58,8 +59,6 @@ private:
|
||||||
|
|
||||||
FullMsgId _highlightedMessageId;
|
FullMsgId _highlightedMessageId;
|
||||||
std::deque<FullMsgId> _queue;
|
std::deque<FullMsgId> _queue;
|
||||||
base::Timer _timer;
|
|
||||||
crl::time _highlightStart = 0;
|
|
||||||
|
|
||||||
AnimationManager _animation;
|
AnimationManager _animation;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 495ad9d9ad4c5bd553c670c0d95892b875fcb89d
|
Subproject commit 125b2c57063a1c2e1a0ff970e41afee0f83fa4ad
|
Loading…
Add table
Reference in a new issue