diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 2a9d17f21e..1ea5ac9b6d 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -705,25 +705,22 @@ void Widget::setupSwipeBack() { && !controller()->openedFolder().current())) { return HistoryView::SwipeHandlerFinishData(); } - return HistoryView::SwipeHandlerFinishData{ - .callback = [=] { - _swipeBackData = {}; - if (const auto forum = controller()->shownForum().current()) { - const auto id = controller()->windowId(); - const auto initial = id.forum(); - if (!initial) { - controller()->closeForum(); - } else if (initial != forum) { - controller()->showForum(initial); - } - } else if (controller()->openedFolder().current()) { - if (!controller()->windowId().folder()) { - controller()->closeFolder(); - } + return HistoryView::DefaultSwipeBackHandlerFinishData([=] { + _swipeBackData = {}; + if (const auto forum = controller()->shownForum().current()) { + const auto id = controller()->windowId(); + const auto initial = id.forum(); + if (!initial) { + controller()->closeForum(); + } else if (initial != forum) { + controller()->showForum(initial); } - }, - .msgBareId = HistoryView::kMsgBareIdSwipeBack, - }; + } else if (controller()->openedFolder().current()) { + if (!controller()->windowId().folder()) { + controller()->closeFolder(); + } + } + }); }, nullptr); } diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp index 4047c533bd..88be0ce7cd 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -441,10 +441,9 @@ void Widget::setupSwipeReply() { } }, [=](int, Qt::LayoutDirection direction) { if (direction == Qt::RightToLeft) { - return HistoryView::SwipeHandlerFinishData{ - .callback = [=] { controller()->showBackFromStack(); }, - .msgBareId = HistoryView::kMsgBareIdSwipeBack, - }; + return HistoryView::DefaultSwipeBackHandlerFinishData([=] { + controller()->showBackFromStack(); + }); } return HistoryView::SwipeHandlerFinishData(); }, nullptr); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 6dcf978acd..4114208f91 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -563,10 +563,9 @@ void HistoryInner::setupSwipeReplyAndBack() { int cursorTop, Qt::LayoutDirection direction) { if (direction == Qt::RightToLeft) { - return HistoryView::SwipeHandlerFinishData{ - .callback = [=] { _controller->showBackFromStack(); }, - .msgBareId = HistoryView::kMsgBareIdSwipeBack, - }; + return HistoryView::DefaultSwipeBackHandlerFinishData([=] { + _controller->showBackFromStack(); + }); } auto result = HistoryView::SwipeHandlerFinishData(); if (inSelectionMode().inSelectionMode diff --git a/Telegram/SourceFiles/history/history_view_swipe.cpp b/Telegram/SourceFiles/history/history_view_swipe.cpp index 866f25d17d..19f3d66a41 100644 --- a/Telegram/SourceFiles/history/history_view_swipe.cpp +++ b/Telegram/SourceFiles/history/history_view_swipe.cpp @@ -27,6 +27,9 @@ namespace { constexpr auto kSwipeSlow = 0.2; +constexpr auto kMsgBareIdSwipeBack = std::numeric_limits::max() - 77; +constexpr auto kSwipedBackSpeedRatio = 0.35; + } // namespace void SetupSwipeHandler( @@ -37,7 +40,6 @@ void SetupSwipeHandler( rpl::producer dontStart) { constexpr auto kThresholdWidth = 50; constexpr auto kMaxRatio = 1.5; - const auto threshold = style::ConvertFloatScale(kThresholdWidth); struct UpdateArgs { QPoint globalCursor; QPointF position; @@ -52,6 +54,7 @@ void SetupSwipeHandler( SwipeHandlerFinishData finishByTopData; std::optional orientation; std::optional direction; + float64 threshold = style::ConvertFloatScale(kThresholdWidth); int directionInt = 1.; QPointF startAt; QPointF delta; @@ -75,9 +78,9 @@ void SetupSwipeHandler( state->data.ratio = ratio; const auto overscrollRatio = std::max(ratio - 1., 0.); const auto translation = int( - base::SafeRound(-std::min(ratio, 1.) * threshold) + base::SafeRound(-std::min(ratio, 1.) * state->threshold) ) + Ui::OverscrollFromAccumulated(int( - base::SafeRound(-overscrollRatio * threshold) + base::SafeRound(-overscrollRatio * state->threshold) )); state->data.msgBareId = state->finishByTopData.msgBareId; state->data.translation = translation @@ -102,7 +105,7 @@ void SetupSwipeHandler( if (state->orientation == Qt::Horizontal) { const auto ratio = std::clamp( delta.value_or(state->delta).x() - / threshold + / state->threshold * state->directionInt, 0., kMaxRatio); @@ -159,6 +162,8 @@ void SetupSwipeHandler( state->finishByTopData = generateFinish( state->cursorTop, state->direction.value_or(Qt::RightToLeft)); + state->threshold = style::ConvertFloatScale(kThresholdWidth) + * state->finishByTopData.speedRatio; if (!state->finishByTopData.callback) { setOrientation(Qt::Vertical); } @@ -180,7 +185,7 @@ void SetupSwipeHandler( state->delta = args.delta; const auto ratio = args.delta.x() * state->directionInt - / threshold; + / state->threshold; updateRatio(ratio); constexpr auto kResetReachedOn = 0.95; constexpr auto kBounceDuration = crl::time(500); @@ -414,4 +419,13 @@ SwipeBackResult SetupSwipeBack( return { std::move(lifetime), std::move(callback) }; } +SwipeHandlerFinishData DefaultSwipeBackHandlerFinishData( + Fn callback) { + return { + .callback = std::move(callback), + .msgBareId = kMsgBareIdSwipeBack, + .speedRatio = kSwipedBackSpeedRatio, + }; +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/history_view_swipe.h b/Telegram/SourceFiles/history/history_view_swipe.h index 49d1468b10..b4fad89ade 100644 --- a/Telegram/SourceFiles/history/history_view_swipe.h +++ b/Telegram/SourceFiles/history/history_view_swipe.h @@ -18,11 +18,10 @@ namespace HistoryView { struct ChatPaintGestureHorizontalData; struct SwipeBackResult; -constexpr auto kMsgBareIdSwipeBack = std::numeric_limits::max() - 77; - struct SwipeHandlerFinishData { Fn callback; int64 msgBareId = 0; + float64 speedRatio = 1.0; }; using Scroll = std::variant< @@ -37,8 +36,11 @@ void SetupSwipeHandler( Fn generateFinishByTop, rpl::producer dontStart = nullptr); -SwipeBackResult SetupSwipeBack( +[[nodiscard]] SwipeBackResult SetupSwipeBack( not_null widget, Fn()> colors); +[[nodiscard]] SwipeHandlerFinishData DefaultSwipeBackHandlerFinishData( + Fn callback); + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp b/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp index 179c1bea9a..c06cbc4952 100644 --- a/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp +++ b/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp @@ -45,10 +45,9 @@ void SetupSwipeBackSection( if (direction != Qt::RightToLeft) { return HistoryView::SwipeHandlerFinishData(); } - return HistoryView::SwipeHandlerFinishData{ - .callback = [=] { list->controller()->showBackFromStack(); }, - .msgBareId = HistoryView::kMsgBareIdSwipeBack, - }; + return HistoryView::DefaultSwipeBackHandlerFinishData([=] { + list->controller()->showBackFromStack(); + }); }, list->touchMaybeSelectingValue()); } diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 11e8dfaa54..3fffd0aed6 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -927,10 +927,9 @@ void RepliesWidget::setupSwipeReplyAndBack() { int cursorTop, Qt::LayoutDirection direction) { if (direction == Qt::RightToLeft) { - return HistoryView::SwipeHandlerFinishData{ - .callback = [=] { controller()->showBackFromStack(); }, - .msgBareId = HistoryView::kMsgBareIdSwipeBack, - }; + return HistoryView::DefaultSwipeBackHandlerFinishData([=] { + controller()->showBackFromStack(); + }); } auto result = HistoryView::SwipeHandlerFinishData(); if (_inner->elementInSelectionMode(nullptr).inSelectionMode) { diff --git a/Telegram/SourceFiles/info/info_content_widget.cpp b/Telegram/SourceFiles/info/info_content_widget.cpp index 2ae0883469..39d9d99d4a 100644 --- a/Telegram/SourceFiles/info/info_content_widget.cpp +++ b/Telegram/SourceFiles/info/info_content_widget.cpp @@ -408,10 +408,9 @@ void ContentWidget::setupSwipeReply() { || direction != Qt::RightToLeft) { return HistoryView::SwipeHandlerFinishData(); } - return HistoryView::SwipeHandlerFinishData{ - .callback = [=] { _controller->showBackFromStack(); }, - .msgBareId = HistoryView::kMsgBareIdSwipeBack, - }; + return HistoryView::DefaultSwipeBackHandlerFinishData([=] { + _controller->showBackFromStack(); + }); }, nullptr); }