From de87bed3755bb6a9594ee8fa0417789c5ac052a4 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 19 Feb 2025 00:21:05 +0300 Subject: [PATCH] Moved out data for swipe handler from history view to ui controls. --- .../SourceFiles/chat_helpers/tabbed_selector.cpp | 2 +- .../SourceFiles/chat_helpers/tabbed_selector.h | 4 ++-- Telegram/SourceFiles/dialogs/dialogs_widget.cpp | 2 +- Telegram/SourceFiles/dialogs/dialogs_widget.h | 4 ++-- .../admin_log/history_admin_log_section.cpp | 2 +- .../history/admin_log/history_admin_log_section.h | 4 ++-- .../SourceFiles/history/history_inner_widget.cpp | 2 +- .../SourceFiles/history/history_inner_widget.h | 6 +++--- .../history/history_view_swipe_back_session.cpp | 6 +++--- Telegram/SourceFiles/history/history_widget.cpp | 2 +- .../history/view/history_view_replies_section.cpp | 2 +- .../history/view/history_view_replies_section.h | 6 +++--- Telegram/SourceFiles/info/info_content_widget.cpp | 2 +- Telegram/SourceFiles/info/info_content_widget.h | 4 ++-- Telegram/SourceFiles/ui/chat/chat_style.h | 4 ++-- Telegram/SourceFiles/ui/controls/swipe_handler.cpp | 14 +++++--------- Telegram/SourceFiles/ui/controls/swipe_handler.h | 12 +++++------- .../controls/swipe_handler_data.h} | 8 ++++---- Telegram/cmake/td_ui.cmake | 2 +- 19 files changed, 41 insertions(+), 47 deletions(-) rename Telegram/SourceFiles/{history/history_view_swipe_data.h => ui/controls/swipe_handler_data.h} (75%) diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 0e16d66e69..a2a971e59b 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -534,7 +534,7 @@ TabbedSelector::~TabbedSelector() = default; void TabbedSelector::setupSwipe() { Ui::Controls::SetupSwipeHandler(this, _scroll.data(), [=]( - HistoryView::ChatPaintGestureHorizontalData data) { + Ui::Controls::SwipeContextData data) { if (data.translation != 0) { if (!_swipeBackData.callback) { _swipeBackData = Ui::Controls::SetupSwipeBack( diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index 6670039c38..272cb7f067 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -10,10 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_common.h" #include "chat_helpers/compose/compose_features.h" #include "ui/rp_widget.h" +#include "ui/controls/swipe_handler_data.h" #include "ui/effects/animations.h" #include "ui/effects/message_sending_animation_common.h" #include "ui/effects/panel_animation.h" -#include "history/history_view_swipe_data.h" #include "ui/cached_round_corners.h" #include "mtproto/sender.h" #include "base/object_ptr.h" @@ -296,7 +296,7 @@ private: const PauseReason _level = {}; const Fn _customTextColor; - HistoryView::SwipeBackResult _swipeBackData; + Ui::Controls::SwipeBackResult _swipeBackData; Mode _mode = Mode::Full; int _roundRadius = 0; diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index d73544520c..4e157244e5 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -678,7 +678,7 @@ Widget::Widget( void Widget::setupSwipeBack() { Ui::Controls::SetupSwipeHandler(_scroll.data(), _scroll.data(), [=]( - HistoryView::ChatPaintGestureHorizontalData data) { + Ui::Controls::SwipeContextData data) { if (data.translation > 0) { if (!_swipeBackData.callback) { _swipeBackData = Ui::Controls::SetupSwipeBack( diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index a46907ef1d..d726959624 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -9,8 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "dialogs/dialogs_key.h" -#include "history/history_view_swipe_data.h" #include "window/section_widget.h" +#include "ui/controls/swipe_handler_data.h" #include "ui/effects/animations.h" #include "ui/userpic_view.h" #include "mtproto/sender.h" @@ -385,7 +385,7 @@ private: ChatSearchTab _searchQueryTab = {}; ChatTypeFilter _searchQueryFilter = {}; - HistoryView::SwipeBackResult _swipeBackData; + Ui::Controls::SwipeBackResult _swipeBackData; SearchProcessState _searchProcess; SearchProcessState _migratedProcess; 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 aabfff4bbd..92af8aec9e 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -421,7 +421,7 @@ void Widget::setupShortcuts() { void Widget::setupSwipeReply() { Ui::Controls::SetupSwipeHandler(this, _scroll.data(), [=]( - HistoryView::ChatPaintGestureHorizontalData data) { + Ui::Controls::SwipeContextData data) { if (data.translation > 0) { if (!_swipeBackData.callback) { _swipeBackData = Ui::Controls::SetupSwipeBack( diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.h index 7521b8f258..9643694f82 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.h @@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/section_memento.h" #include "history/admin_log/history_admin_log_item.h" #include "history/admin_log/history_admin_log_filter_value.h" -#include "history/history_view_swipe_data.h" +#include "ui/controls/swipe_handler_data.h" #include "mtproto/sender.h" namespace Ui { @@ -83,7 +83,7 @@ private: object_ptr _fixedBarShadow; object_ptr _whatIsThis; - HistoryView::SwipeBackResult _swipeBackData; + Ui::Controls::SwipeBackResult _swipeBackData; }; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 3af6113bdc..ae56287868 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -529,7 +529,7 @@ void HistoryInner::setupSwipeReplyAndBack() { } const auto peer = _peer; Ui::Controls::SetupSwipeHandler(this, _scroll, [=, history = _history]( - HistoryView::ChatPaintGestureHorizontalData data) { + Ui::Controls::SwipeContextData data) { if (data.translation > 0) { if (!_swipeBackData.callback) { _swipeBackData = Ui::Controls::SetupSwipeBack( diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 855add11bc..33dd734966 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -10,11 +10,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "data/data_report.h" #include "ui/rp_widget.h" +#include "ui/controls/swipe_handler_data.h" #include "ui/effects/animations.h" #include "ui/dragging_scroll_manager.h" #include "ui/widgets/tooltip.h" #include "ui/widgets/scroll_area.h" -#include "history/history_view_swipe_data.h" #include "history/view/history_view_top_bar_widget.h" #include @@ -543,8 +543,8 @@ private: crl::time _touchTime = 0; base::Timer _touchScrollTimer; - HistoryView::ChatPaintGestureHorizontalData _gestureHorizontal; - HistoryView::SwipeBackResult _swipeBackData; + Ui::Controls::SwipeContextData _gestureHorizontal; + Ui::Controls::SwipeBackResult _swipeBackData; // _menu must be destroyed before _whoReactedMenuLifetime. rpl::lifetime _whoReactedMenuLifetime; diff --git a/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp b/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp index 9ad05f2867..e39ee4d4d7 100644 --- a/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp +++ b/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp @@ -7,10 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/history_view_swipe_back_session.h" -#include "history/history_view_swipe_data.h" #include "history/view/history_view_list_widget.h" #include "ui/chat/chat_style.h" #include "ui/controls/swipe_handler.h" +#include "ui/controls/swipe_handler_data.h" #include "window/window_session_controller.h" namespace Window { @@ -20,9 +20,9 @@ void SetupSwipeBackSection( not_null scroll, not_null list) { const auto swipeBackData - = list->lifetime().make_state(); + = list->lifetime().make_state(); Ui::Controls::SetupSwipeHandler(parent, scroll, [=]( - HistoryView::ChatPaintGestureHorizontalData data) { + Ui::Controls::SwipeContextData data) { if (data.translation > 0) { if (!swipeBackData->callback) { const auto color = [=]() -> std::pair { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 5dbbe25a83..c6c11b082b 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -53,13 +53,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/controls/send_as_button.h" #include "ui/controls/silent_toggle.h" #include "ui/controls/swipe_handler.h" +#include "ui/controls/swipe_handler_data.h" #include "ui/ui_utility.h" #include "inline_bots/inline_bot_result.h" #include "base/event_filter.h" #include "base/qt_signal_producer.h" #include "base/qt/qt_key_modifiers.h" #include "base/unixtime.h" -#include "history/history_view_swipe_data.h" #include "base/call_delayed.h" #include "data/business/data_shortcut_messages.h" #include "data/components/credits.h" diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index a98922ca5d..5900e2e6c1 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -891,7 +891,7 @@ void RepliesWidget::setupSwipeReplyAndBack() { return false; }; Ui::Controls::SetupSwipeHandler(_inner, _scroll.get(), [=]( - HistoryView::ChatPaintGestureHorizontalData data) { + Ui::Controls::SwipeContextData data) { if (data.translation > 0) { if (!_swipeBackData.callback) { _swipeBackData = Ui::Controls::SetupSwipeBack( diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index faab901de2..3bbe7f5c59 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -12,8 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_corner_buttons.h" #include "history/view/history_view_list_widget.h" #include "history/history_item_helpers.h" -#include "history/history_view_swipe_data.h" #include "data/data_messages.h" +#include "ui/controls/swipe_handler_data.h" #include "base/timer.h" class History; @@ -393,8 +393,8 @@ private: HistoryView::CornerButtons _cornerButtons; rpl::lifetime _topicLifetime; - HistoryView::ChatPaintGestureHorizontalData _gestureHorizontal; - HistoryView::SwipeBackResult _swipeBackData; + Ui::Controls::SwipeContextData _gestureHorizontal; + Ui::Controls::SwipeBackResult _swipeBackData; SendPaymentHelper _sendPayment; diff --git a/Telegram/SourceFiles/info/info_content_widget.cpp b/Telegram/SourceFiles/info/info_content_widget.cpp index 396af38b1f..499ebb16fb 100644 --- a/Telegram/SourceFiles/info/info_content_widget.cpp +++ b/Telegram/SourceFiles/info/info_content_widget.cpp @@ -386,7 +386,7 @@ not_null ContentWidget::scroll() const { void ContentWidget::setupSwipeReply() { Ui::Controls::SetupSwipeHandler(this, _scroll.data(), [=]( - HistoryView::ChatPaintGestureHorizontalData data) { + Ui::Controls::SwipeContextData data) { if (data.translation > 0) { if (!_swipeBackData.callback) { _swipeBackData = Ui::Controls::SetupSwipeBack( diff --git a/Telegram/SourceFiles/info/info_content_widget.h b/Telegram/SourceFiles/info/info_content_widget.h index c53ffadf44..86389fea99 100644 --- a/Telegram/SourceFiles/info/info_content_widget.h +++ b/Telegram/SourceFiles/info/info_content_widget.h @@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_wrap_widget.h" #include "info/statistics/info_statistics_tag.h" -#include "history/history_view_swipe_data.h" +#include "ui/controls/swipe_handler_data.h" namespace Api { struct WhoReadList; @@ -192,7 +192,7 @@ private: // To paint round edges from content. style::margins _paintPadding; - HistoryView::SwipeBackResult _swipeBackData; + Ui::Controls::SwipeBackResult _swipeBackData; }; diff --git a/Telegram/SourceFiles/ui/chat/chat_style.h b/Telegram/SourceFiles/ui/chat/chat_style.h index 6247d3879e..8205d23049 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.h +++ b/Telegram/SourceFiles/ui/chat/chat_style.h @@ -10,8 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/cached_round_corners.h" #include "ui/chat/message_bubble.h" #include "ui/chat/chat_style_radius.h" +#include "ui/controls/swipe_handler_data.h" #include "ui/style/style_core_palette.h" -#include "history/history_view_swipe_data.h" #include "layout/layout_selection.h" #include "styles/style_basic.h" @@ -165,7 +165,7 @@ struct ChatPaintContext { QPainterPath *highlightPathCache = nullptr; mutable QRect highlightInterpolateTo; crl::time now = 0; - HistoryView::ChatPaintGestureHorizontalData gestureHorizontal; + Ui::Controls::SwipeContextData gestureHorizontal; void translate(int x, int y) { viewport.translate(x, y); diff --git a/Telegram/SourceFiles/ui/controls/swipe_handler.cpp b/Telegram/SourceFiles/ui/controls/swipe_handler.cpp index 2c7f5b0196..e21f07f53e 100644 --- a/Telegram/SourceFiles/ui/controls/swipe_handler.cpp +++ b/Telegram/SourceFiles/ui/controls/swipe_handler.cpp @@ -11,8 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/base_platform_info.h" #include "base/qt/qt_common_adapters.h" #include "base/event_filter.h" -#include "history/history_view_swipe_data.h" #include "ui/chat/chat_style.h" +#include "ui/controls/swipe_handler_data.h" #include "ui/painter.h" #include "ui/rect.h" #include "ui/ui_utility.h" @@ -30,16 +30,12 @@ constexpr auto kSwipeSlow = 0.2; constexpr auto kMsgBareIdSwipeBack = std::numeric_limits::max() - 77; constexpr auto kSwipedBackSpeedRatio = 0.35; -using ChatPaintGestureHorizontalData - = HistoryView::ChatPaintGestureHorizontalData; -using SwipeBackResult = HistoryView::SwipeBackResult; - } // namespace void SetupSwipeHandler( not_null widget, Scroll scroll, - Fn update, + Fn update, Fn generateFinish, rpl::producer dontStart) { constexpr auto kThresholdWidth = 50; @@ -54,7 +50,7 @@ void SetupSwipeHandler( base::unique_qptr filter; Ui::Animations::Simple animationReach; Ui::Animations::Simple animationEnd; - ChatPaintGestureHorizontalData data; + SwipeContextData data; SwipeHandlerFinishData finishByTopData; std::optional orientation; std::optional direction; @@ -306,7 +302,7 @@ SwipeBackResult SetupSwipeBack( bool mirrored) { struct State { base::unique_qptr back; - ChatPaintGestureHorizontalData data; + SwipeContextData data; }; constexpr auto kMaxInnerOffset = 0.5; @@ -396,7 +392,7 @@ SwipeBackResult SetupSwipeBack( }; }; - const auto callback = ([=](ChatPaintGestureHorizontalData data) { + const auto callback = ([=](SwipeContextData data) { const auto ratio = std::min(1.0, data.ratio); state->data = std::move(data); if (ratio > 0) { diff --git a/Telegram/SourceFiles/ui/controls/swipe_handler.h b/Telegram/SourceFiles/ui/controls/swipe_handler.h index 92325ec9c5..ac3f5f014b 100644 --- a/Telegram/SourceFiles/ui/controls/swipe_handler.h +++ b/Telegram/SourceFiles/ui/controls/swipe_handler.h @@ -7,11 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -namespace HistoryView { -struct ChatPaintGestureHorizontalData; -struct SwipeBackResult; -} // namespace HistoryView - namespace Ui { class ElasticScroll; class RpWidget; @@ -20,6 +15,9 @@ class ScrollArea; namespace Ui::Controls { +struct SwipeContextData; +struct SwipeBackResult; + struct SwipeHandlerFinishData { Fn callback; int64 msgBareId = 0; @@ -34,11 +32,11 @@ using Scroll = std::variant< void SetupSwipeHandler( not_null widget, Scroll scroll, - Fn update, + Fn update, Fn generateFinishByTop, rpl::producer dontStart = nullptr); -[[nodiscard]] HistoryView::SwipeBackResult SetupSwipeBack( +[[nodiscard]] SwipeBackResult SetupSwipeBack( not_null widget, Fn()> colors, bool mirrored = false); diff --git a/Telegram/SourceFiles/history/history_view_swipe_data.h b/Telegram/SourceFiles/ui/controls/swipe_handler_data.h similarity index 75% rename from Telegram/SourceFiles/history/history_view_swipe_data.h rename to Telegram/SourceFiles/ui/controls/swipe_handler_data.h index 3d2d356c4c..b90b5351f5 100644 --- a/Telegram/SourceFiles/history/history_view_swipe_data.h +++ b/Telegram/SourceFiles/ui/controls/swipe_handler_data.h @@ -7,9 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -namespace HistoryView { +namespace Ui::Controls { -struct ChatPaintGestureHorizontalData { +struct SwipeContextData final { float64 ratio = 0.; float64 reachRatio = 0.; int64 msgBareId = 0; @@ -19,7 +19,7 @@ struct ChatPaintGestureHorizontalData { struct SwipeBackResult final { rpl::lifetime lifetime; - Fn callback; + Fn callback; }; -} // namespace HistoryView +} // namespace Ui::Controls diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index 8eadb9a9c0..321fcbdbc9 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -129,7 +129,6 @@ PRIVATE history/admin_log/history_admin_log_filter_value.h history/history_view_top_toast.cpp history/history_view_top_toast.h - history/history_view_swipe_data.h history/view/controls/history_view_characters_limit.cpp history/view/controls/history_view_characters_limit.h history/view/controls/history_view_voice_record_button.cpp @@ -382,6 +381,7 @@ PRIVATE ui/controls/send_button.h ui/controls/swipe_handler.cpp ui/controls/swipe_handler.h + ui/controls/swipe_handler_data.h ui/controls/tabbed_search.cpp ui/controls/tabbed_search.h ui/controls/who_reacted_context_action.cpp