mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 07:33:52 +02:00
Added initial ability to handle history view swipe in both directions.
This commit is contained in:
parent
11d0f9db03
commit
17a10cf6bb
1 changed files with 26 additions and 4 deletions
|
@ -48,6 +48,8 @@ void SetupSwipeHandler(
|
||||||
ChatPaintGestureHorizontalData data;
|
ChatPaintGestureHorizontalData data;
|
||||||
SwipeHandlerFinishData finishByTopData;
|
SwipeHandlerFinishData finishByTopData;
|
||||||
std::optional<Qt::Orientation> orientation;
|
std::optional<Qt::Orientation> orientation;
|
||||||
|
std::optional<Qt::LayoutDirection> direction;
|
||||||
|
int directionInt = 1.;
|
||||||
QPointF startAt;
|
QPointF startAt;
|
||||||
QPointF delta;
|
QPointF delta;
|
||||||
int cursorTop = 0;
|
int cursorTop = 0;
|
||||||
|
@ -75,7 +77,8 @@ void SetupSwipeHandler(
|
||||||
base::SafeRound(-overscrollRatio * threshold)
|
base::SafeRound(-overscrollRatio * threshold)
|
||||||
));
|
));
|
||||||
state->data.msgBareId = state->finishByTopData.msgBareId;
|
state->data.msgBareId = state->finishByTopData.msgBareId;
|
||||||
state->data.translation = translation;
|
state->data.translation = translation
|
||||||
|
* state->directionInt;
|
||||||
state->data.cursorTop = state->cursorTop;
|
state->data.cursorTop = state->cursorTop;
|
||||||
update(state->data);
|
update(state->data);
|
||||||
};
|
};
|
||||||
|
@ -90,7 +93,9 @@ void SetupSwipeHandler(
|
||||||
const auto processEnd = [=](std::optional<QPointF> delta = {}) {
|
const auto processEnd = [=](std::optional<QPointF> delta = {}) {
|
||||||
if (state->orientation == Qt::Horizontal) {
|
if (state->orientation == Qt::Horizontal) {
|
||||||
const auto ratio = std::clamp(
|
const auto ratio = std::clamp(
|
||||||
delta.value_or(state->delta).x() / threshold,
|
delta.value_or(state->delta).x()
|
||||||
|
/ threshold
|
||||||
|
* state->directionInt,
|
||||||
0.,
|
0.,
|
||||||
kMaxRatio);
|
kMaxRatio);
|
||||||
if ((ratio >= 1) && state->finishByTopData.callback) {
|
if ((ratio >= 1) && state->finishByTopData.callback) {
|
||||||
|
@ -108,6 +113,9 @@ void SetupSwipeHandler(
|
||||||
setOrientation(std::nullopt);
|
setOrientation(std::nullopt);
|
||||||
state->started = false;
|
state->started = false;
|
||||||
state->reached = false;
|
state->reached = false;
|
||||||
|
state->direction = std::nullopt;
|
||||||
|
state->startAt = {};
|
||||||
|
state->delta = {};
|
||||||
};
|
};
|
||||||
scroll->scrolls() | rpl::start_with_next([=] {
|
scroll->scrolls() | rpl::start_with_next([=] {
|
||||||
if (state->orientation != Qt::Vertical) {
|
if (state->orientation != Qt::Vertical) {
|
||||||
|
@ -119,7 +127,19 @@ void SetupSwipeHandler(
|
||||||
update(state->data);
|
update(state->data);
|
||||||
};
|
};
|
||||||
const auto updateWith = [=](UpdateArgs args) {
|
const auto updateWith = [=](UpdateArgs args) {
|
||||||
if (!state->started || state->touch != args.touch) {
|
if (!state->started
|
||||||
|
|| state->touch != args.touch
|
||||||
|
|| !state->direction) {
|
||||||
|
state->direction = (args.delta.x() == 0)
|
||||||
|
? std::nullopt
|
||||||
|
: args.delta.x() < 0
|
||||||
|
? std::make_optional(Qt::RightToLeft)
|
||||||
|
: std::make_optional(Qt::LeftToRight);
|
||||||
|
state->directionInt = (!state->direction
|
||||||
|
|| (*state->direction) == Qt::LeftToRight)
|
||||||
|
? 1
|
||||||
|
: -1;
|
||||||
|
|
||||||
state->started = true;
|
state->started = true;
|
||||||
state->touch = args.touch;
|
state->touch = args.touch;
|
||||||
state->startAt = args.position;
|
state->startAt = args.position;
|
||||||
|
@ -146,7 +166,9 @@ void SetupSwipeHandler(
|
||||||
}
|
}
|
||||||
} else if (*state->orientation == Qt::Horizontal) {
|
} else if (*state->orientation == Qt::Horizontal) {
|
||||||
state->delta = args.delta;
|
state->delta = args.delta;
|
||||||
const auto ratio = args.delta.x() / threshold;
|
const auto ratio = args.delta.x()
|
||||||
|
* state->directionInt
|
||||||
|
/ threshold;
|
||||||
updateRatio(ratio);
|
updateRatio(ratio);
|
||||||
constexpr auto kResetReachedOn = 0.95;
|
constexpr auto kResetReachedOn = 0.95;
|
||||||
constexpr auto kBounceDuration = crl::time(500);
|
constexpr auto kBounceDuration = crl::time(500);
|
||||||
|
|
Loading…
Add table
Reference in a new issue