From 2b75b48919b08bc47e94151da021dbfdfc078568 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 10 Apr 2026 10:17:56 +0300 Subject: [PATCH] [thanos] Added scrollToY delegate callback for synthetic scroll support. --- Telegram/SourceFiles/history/history_inner_widget.cpp | 3 +++ Telegram/SourceFiles/history/history_widget.h | 8 +++----- .../SourceFiles/history/view/history_view_list_widget.cpp | 3 +++ .../SourceFiles/ui/effects/thanos_effect_controller.cpp | 4 ++-- .../SourceFiles/ui/effects/thanos_effect_controller.h | 1 + 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 70031fba1c..e31421c1f3 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -4249,6 +4249,9 @@ void HistoryInner::setupThanosEffect() { .scrollArea = [=]() -> not_null { return _scroll; }, + .scrollToY = [=](int y) { + _widget->synteticScrollToY(y); + }, .setCollapseGaps = [=](std::vector gaps) { setCollapseGaps(std::move(gaps)); }, diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 6a48fa5e07..09ac181178 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -338,6 +338,9 @@ protected: void mouseReleaseEvent(QMouseEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; +public: + void synteticScrollToY(int y); + private: using TabbedPanel = ChatHelpers::TabbedPanel; using TabbedSelector = ChatHelpers::TabbedSelector; @@ -651,11 +654,6 @@ private: int itemTopForHighlight(not_null view) const; void scrollToCurrentVoiceMessage(FullMsgId fromId, FullMsgId toId); - // Scroll to current y without updating the _lastUserScrolled time. - // Used to distinguish between user scrolls and syntetic scrolls. - // This one is syntetic. - void synteticScrollToY(int y); - void writeDrafts(); void writeDraftTexts(); void writeDraftCursors(); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 531d90cb59..ac6dc930dc 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -4411,6 +4411,9 @@ void ListWidget::setupThanosEffect() { .scrollArea = [=]() -> not_null { return scroll; }, + .scrollToY = [=](int y) { + scroll->scrollToY(y); + }, .setCollapseGaps = [=](std::vector gaps) { setCollapseGaps(std::move(gaps)); }, diff --git a/Telegram/SourceFiles/ui/effects/thanos_effect_controller.cpp b/Telegram/SourceFiles/ui/effects/thanos_effect_controller.cpp index 8d8365893f..0261d8e63a 100644 --- a/Telegram/SourceFiles/ui/effects/thanos_effect_controller.cpp +++ b/Telegram/SourceFiles/ui/effects/thanos_effect_controller.cpp @@ -229,7 +229,7 @@ void ThanosEffectController::startCollapseAnimation( const auto aboveViewport = std::max(0, scrollTop - itemTop); const auto scrollAdjust = std::min(height, aboveViewport); if (scrollAdjust > 0) { - scroll->scrollToY(scrollTop + scrollAdjust); + _delegate.scrollToY(scrollTop + scrollAdjust); } auto totalHeight = 0; @@ -266,7 +266,7 @@ void ThanosEffectController::collapseAnimationCallback() { const auto scroll = _delegate.scrollArea(); const auto scrollTop = scroll->scrollTop(); syncCollapseGapsToHost(); - scroll->scrollToY(std::max(scrollTop - totalDelta, 0)); + _delegate.scrollToY(std::max(scrollTop - totalDelta, 0)); } if (!_collapseAnimation.animating()) { diff --git a/Telegram/SourceFiles/ui/effects/thanos_effect_controller.h b/Telegram/SourceFiles/ui/effects/thanos_effect_controller.h index d8e62b09e1..bee945003b 100644 --- a/Telegram/SourceFiles/ui/effects/thanos_effect_controller.h +++ b/Telegram/SourceFiles/ui/effects/thanos_effect_controller.h @@ -46,6 +46,7 @@ public: Fn preparePaintContext; Fn window; Fn()> scrollArea; + Fn scrollToY; Fn)> setCollapseGaps; };