Moved out data for swipe handler from history view to ui controls.

This commit is contained in:
23rd 2025-02-19 00:21:05 +03:00 committed by John Preston
parent 5cdfaab2db
commit de87bed375
19 changed files with 41 additions and 47 deletions

View file

@ -534,7 +534,7 @@ TabbedSelector::~TabbedSelector() = default;
void TabbedSelector::setupSwipe() { void TabbedSelector::setupSwipe() {
Ui::Controls::SetupSwipeHandler(this, _scroll.data(), [=]( Ui::Controls::SetupSwipeHandler(this, _scroll.data(), [=](
HistoryView::ChatPaintGestureHorizontalData data) { Ui::Controls::SwipeContextData data) {
if (data.translation != 0) { if (data.translation != 0) {
if (!_swipeBackData.callback) { if (!_swipeBackData.callback) {
_swipeBackData = Ui::Controls::SetupSwipeBack( _swipeBackData = Ui::Controls::SetupSwipeBack(

View file

@ -10,10 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_common.h" #include "api/api_common.h"
#include "chat_helpers/compose/compose_features.h" #include "chat_helpers/compose/compose_features.h"
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
#include "ui/controls/swipe_handler_data.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/effects/message_sending_animation_common.h" #include "ui/effects/message_sending_animation_common.h"
#include "ui/effects/panel_animation.h" #include "ui/effects/panel_animation.h"
#include "history/history_view_swipe_data.h"
#include "ui/cached_round_corners.h" #include "ui/cached_round_corners.h"
#include "mtproto/sender.h" #include "mtproto/sender.h"
#include "base/object_ptr.h" #include "base/object_ptr.h"
@ -296,7 +296,7 @@ private:
const PauseReason _level = {}; const PauseReason _level = {};
const Fn<QColor()> _customTextColor; const Fn<QColor()> _customTextColor;
HistoryView::SwipeBackResult _swipeBackData; Ui::Controls::SwipeBackResult _swipeBackData;
Mode _mode = Mode::Full; Mode _mode = Mode::Full;
int _roundRadius = 0; int _roundRadius = 0;

View file

@ -678,7 +678,7 @@ Widget::Widget(
void Widget::setupSwipeBack() { void Widget::setupSwipeBack() {
Ui::Controls::SetupSwipeHandler(_scroll.data(), _scroll.data(), [=]( Ui::Controls::SetupSwipeHandler(_scroll.data(), _scroll.data(), [=](
HistoryView::ChatPaintGestureHorizontalData data) { Ui::Controls::SwipeContextData data) {
if (data.translation > 0) { if (data.translation > 0) {
if (!_swipeBackData.callback) { if (!_swipeBackData.callback) {
_swipeBackData = Ui::Controls::SetupSwipeBack( _swipeBackData = Ui::Controls::SetupSwipeBack(

View file

@ -9,8 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/timer.h" #include "base/timer.h"
#include "dialogs/dialogs_key.h" #include "dialogs/dialogs_key.h"
#include "history/history_view_swipe_data.h"
#include "window/section_widget.h" #include "window/section_widget.h"
#include "ui/controls/swipe_handler_data.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/userpic_view.h" #include "ui/userpic_view.h"
#include "mtproto/sender.h" #include "mtproto/sender.h"
@ -385,7 +385,7 @@ private:
ChatSearchTab _searchQueryTab = {}; ChatSearchTab _searchQueryTab = {};
ChatTypeFilter _searchQueryFilter = {}; ChatTypeFilter _searchQueryFilter = {};
HistoryView::SwipeBackResult _swipeBackData; Ui::Controls::SwipeBackResult _swipeBackData;
SearchProcessState _searchProcess; SearchProcessState _searchProcess;
SearchProcessState _migratedProcess; SearchProcessState _migratedProcess;

View file

@ -421,7 +421,7 @@ void Widget::setupShortcuts() {
void Widget::setupSwipeReply() { void Widget::setupSwipeReply() {
Ui::Controls::SetupSwipeHandler(this, _scroll.data(), [=]( Ui::Controls::SetupSwipeHandler(this, _scroll.data(), [=](
HistoryView::ChatPaintGestureHorizontalData data) { Ui::Controls::SwipeContextData data) {
if (data.translation > 0) { if (data.translation > 0) {
if (!_swipeBackData.callback) { if (!_swipeBackData.callback) {
_swipeBackData = Ui::Controls::SetupSwipeBack( _swipeBackData = Ui::Controls::SetupSwipeBack(

View file

@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/section_memento.h" #include "window/section_memento.h"
#include "history/admin_log/history_admin_log_item.h" #include "history/admin_log/history_admin_log_item.h"
#include "history/admin_log/history_admin_log_filter_value.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" #include "mtproto/sender.h"
namespace Ui { namespace Ui {
@ -83,7 +83,7 @@ private:
object_ptr<Ui::PlainShadow> _fixedBarShadow; object_ptr<Ui::PlainShadow> _fixedBarShadow;
object_ptr<Ui::FlatButton> _whatIsThis; object_ptr<Ui::FlatButton> _whatIsThis;
HistoryView::SwipeBackResult _swipeBackData; Ui::Controls::SwipeBackResult _swipeBackData;
}; };

View file

@ -529,7 +529,7 @@ void HistoryInner::setupSwipeReplyAndBack() {
} }
const auto peer = _peer; const auto peer = _peer;
Ui::Controls::SetupSwipeHandler(this, _scroll, [=, history = _history]( Ui::Controls::SetupSwipeHandler(this, _scroll, [=, history = _history](
HistoryView::ChatPaintGestureHorizontalData data) { Ui::Controls::SwipeContextData data) {
if (data.translation > 0) { if (data.translation > 0) {
if (!_swipeBackData.callback) { if (!_swipeBackData.callback) {
_swipeBackData = Ui::Controls::SetupSwipeBack( _swipeBackData = Ui::Controls::SetupSwipeBack(

View file

@ -10,11 +10,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/timer.h" #include "base/timer.h"
#include "data/data_report.h" #include "data/data_report.h"
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
#include "ui/controls/swipe_handler_data.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/dragging_scroll_manager.h" #include "ui/dragging_scroll_manager.h"
#include "ui/widgets/tooltip.h" #include "ui/widgets/tooltip.h"
#include "ui/widgets/scroll_area.h" #include "ui/widgets/scroll_area.h"
#include "history/history_view_swipe_data.h"
#include "history/view/history_view_top_bar_widget.h" #include "history/view/history_view_top_bar_widget.h"
#include <QtGui/QPainterPath> #include <QtGui/QPainterPath>
@ -543,8 +543,8 @@ private:
crl::time _touchTime = 0; crl::time _touchTime = 0;
base::Timer _touchScrollTimer; base::Timer _touchScrollTimer;
HistoryView::ChatPaintGestureHorizontalData _gestureHorizontal; Ui::Controls::SwipeContextData _gestureHorizontal;
HistoryView::SwipeBackResult _swipeBackData; Ui::Controls::SwipeBackResult _swipeBackData;
// _menu must be destroyed before _whoReactedMenuLifetime. // _menu must be destroyed before _whoReactedMenuLifetime.
rpl::lifetime _whoReactedMenuLifetime; rpl::lifetime _whoReactedMenuLifetime;

View file

@ -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_back_session.h"
#include "history/history_view_swipe_data.h"
#include "history/view/history_view_list_widget.h" #include "history/view/history_view_list_widget.h"
#include "ui/chat/chat_style.h" #include "ui/chat/chat_style.h"
#include "ui/controls/swipe_handler.h" #include "ui/controls/swipe_handler.h"
#include "ui/controls/swipe_handler_data.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
namespace Window { namespace Window {
@ -20,9 +20,9 @@ void SetupSwipeBackSection(
not_null<Ui::ScrollArea*> scroll, not_null<Ui::ScrollArea*> scroll,
not_null<HistoryView::ListWidget*> list) { not_null<HistoryView::ListWidget*> list) {
const auto swipeBackData const auto swipeBackData
= list->lifetime().make_state<HistoryView::SwipeBackResult>(); = list->lifetime().make_state<Ui::Controls::SwipeBackResult>();
Ui::Controls::SetupSwipeHandler(parent, scroll, [=]( Ui::Controls::SetupSwipeHandler(parent, scroll, [=](
HistoryView::ChatPaintGestureHorizontalData data) { Ui::Controls::SwipeContextData data) {
if (data.translation > 0) { if (data.translation > 0) {
if (!swipeBackData->callback) { if (!swipeBackData->callback) {
const auto color = [=]() -> std::pair<QColor, QColor> { const auto color = [=]() -> std::pair<QColor, QColor> {

View file

@ -53,13 +53,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/controls/send_as_button.h" #include "ui/controls/send_as_button.h"
#include "ui/controls/silent_toggle.h" #include "ui/controls/silent_toggle.h"
#include "ui/controls/swipe_handler.h" #include "ui/controls/swipe_handler.h"
#include "ui/controls/swipe_handler_data.h"
#include "ui/ui_utility.h" #include "ui/ui_utility.h"
#include "inline_bots/inline_bot_result.h" #include "inline_bots/inline_bot_result.h"
#include "base/event_filter.h" #include "base/event_filter.h"
#include "base/qt_signal_producer.h" #include "base/qt_signal_producer.h"
#include "base/qt/qt_key_modifiers.h" #include "base/qt/qt_key_modifiers.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "history/history_view_swipe_data.h"
#include "base/call_delayed.h" #include "base/call_delayed.h"
#include "data/business/data_shortcut_messages.h" #include "data/business/data_shortcut_messages.h"
#include "data/components/credits.h" #include "data/components/credits.h"

View file

@ -891,7 +891,7 @@ void RepliesWidget::setupSwipeReplyAndBack() {
return false; return false;
}; };
Ui::Controls::SetupSwipeHandler(_inner, _scroll.get(), [=]( Ui::Controls::SetupSwipeHandler(_inner, _scroll.get(), [=](
HistoryView::ChatPaintGestureHorizontalData data) { Ui::Controls::SwipeContextData data) {
if (data.translation > 0) { if (data.translation > 0) {
if (!_swipeBackData.callback) { if (!_swipeBackData.callback) {
_swipeBackData = Ui::Controls::SetupSwipeBack( _swipeBackData = Ui::Controls::SetupSwipeBack(

View file

@ -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_corner_buttons.h"
#include "history/view/history_view_list_widget.h" #include "history/view/history_view_list_widget.h"
#include "history/history_item_helpers.h" #include "history/history_item_helpers.h"
#include "history/history_view_swipe_data.h"
#include "data/data_messages.h" #include "data/data_messages.h"
#include "ui/controls/swipe_handler_data.h"
#include "base/timer.h" #include "base/timer.h"
class History; class History;
@ -393,8 +393,8 @@ private:
HistoryView::CornerButtons _cornerButtons; HistoryView::CornerButtons _cornerButtons;
rpl::lifetime _topicLifetime; rpl::lifetime _topicLifetime;
HistoryView::ChatPaintGestureHorizontalData _gestureHorizontal; Ui::Controls::SwipeContextData _gestureHorizontal;
HistoryView::SwipeBackResult _swipeBackData; Ui::Controls::SwipeBackResult _swipeBackData;
SendPaymentHelper _sendPayment; SendPaymentHelper _sendPayment;

View file

@ -386,7 +386,7 @@ not_null<Ui::ScrollArea*> ContentWidget::scroll() const {
void ContentWidget::setupSwipeReply() { void ContentWidget::setupSwipeReply() {
Ui::Controls::SetupSwipeHandler(this, _scroll.data(), [=]( Ui::Controls::SetupSwipeHandler(this, _scroll.data(), [=](
HistoryView::ChatPaintGestureHorizontalData data) { Ui::Controls::SwipeContextData data) {
if (data.translation > 0) { if (data.translation > 0) {
if (!_swipeBackData.callback) { if (!_swipeBackData.callback) {
_swipeBackData = Ui::Controls::SetupSwipeBack( _swipeBackData = Ui::Controls::SetupSwipeBack(

View file

@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/info_wrap_widget.h" #include "info/info_wrap_widget.h"
#include "info/statistics/info_statistics_tag.h" #include "info/statistics/info_statistics_tag.h"
#include "history/history_view_swipe_data.h" #include "ui/controls/swipe_handler_data.h"
namespace Api { namespace Api {
struct WhoReadList; struct WhoReadList;
@ -192,7 +192,7 @@ private:
// To paint round edges from content. // To paint round edges from content.
style::margins _paintPadding; style::margins _paintPadding;
HistoryView::SwipeBackResult _swipeBackData; Ui::Controls::SwipeBackResult _swipeBackData;
}; };

View file

@ -10,8 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/cached_round_corners.h" #include "ui/cached_round_corners.h"
#include "ui/chat/message_bubble.h" #include "ui/chat/message_bubble.h"
#include "ui/chat/chat_style_radius.h" #include "ui/chat/chat_style_radius.h"
#include "ui/controls/swipe_handler_data.h"
#include "ui/style/style_core_palette.h" #include "ui/style/style_core_palette.h"
#include "history/history_view_swipe_data.h"
#include "layout/layout_selection.h" #include "layout/layout_selection.h"
#include "styles/style_basic.h" #include "styles/style_basic.h"
@ -165,7 +165,7 @@ struct ChatPaintContext {
QPainterPath *highlightPathCache = nullptr; QPainterPath *highlightPathCache = nullptr;
mutable QRect highlightInterpolateTo; mutable QRect highlightInterpolateTo;
crl::time now = 0; crl::time now = 0;
HistoryView::ChatPaintGestureHorizontalData gestureHorizontal; Ui::Controls::SwipeContextData gestureHorizontal;
void translate(int x, int y) { void translate(int x, int y) {
viewport.translate(x, y); viewport.translate(x, y);

View file

@ -11,8 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "base/qt/qt_common_adapters.h" #include "base/qt/qt_common_adapters.h"
#include "base/event_filter.h" #include "base/event_filter.h"
#include "history/history_view_swipe_data.h"
#include "ui/chat/chat_style.h" #include "ui/chat/chat_style.h"
#include "ui/controls/swipe_handler_data.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "ui/rect.h" #include "ui/rect.h"
#include "ui/ui_utility.h" #include "ui/ui_utility.h"
@ -30,16 +30,12 @@ constexpr auto kSwipeSlow = 0.2;
constexpr auto kMsgBareIdSwipeBack = std::numeric_limits<int64>::max() - 77; constexpr auto kMsgBareIdSwipeBack = std::numeric_limits<int64>::max() - 77;
constexpr auto kSwipedBackSpeedRatio = 0.35; constexpr auto kSwipedBackSpeedRatio = 0.35;
using ChatPaintGestureHorizontalData
= HistoryView::ChatPaintGestureHorizontalData;
using SwipeBackResult = HistoryView::SwipeBackResult;
} // namespace } // namespace
void SetupSwipeHandler( void SetupSwipeHandler(
not_null<Ui::RpWidget*> widget, not_null<Ui::RpWidget*> widget,
Scroll scroll, Scroll scroll,
Fn<void(ChatPaintGestureHorizontalData)> update, Fn<void(SwipeContextData)> update,
Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinish, Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinish,
rpl::producer<bool> dontStart) { rpl::producer<bool> dontStart) {
constexpr auto kThresholdWidth = 50; constexpr auto kThresholdWidth = 50;
@ -54,7 +50,7 @@ void SetupSwipeHandler(
base::unique_qptr<QObject> filter; base::unique_qptr<QObject> filter;
Ui::Animations::Simple animationReach; Ui::Animations::Simple animationReach;
Ui::Animations::Simple animationEnd; Ui::Animations::Simple animationEnd;
ChatPaintGestureHorizontalData data; SwipeContextData data;
SwipeHandlerFinishData finishByTopData; SwipeHandlerFinishData finishByTopData;
std::optional<Qt::Orientation> orientation; std::optional<Qt::Orientation> orientation;
std::optional<Qt::LayoutDirection> direction; std::optional<Qt::LayoutDirection> direction;
@ -306,7 +302,7 @@ SwipeBackResult SetupSwipeBack(
bool mirrored) { bool mirrored) {
struct State { struct State {
base::unique_qptr<Ui::RpWidget> back; base::unique_qptr<Ui::RpWidget> back;
ChatPaintGestureHorizontalData data; SwipeContextData data;
}; };
constexpr auto kMaxInnerOffset = 0.5; 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); const auto ratio = std::min(1.0, data.ratio);
state->data = std::move(data); state->data = std::move(data);
if (ratio > 0) { if (ratio > 0) {

View file

@ -7,11 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
namespace HistoryView {
struct ChatPaintGestureHorizontalData;
struct SwipeBackResult;
} // namespace HistoryView
namespace Ui { namespace Ui {
class ElasticScroll; class ElasticScroll;
class RpWidget; class RpWidget;
@ -20,6 +15,9 @@ class ScrollArea;
namespace Ui::Controls { namespace Ui::Controls {
struct SwipeContextData;
struct SwipeBackResult;
struct SwipeHandlerFinishData { struct SwipeHandlerFinishData {
Fn<void(void)> callback; Fn<void(void)> callback;
int64 msgBareId = 0; int64 msgBareId = 0;
@ -34,11 +32,11 @@ using Scroll = std::variant<
void SetupSwipeHandler( void SetupSwipeHandler(
not_null<Ui::RpWidget*> widget, not_null<Ui::RpWidget*> widget,
Scroll scroll, Scroll scroll,
Fn<void(HistoryView::ChatPaintGestureHorizontalData)> update, Fn<void(SwipeContextData)> update,
Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinishByTop, Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinishByTop,
rpl::producer<bool> dontStart = nullptr); rpl::producer<bool> dontStart = nullptr);
[[nodiscard]] HistoryView::SwipeBackResult SetupSwipeBack( [[nodiscard]] SwipeBackResult SetupSwipeBack(
not_null<Ui::RpWidget*> widget, not_null<Ui::RpWidget*> widget,
Fn<std::pair<QColor, QColor>()> colors, Fn<std::pair<QColor, QColor>()> colors,
bool mirrored = false); bool mirrored = false);

View file

@ -7,9 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
namespace HistoryView { namespace Ui::Controls {
struct ChatPaintGestureHorizontalData { struct SwipeContextData final {
float64 ratio = 0.; float64 ratio = 0.;
float64 reachRatio = 0.; float64 reachRatio = 0.;
int64 msgBareId = 0; int64 msgBareId = 0;
@ -19,7 +19,7 @@ struct ChatPaintGestureHorizontalData {
struct SwipeBackResult final { struct SwipeBackResult final {
rpl::lifetime lifetime; rpl::lifetime lifetime;
Fn<void(ChatPaintGestureHorizontalData)> callback; Fn<void(SwipeContextData)> callback;
}; };
} // namespace HistoryView } // namespace Ui::Controls

View file

@ -129,7 +129,6 @@ PRIVATE
history/admin_log/history_admin_log_filter_value.h history/admin_log/history_admin_log_filter_value.h
history/history_view_top_toast.cpp history/history_view_top_toast.cpp
history/history_view_top_toast.h 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.cpp
history/view/controls/history_view_characters_limit.h history/view/controls/history_view_characters_limit.h
history/view/controls/history_view_voice_record_button.cpp history/view/controls/history_view_voice_record_button.cpp
@ -382,6 +381,7 @@ PRIVATE
ui/controls/send_button.h ui/controls/send_button.h
ui/controls/swipe_handler.cpp ui/controls/swipe_handler.cpp
ui/controls/swipe_handler.h ui/controls/swipe_handler.h
ui/controls/swipe_handler_data.h
ui/controls/tabbed_search.cpp ui/controls/tabbed_search.cpp
ui/controls/tabbed_search.h ui/controls/tabbed_search.h
ui/controls/who_reacted_context_action.cpp ui/controls/who_reacted_context_action.cpp