mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-05-09 17:33:58 +02:00
Replaced SetupSwipeHandler signature from arguments to struct.
This commit is contained in:
parent
a30951dc91
commit
f734c0475b
10 changed files with 120 additions and 46 deletions
|
@ -533,8 +533,7 @@ TabbedSelector::~TabbedSelector() = default;
|
|||
void TabbedSelector::reinstallSwipe(not_null<Ui::RpWidget*> widget) {
|
||||
_swipeLifetime.destroy();
|
||||
|
||||
Ui::Controls::SetupSwipeHandler(widget, _scroll.data(), [=](
|
||||
Ui::Controls::SwipeContextData data) {
|
||||
auto update = [=](Ui::Controls::SwipeContextData data) {
|
||||
if (data.translation != 0) {
|
||||
if (!_swipeBackData.callback) {
|
||||
_swipeBackData = Ui::Controls::SetupSwipeBack(
|
||||
|
@ -552,7 +551,9 @@ void TabbedSelector::reinstallSwipe(not_null<Ui::RpWidget*> widget) {
|
|||
} else if (_swipeBackData.lifetime) {
|
||||
_swipeBackData = {};
|
||||
}
|
||||
}, [=](int, Qt::LayoutDirection direction) {
|
||||
};
|
||||
|
||||
auto init = [=](int, Qt::LayoutDirection direction) {
|
||||
if (!_tabsSlider) {
|
||||
return Ui::Controls::SwipeHandlerFinishData();
|
||||
}
|
||||
|
@ -571,7 +572,16 @@ void TabbedSelector::reinstallSwipe(not_null<Ui::RpWidget*> widget) {
|
|||
});
|
||||
}
|
||||
return Ui::Controls::SwipeHandlerFinishData();
|
||||
}, nullptr, &_swipeLifetime);
|
||||
};
|
||||
|
||||
Ui::Controls::SetupSwipeHandler({
|
||||
.widget = widget,
|
||||
.scroll = _scroll.data(),
|
||||
.update = std::move(update),
|
||||
.init = std::move(init),
|
||||
.dontStart = nullptr,
|
||||
.onLifetime = &_swipeLifetime,
|
||||
});
|
||||
}
|
||||
|
||||
const style::EmojiPan &TabbedSelector::st() const {
|
||||
|
|
|
@ -691,8 +691,8 @@ void Widget::setupSwipeBack() {
|
|||
}
|
||||
return !current;
|
||||
};
|
||||
Ui::Controls::SetupSwipeHandler(_inner, _scroll.data(), [=](
|
||||
Ui::Controls::SwipeContextData data) {
|
||||
|
||||
auto update = [=](Ui::Controls::SwipeContextData data) {
|
||||
if (data.translation != 0) {
|
||||
if (data.translation < 0
|
||||
&& _inner
|
||||
|
@ -724,7 +724,9 @@ void Widget::setupSwipeBack() {
|
|||
_inner->update();
|
||||
}
|
||||
}
|
||||
}, [=](int top, Qt::LayoutDirection direction) {
|
||||
};
|
||||
|
||||
auto init = [=](int top, Qt::LayoutDirection direction) {
|
||||
_swipeBackIconMirrored = false;
|
||||
_swipeBackMirrored = false;
|
||||
if (_childListShown.current()) {
|
||||
|
@ -812,7 +814,15 @@ void Widget::setupSwipeBack() {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Ui::Controls::SwipeHandlerFinishData();
|
||||
};
|
||||
|
||||
Ui::Controls::SetupSwipeHandler({
|
||||
.widget = _inner,
|
||||
.scroll = _scroll.data(),
|
||||
.update = std::move(update),
|
||||
.init = std::move(init),
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -420,8 +420,7 @@ void Widget::setupShortcuts() {
|
|||
}
|
||||
|
||||
void Widget::setupSwipeReply() {
|
||||
Ui::Controls::SetupSwipeHandler(_inner.data(), _scroll.data(), [=](
|
||||
Ui::Controls::SwipeContextData data) {
|
||||
auto update = [=](Ui::Controls::SwipeContextData data) {
|
||||
if (data.translation > 0) {
|
||||
if (!_swipeBackData.callback) {
|
||||
_swipeBackData = Ui::Controls::SetupSwipeBack(
|
||||
|
@ -439,13 +438,22 @@ void Widget::setupSwipeReply() {
|
|||
} else if (_swipeBackData.lifetime) {
|
||||
_swipeBackData = {};
|
||||
}
|
||||
}, [=](int, Qt::LayoutDirection direction) {
|
||||
};
|
||||
|
||||
auto init = [=](int, Qt::LayoutDirection direction) {
|
||||
if (direction == Qt::RightToLeft) {
|
||||
return Ui::Controls::DefaultSwipeBackHandlerFinishData([=] {
|
||||
controller()->showBackFromStack();
|
||||
});
|
||||
}
|
||||
return Ui::Controls::SwipeHandlerFinishData();
|
||||
};
|
||||
|
||||
Ui::Controls::SetupSwipeHandler({
|
||||
.widget = _inner.data(),
|
||||
.scroll = _scroll.data(),
|
||||
.update = std::move(update),
|
||||
.init = std::move(init),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -528,8 +528,8 @@ void HistoryInner::setupSwipeReplyAndBack() {
|
|||
return;
|
||||
}
|
||||
const auto peer = _peer;
|
||||
Ui::Controls::SetupSwipeHandler(this, _scroll, [=, history = _history](
|
||||
Ui::Controls::SwipeContextData data) {
|
||||
|
||||
auto update = [=, history = _history](Ui::Controls::SwipeContextData data) {
|
||||
if (data.translation > 0) {
|
||||
if (!_swipeBackData.callback) {
|
||||
_swipeBackData = Ui::Controls::SetupSwipeBack(
|
||||
|
@ -559,7 +559,9 @@ void HistoryInner::setupSwipeReplyAndBack() {
|
|||
repaintItem(item);
|
||||
}
|
||||
}
|
||||
}, [=, show = _controller->uiShow()](
|
||||
};
|
||||
|
||||
auto init = [=, show = _controller->uiShow()](
|
||||
int cursorTop,
|
||||
Qt::LayoutDirection direction) {
|
||||
if (direction == Qt::RightToLeft) {
|
||||
|
@ -607,7 +609,15 @@ void HistoryInner::setupSwipeReplyAndBack() {
|
|||
return false;
|
||||
});
|
||||
return result;
|
||||
}, _touchMaybeSelecting.value());
|
||||
};
|
||||
|
||||
Ui::Controls::SetupSwipeHandler({
|
||||
.widget = this,
|
||||
.scroll = _scroll,
|
||||
.update = std::move(update),
|
||||
.init = std::move(init),
|
||||
.dontStart = _touchMaybeSelecting.value(),
|
||||
});
|
||||
}
|
||||
|
||||
bool HistoryInner::hasSelectRestriction() const {
|
||||
|
|
|
@ -21,8 +21,7 @@ void SetupSwipeBackSection(
|
|||
not_null<HistoryView::ListWidget*> list) {
|
||||
const auto swipeBackData
|
||||
= list->lifetime().make_state<Ui::Controls::SwipeBackResult>();
|
||||
Ui::Controls::SetupSwipeHandler(list, scroll, [=](
|
||||
Ui::Controls::SwipeContextData data) {
|
||||
auto update = [=](Ui::Controls::SwipeContextData data) {
|
||||
if (data.translation > 0) {
|
||||
if (!swipeBackData->callback) {
|
||||
const auto color = [=]() -> std::pair<QColor, QColor> {
|
||||
|
@ -43,14 +42,22 @@ void SetupSwipeBackSection(
|
|||
} else if (swipeBackData->lifetime) {
|
||||
(*swipeBackData) = {};
|
||||
}
|
||||
}, [=](int, Qt::LayoutDirection direction) {
|
||||
};
|
||||
auto init = [=](int, Qt::LayoutDirection direction) {
|
||||
if (direction != Qt::RightToLeft) {
|
||||
return Ui::Controls::SwipeHandlerFinishData();
|
||||
}
|
||||
return Ui::Controls::DefaultSwipeBackHandlerFinishData([=] {
|
||||
list->controller()->showBackFromStack();
|
||||
});
|
||||
}, list->touchMaybeSelectingValue());
|
||||
};
|
||||
Ui::Controls::SetupSwipeHandler({
|
||||
.widget = list,
|
||||
.scroll = scroll,
|
||||
.update = std::move(update),
|
||||
.init = std::move(init),
|
||||
.dontStart = list->touchMaybeSelectingValue(),
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Window
|
||||
|
|
|
@ -890,8 +890,8 @@ void RepliesWidget::setupSwipeReplyAndBack() {
|
|||
}
|
||||
return false;
|
||||
};
|
||||
Ui::Controls::SetupSwipeHandler(_inner, _scroll.get(), [=](
|
||||
Ui::Controls::SwipeContextData data) {
|
||||
|
||||
auto update = [=](Ui::Controls::SwipeContextData data) {
|
||||
if (data.translation > 0) {
|
||||
if (!_swipeBackData.callback) {
|
||||
_swipeBackData = Ui::Controls::SetupSwipeBack(
|
||||
|
@ -923,7 +923,9 @@ void RepliesWidget::setupSwipeReplyAndBack() {
|
|||
_history->owner().requestItemRepaint(item);
|
||||
}
|
||||
}
|
||||
}, [=, show = controller()->uiShow()](
|
||||
};
|
||||
|
||||
auto init = [=, show = controller()->uiShow()](
|
||||
int cursorTop,
|
||||
Qt::LayoutDirection direction) {
|
||||
if (direction == Qt::RightToLeft) {
|
||||
|
@ -962,7 +964,15 @@ void RepliesWidget::setupSwipeReplyAndBack() {
|
|||
});
|
||||
};
|
||||
return result;
|
||||
}, _inner->touchMaybeSelectingValue());
|
||||
};
|
||||
|
||||
Ui::Controls::SetupSwipeHandler({
|
||||
.widget = _inner,
|
||||
.scroll = _scroll.get(),
|
||||
.update = std::move(update),
|
||||
.init = std::move(init),
|
||||
.dontStart = _inner->touchMaybeSelectingValue(),
|
||||
});
|
||||
}
|
||||
|
||||
void RepliesWidget::chooseAttach(
|
||||
|
|
|
@ -411,8 +411,7 @@ not_null<Ui::ScrollArea*> ContentWidget::scroll() const {
|
|||
}
|
||||
|
||||
void ContentWidget::setupSwipeHandler(not_null<Ui::RpWidget*> widget) {
|
||||
Ui::Controls::SetupSwipeHandler(widget, _scroll.data(), [=](
|
||||
Ui::Controls::SwipeContextData data) {
|
||||
auto update = [=](Ui::Controls::SwipeContextData data) {
|
||||
if (data.translation > 0) {
|
||||
if (!_swipeBackData.callback) {
|
||||
_swipeBackData = Ui::Controls::SetupSwipeBack(
|
||||
|
@ -429,7 +428,9 @@ void ContentWidget::setupSwipeHandler(not_null<Ui::RpWidget*> widget) {
|
|||
} else if (_swipeBackData.lifetime) {
|
||||
_swipeBackData = {};
|
||||
}
|
||||
}, [=](int, Qt::LayoutDirection direction) {
|
||||
};
|
||||
|
||||
auto init = [=](int, Qt::LayoutDirection direction) {
|
||||
return (direction == Qt::RightToLeft && _controller->hasBackButton())
|
||||
? Ui::Controls::DefaultSwipeBackHandlerFinishData([=] {
|
||||
checkBeforeClose(crl::guard(this, [=] {
|
||||
|
@ -438,6 +439,13 @@ void ContentWidget::setupSwipeHandler(not_null<Ui::RpWidget*> widget) {
|
|||
}));
|
||||
})
|
||||
: Ui::Controls::SwipeHandlerFinishData();
|
||||
};
|
||||
|
||||
Ui::Controls::SetupSwipeHandler({
|
||||
.widget = widget,
|
||||
.scroll = _scroll.data(),
|
||||
.update = std::move(update),
|
||||
.init = std::move(init),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -61,16 +61,14 @@ private:
|
|||
|
||||
} // namespace
|
||||
|
||||
void SetupSwipeHandler(
|
||||
not_null<Ui::RpWidget*> widget,
|
||||
Scroll scroll,
|
||||
Fn<void(SwipeContextData)> update,
|
||||
Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinish,
|
||||
rpl::producer<bool> dontStart,
|
||||
rpl::lifetime *onLifetime) {
|
||||
void SetupSwipeHandler(SwipeHandlerArgs &&args) {
|
||||
static constexpr auto kThresholdWidth = 50;
|
||||
static constexpr auto kMaxRatio = 1.5;
|
||||
|
||||
const auto widget = std::move(args.widget);
|
||||
const auto scroll = std::move(args.scroll);
|
||||
const auto update = std::move(args.update);
|
||||
|
||||
struct UpdateArgs {
|
||||
QPoint globalCursor;
|
||||
QPointF position;
|
||||
|
@ -98,11 +96,13 @@ void SetupSwipeHandler(
|
|||
|
||||
rpl::lifetime lifetime;
|
||||
};
|
||||
auto &useLifetime = onLifetime ? *onLifetime : widget->lifetime();
|
||||
auto &useLifetime = args.onLifetime
|
||||
? *(args.onLifetime)
|
||||
: args.widget->lifetime();
|
||||
const auto state = useLifetime.make_state<State>();
|
||||
if (dontStart) {
|
||||
if (args.dontStart) {
|
||||
std::move(
|
||||
dontStart
|
||||
args.dontStart
|
||||
) | rpl::start_with_next([=](bool dontStart) {
|
||||
state->dontStart = dontStart;
|
||||
}, state->lifetime);
|
||||
|
@ -188,7 +188,7 @@ void SetupSwipeHandler(
|
|||
state->data.reachRatio = value;
|
||||
update(state->data);
|
||||
};
|
||||
const auto updateWith = [=](UpdateArgs args) {
|
||||
const auto updateWith = [=, generateFinish = args.init](UpdateArgs args) {
|
||||
const auto fillFinishByTop = [&] {
|
||||
if (!args.delta.x()) {
|
||||
LOG(("SKIPPING fillFinishByTop."));
|
||||
|
|
|
@ -32,13 +32,16 @@ using Scroll = std::variant<
|
|||
not_null<Ui::ScrollArea*>,
|
||||
not_null<Ui::ElasticScroll*>>;
|
||||
|
||||
void SetupSwipeHandler(
|
||||
not_null<Ui::RpWidget*> widget,
|
||||
Scroll scroll,
|
||||
Fn<void(SwipeContextData)> update,
|
||||
Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> generateFinishByTop,
|
||||
rpl::producer<bool> dontStart = nullptr,
|
||||
rpl::lifetime *onLifetime = nullptr);
|
||||
struct SwipeHandlerArgs {
|
||||
not_null<Ui::RpWidget*> widget;
|
||||
Scroll scroll;
|
||||
Fn<void(SwipeContextData)> update;
|
||||
Fn<SwipeHandlerFinishData(int, Qt::LayoutDirection)> init;
|
||||
rpl::producer<bool> dontStart = nullptr;
|
||||
rpl::lifetime *onLifetime = nullptr;
|
||||
};
|
||||
|
||||
void SetupSwipeHandler(SwipeHandlerArgs &&args);
|
||||
|
||||
[[nodiscard]] SwipeBackResult SetupSwipeBack(
|
||||
not_null<Ui::RpWidget*> widget,
|
||||
|
|
|
@ -1051,8 +1051,7 @@ void MainMenu::setupSwipe() {
|
|||
});
|
||||
}
|
||||
|
||||
Ui::Controls::SetupSwipeHandler(_inner, _scroll.data(), [=](
|
||||
Ui::Controls::SwipeContextData data) {
|
||||
auto update = [=](Ui::Controls::SwipeContextData data) {
|
||||
if (data.translation < 0) {
|
||||
if (!_swipeBackData.callback) {
|
||||
_swipeBackData = Ui::Controls::SetupSwipeBack(
|
||||
|
@ -1069,13 +1068,22 @@ void MainMenu::setupSwipe() {
|
|||
} else if (_swipeBackData.lifetime) {
|
||||
_swipeBackData = {};
|
||||
}
|
||||
}, [=](int, Qt::LayoutDirection direction) {
|
||||
};
|
||||
|
||||
auto init = [=](int, Qt::LayoutDirection direction) {
|
||||
if (direction != Qt::LeftToRight) {
|
||||
return Ui::Controls::SwipeHandlerFinishData();
|
||||
}
|
||||
return Ui::Controls::DefaultSwipeBackHandlerFinishData([=] {
|
||||
closeLayer();
|
||||
});
|
||||
};
|
||||
|
||||
Ui::Controls::SetupSwipeHandler({
|
||||
.widget = _inner,
|
||||
.scroll = _scroll.data(),
|
||||
.update = std::move(update),
|
||||
.init = std::move(init),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue