From 763b3a37c34fd7819f9d553b94387c4fe16554ff Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 11 Jul 2023 12:21:33 +0400 Subject: [PATCH] Allow to change overscroll from outside. --- ui/widgets/elastic_scroll.cpp | 16 +++++++++++++--- ui/widgets/elastic_scroll.h | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ui/widgets/elastic_scroll.cpp b/ui/widgets/elastic_scroll.cpp index e9ef0f4..255ce12 100644 --- a/ui/widgets/elastic_scroll.cpp +++ b/ui/widgets/elastic_scroll.cpp @@ -1118,9 +1118,19 @@ void ElasticScroll::setOverscrollTypes( } } -void ElasticScroll::setOverscrollDefaults(int from, int till) { +void ElasticScroll::setOverscrollDefaults(int from, int till, bool shift) { Expects(from <= 0 && till >= 0); + if (_state.visibleFrom > 0 + || (!_state.visibleFrom + && _overscrollTypeFrom != OverscrollType::Virtual)) { + from = 0; + } + if (_state.visibleTill < _state.fullSize + || (_state.visibleTill == _state.fullSize + && _overscrollTypeTill != OverscrollType::Virtual)) { + till = 0; + } const auto fromChanged = (_overscrollDefaultFrom != from); const auto tillChanged = (_overscrollDefaultTill != till); const auto changed = (fromChanged && _overscroll < 0) @@ -1133,8 +1143,8 @@ void ElasticScroll::setOverscrollDefaults(int from, int till) { _overscrollDefaultTill = till; if (changed) { const auto delta = (_overscroll < 0) - ? (_overscroll - _overscrollDefaultFrom) - : (_overscroll - _overscrollDefaultTill); + ? (_overscroll - (shift ? 0 : _overscrollDefaultFrom)) + : (_overscroll - (shift ? 0 : _overscrollDefaultTill)); _overscrollAccumulated = currentOverscrollDefaultAccumulated() + OverscrollToAccumulated(delta); } diff --git a/ui/widgets/elastic_scroll.h b/ui/widgets/elastic_scroll.h index cba6c51..4a3434b 100644 --- a/ui/widgets/elastic_scroll.h +++ b/ui/widgets/elastic_scroll.h @@ -162,7 +162,7 @@ public: Real, }; void setOverscrollTypes(OverscrollType from, OverscrollType till); - void setOverscrollDefaults(int from, int till); + void setOverscrollDefaults(int from, int till, bool shift = false); void setOverscrollBg(QColor bg); [[nodiscard]] rpl::producer<> scrolls() const;