From e8dd2b9e7b72a0fd7952f3d2180fbeff7926ecc9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 3 Sep 2024 22:14:32 +0400 Subject: [PATCH] Use only integer translations in reply swipe. --- .../SourceFiles/history/history_inner_widget.cpp | 16 ++++++++++------ .../SourceFiles/history/history_view_swipe.cpp | 2 +- .../history/history_view_swipe_data.h | 2 +- .../history/view/history_view_list_widget.cpp | 2 +- .../history/view/history_view_message.cpp | 2 +- .../view/history_view_replies_section.cpp | 15 +++++++++------ 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index e3662fc16..b7687266e 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -581,12 +581,16 @@ void HistoryInner::setupSharingDisallowed() { void HistoryInner::setupSwipeReply() { HistoryView::SetupSwipeHandler(this, _scroll, [=, history = _history]( HistoryView::ChatPaintGestureHorizontalData data) { + const auto changed = (_gestureHorizontal.msgBareId != data.msgBareId) + || (_gestureHorizontal.translation != data.translation); _gestureHorizontal = data; - const auto item = history->peer->owner().message( - history->peer->id, - MsgId{ data.msgBareId }); - if (item) { - repaintItem(item); + if (changed) { + const auto item = history->peer->owner().message( + history->peer->id, + MsgId{ data.msgBareId }); + if (item) { + repaintItem(item); + } } }, [=, show = _controller->uiShow()](int cursorTop) { auto result = HistoryView::SwipeHandlerFinishData(); @@ -1230,7 +1234,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) { // paint the userpic if it intersects the painted rect if (userpicTop + st::msgPhotoSize > clip.top()) { const auto item = view->data(); - const auto hasTranslation = _gestureHorizontal.ratio + const auto hasTranslation = _gestureHorizontal.translation && (_gestureHorizontal.msgBareId == item->fullId().msg.bare); if (hasTranslation) { p.translate(_gestureHorizontal.translation, 0); diff --git a/Telegram/SourceFiles/history/history_view_swipe.cpp b/Telegram/SourceFiles/history/history_view_swipe.cpp index e7034bece..81769891a 100644 --- a/Telegram/SourceFiles/history/history_view_swipe.cpp +++ b/Telegram/SourceFiles/history/history_view_swipe.cpp @@ -48,7 +48,7 @@ void SetupSwipeHandler( update({ .ratio = std::clamp(ratio, 0., 1.5), .reachRatio = state->animationReach.value(0.), - .translation = (-std::clamp(ratio, 0., 1.5) * threshold), + .translation = int(base::SafeRound(-std::clamp(ratio, 0., 1.5) * threshold)), .msgBareId = state->finishByTopData.msgBareId, .cursorTop = state->cursorTop, }); diff --git a/Telegram/SourceFiles/history/history_view_swipe_data.h b/Telegram/SourceFiles/history/history_view_swipe_data.h index a08ef8e2c..c3dd9eb77 100644 --- a/Telegram/SourceFiles/history/history_view_swipe_data.h +++ b/Telegram/SourceFiles/history/history_view_swipe_data.h @@ -12,8 +12,8 @@ namespace HistoryView { struct ChatPaintGestureHorizontalData { float64 ratio = 0.; float64 reachRatio = 0.; - float64 translation = 0.; int64 msgBareId = 0; + int translation = 0; int cursorTop = 0; }; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 4031a4f36..c6b0fd066 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -2305,7 +2305,7 @@ void ListWidget::paintUserpics( // paint the userpic if it intersects the painted rect if (userpicTop + st::msgPhotoSize > clip.top()) { const auto item = view->data(); - const auto hasTranslation = context.gestureHorizontal.ratio + const auto hasTranslation = context.gestureHorizontal.translation && (context.gestureHorizontal.msgBareId == item->fullId().msg.bare); if (hasTranslation) { p.translate(context.gestureHorizontal.translation, 0); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 669ad90fa..c84cf1779 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1092,7 +1092,7 @@ void Message::draw(Painter &p, const PaintContext &context) const { const auto item = data(); const auto media = this->media(); - const auto hasGesture = context.gestureHorizontal.ratio + const auto hasGesture = context.gestureHorizontal.translation && (context.gestureHorizontal.msgBareId == item->fullId().msg.bare); if (hasGesture) { p.translate(context.gestureHorizontal.translation, 0); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index baf644137..def3156c2 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -882,13 +882,16 @@ void RepliesWidget::setupSwipeReply() { }; HistoryView::SetupSwipeHandler(_inner, _scroll.get(), [=]( HistoryView::ChatPaintGestureHorizontalData data) { + const auto changed = (_gestureHorizontal.msgBareId != data.msgBareId) + || (_gestureHorizontal.translation != data.translation); _gestureHorizontal = data; - const auto item = _history->peer->owner().message( - _history->peer->id, - MsgId{ data.msgBareId }); - if (item) { - _inner->update(); - // repaintItem(item); + if (changed) { + const auto item = _history->peer->owner().message( + _history->peer->id, + MsgId{ data.msgBareId }); + if (item) { + _history->owner().requestItemRepaint(item); + } } }, [=, show = controller()->uiShow()](int cursorTop) { auto result = HistoryView::SwipeHandlerFinishData();