2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-02 23:55:12 +00:00

Nice expand / collapse animations.

This commit is contained in:
John Preston
2023-06-27 14:49:04 +04:00
parent aff094f278
commit 7f583f86c0
3 changed files with 125 additions and 30 deletions

View File

@@ -1137,7 +1137,16 @@ void Widget::scrollToDefault(bool verytop) {
startScrollUpButtonAnimation(false);
const auto scroll = [=] {
_scroll->scrollToY(qRound(_scrollToAnimation.value(scrollTo)));
const auto animated = qRound(_scrollToAnimation.value(scrollTo));
const auto animatedDelta = animated - scrollTo;
const auto realDelta = _scroll->scrollTop() - scrollTo;
if (realDelta * animatedDelta < 0) {
// We scrolled manually to the other side of target 'scrollTo'.
_scrollToAnimation.stop();
} else if (std::abs(realDelta) > std::abs(animatedDelta)) {
// We scroll by animation only if it gets us closer to target.
_scroll->scrollToY(animated);
}
};
_scrollToAnimation.start(
@@ -2019,7 +2028,6 @@ void Widget::dropEvent(QDropEvent *e) {
void Widget::listScrollUpdated() {
const auto scrollTop = _scroll->scrollTop();
PROFILE_LOG(("SCROLLED: %1").arg(scrollTop));
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
updateScrollUpVisibility();