mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-02 20:03:59 +02:00
Increased speed of swipe-to-back.
This commit is contained in:
parent
d02e55da06
commit
6bed3f3f09
8 changed files with 54 additions and 46 deletions
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -27,6 +27,9 @@ namespace {
|
|||
|
||||
constexpr auto kSwipeSlow = 0.2;
|
||||
|
||||
constexpr auto kMsgBareIdSwipeBack = std::numeric_limits<int64>::max() - 77;
|
||||
constexpr auto kSwipedBackSpeedRatio = 0.35;
|
||||
|
||||
} // namespace
|
||||
|
||||
void SetupSwipeHandler(
|
||||
|
@ -37,7 +40,6 @@ void SetupSwipeHandler(
|
|||
rpl::producer<bool> 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<Qt::Orientation> orientation;
|
||||
std::optional<Qt::LayoutDirection> 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<void(void)> callback) {
|
||||
return {
|
||||
.callback = std::move(callback),
|
||||
.msgBareId = kMsgBareIdSwipeBack,
|
||||
.speedRatio = kSwipedBackSpeedRatio,
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace HistoryView
|
||||
|
|
|
@ -18,11 +18,10 @@ namespace HistoryView {
|
|||
struct ChatPaintGestureHorizontalData;
|
||||
struct SwipeBackResult;
|
||||
|
||||
constexpr auto kMsgBareIdSwipeBack = std::numeric_limits<int64>::max() - 77;
|
||||
|
||||
struct SwipeHandlerFinishData {
|
||||
Fn<void(void)> callback;
|
||||
int64 msgBareId = 0;
|
||||
float64 speedRatio = 1.0;
|
||||
};
|
||||
|
||||
using Scroll = std::variant<
|
||||
|
@ -37,8 +36,11 @@ void SetupSwipeHandler(
|
|||
Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinishByTop,
|
||||
rpl::producer<bool> dontStart = nullptr);
|
||||
|
||||
SwipeBackResult SetupSwipeBack(
|
||||
[[nodiscard]] SwipeBackResult SetupSwipeBack(
|
||||
not_null<Ui::RpWidget*> widget,
|
||||
Fn<std::pair<QColor, QColor>()> colors);
|
||||
|
||||
[[nodiscard]] SwipeHandlerFinishData DefaultSwipeBackHandlerFinishData(
|
||||
Fn<void(void)> callback);
|
||||
|
||||
} // namespace HistoryView
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue