mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Added ability to provide ElasticScroll to SetupSwipeHandler.
This commit is contained in:
parent
540fa0e669
commit
d93d8ab1cc
2 changed files with 25 additions and 11 deletions
|
@ -31,7 +31,7 @@ constexpr auto kSwipeSlow = 0.2;
|
||||||
|
|
||||||
void SetupSwipeHandler(
|
void SetupSwipeHandler(
|
||||||
not_null<Ui::RpWidget*> widget,
|
not_null<Ui::RpWidget*> widget,
|
||||||
not_null<Ui::ScrollArea*> scroll,
|
Scroll scroll,
|
||||||
Fn<void(ChatPaintGestureHorizontalData)> update,
|
Fn<void(ChatPaintGestureHorizontalData)> update,
|
||||||
Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinish,
|
Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinish,
|
||||||
rpl::producer<bool> dontStart) {
|
rpl::producer<bool> dontStart) {
|
||||||
|
@ -88,10 +88,15 @@ void SetupSwipeHandler(
|
||||||
const auto setOrientation = [=](std::optional<Qt::Orientation> o) {
|
const auto setOrientation = [=](std::optional<Qt::Orientation> o) {
|
||||||
state->orientation = o;
|
state->orientation = o;
|
||||||
const auto isHorizontal = (o == Qt::Horizontal);
|
const auto isHorizontal = (o == Qt::Horizontal);
|
||||||
scroll->viewport()->setAttribute(
|
v::match(scroll, [](v::null_t) {
|
||||||
Qt::WA_AcceptTouchEvents,
|
}, [&](const auto &scroll) {
|
||||||
!isHorizontal);
|
if (const auto viewport = scroll->viewport()) {
|
||||||
scroll->disableScroll(isHorizontal);
|
viewport->setAttribute(
|
||||||
|
Qt::WA_AcceptTouchEvents,
|
||||||
|
!isHorizontal);
|
||||||
|
}
|
||||||
|
scroll->disableScroll(isHorizontal);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
const auto processEnd = [=](std::optional<QPointF> delta = {}) {
|
const auto processEnd = [=](std::optional<QPointF> delta = {}) {
|
||||||
if (state->orientation == Qt::Horizontal) {
|
if (state->orientation == Qt::Horizontal) {
|
||||||
|
@ -120,11 +125,14 @@ void SetupSwipeHandler(
|
||||||
state->startAt = {};
|
state->startAt = {};
|
||||||
state->delta = {};
|
state->delta = {};
|
||||||
};
|
};
|
||||||
scroll->scrolls() | rpl::start_with_next([=] {
|
v::match(scroll, [](v::null_t) {
|
||||||
if (state->orientation != Qt::Vertical) {
|
}, [&](const auto &scroll) {
|
||||||
processEnd();
|
scroll->scrolls() | rpl::start_with_next([=] {
|
||||||
}
|
if (state->orientation != Qt::Vertical) {
|
||||||
}, state->lifetime);
|
processEnd();
|
||||||
|
}
|
||||||
|
}, state->lifetime);
|
||||||
|
});
|
||||||
const auto animationReachCallback = [=](float64 value) {
|
const auto animationReachCallback = [=](float64 value) {
|
||||||
state->data.reachRatio = value;
|
state->data.reachRatio = value;
|
||||||
update(state->data);
|
update(state->data);
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
class ElasticScroll;
|
||||||
class RpWidget;
|
class RpWidget;
|
||||||
class ScrollArea;
|
class ScrollArea;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
@ -24,9 +25,14 @@ struct SwipeHandlerFinishData {
|
||||||
int64 msgBareId = 0;
|
int64 msgBareId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using Scroll = std::variant<
|
||||||
|
v::null_t,
|
||||||
|
not_null<Ui::ScrollArea*>,
|
||||||
|
not_null<Ui::ElasticScroll*>>;
|
||||||
|
|
||||||
void SetupSwipeHandler(
|
void SetupSwipeHandler(
|
||||||
not_null<Ui::RpWidget*> widget,
|
not_null<Ui::RpWidget*> widget,
|
||||||
not_null<Ui::ScrollArea*> scroll,
|
Scroll scroll,
|
||||||
Fn<void(ChatPaintGestureHorizontalData)> update,
|
Fn<void(ChatPaintGestureHorizontalData)> update,
|
||||||
Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinishByTop,
|
Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinishByTop,
|
||||||
rpl::producer<bool> dontStart = nullptr);
|
rpl::producer<bool> dontStart = nullptr);
|
||||||
|
|
Loading…
Add table
Reference in a new issue