Added ability to set swipe back widget on opposite side.

This commit is contained in:
23rd 2025-02-18 21:17:57 +03:00 committed by John Preston
parent ad64e068db
commit 4c74cbbbe9
2 changed files with 24 additions and 13 deletions

View file

@ -298,16 +298,17 @@ void SetupSwipeHandler(
SwipeBackResult SetupSwipeBack( SwipeBackResult SetupSwipeBack(
not_null<Ui::RpWidget*> widget, not_null<Ui::RpWidget*> widget,
Fn<std::pair<QColor, QColor>()> colors) { Fn<std::pair<QColor, QColor>()> colors,
bool mirrored) {
struct State { struct State {
base::unique_qptr<Ui::RpWidget> back; base::unique_qptr<Ui::RpWidget> back;
ChatPaintGestureHorizontalData data; ChatPaintGestureHorizontalData data;
}; };
constexpr auto kMaxRightOffset = 0.5; constexpr auto kMaxInnerOffset = 0.5;
constexpr auto kMaxLeftOffset = 0.8; constexpr auto kMaxOuterOffset = 0.8;
constexpr auto kIdealSize = 100; constexpr auto kIdealSize = 100;
const auto maxOffset = st::swipeBackSize * kMaxRightOffset; const auto maxOffset = st::swipeBackSize * kMaxInnerOffset;
const auto sizeRatio = st::swipeBackSize const auto sizeRatio = st::swipeBackSize
/ style::ConvertFloatScale(kIdealSize); / style::ConvertFloatScale(kIdealSize);
@ -346,10 +347,10 @@ SwipeBackResult SetupSwipeBack(
const auto arcRect = rect - Margins(strokeWidth); const auto arcRect = rect - Margins(strokeWidth);
auto hq = PainterHighQualityEnabler(p); auto hq = PainterHighQualityEnabler(p);
p.setOpacity(ratio); p.setOpacity(ratio);
if (reachScale) { if (reachScale || mirrored) {
const auto scale = (1. + 1. * reachScale); const auto scale = (1. + 1. * reachScale);
p.translate(center); p.translate(center);
p.scale(scale, scale); p.scale(scale * (mirrored ? -1 : 1), scale);
p.translate(-center); p.translate(-center);
} }
{ {
@ -405,12 +406,21 @@ SwipeBackResult SetupSwipeBack(
raw->show(); raw->show();
raw->raise(); raw->raise();
} }
if (!mirrored) {
state->back->moveToLeft( state->back->moveToLeft(
anim::interpolate( anim::interpolate(
-st::swipeBackSize * kMaxLeftOffset, -st::swipeBackSize * kMaxOuterOffset,
maxOffset - st::swipeBackSize, maxOffset - st::swipeBackSize,
ratio), ratio),
(widget->height() - state->back->height()) / 2); (widget->height() - state->back->height()) / 2);
} else {
state->back->moveToLeft(
anim::interpolate(
widget->width() + st::swipeBackSize * kMaxOuterOffset,
widget->width() - maxOffset,
ratio),
(widget->height() - state->back->height()) / 2);
}
state->back->update(); state->back->update();
} else if (state->back) { } else if (state->back) {
state->back = nullptr; state->back = nullptr;

View file

@ -38,7 +38,8 @@ void SetupSwipeHandler(
[[nodiscard]] SwipeBackResult SetupSwipeBack( [[nodiscard]] SwipeBackResult SetupSwipeBack(
not_null<Ui::RpWidget*> widget, not_null<Ui::RpWidget*> widget,
Fn<std::pair<QColor, QColor>()> colors); Fn<std::pair<QColor, QColor>()> colors,
bool mirrored = false);
[[nodiscard]] SwipeHandlerFinishData DefaultSwipeBackHandlerFinishData( [[nodiscard]] SwipeHandlerFinishData DefaultSwipeBackHandlerFinishData(
Fn<void(void)> callback); Fn<void(void)> callback);