From dbbec068a81bb0c7a43565ce386898de3f1b537e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 31 Jan 2022 19:02:40 +0300 Subject: [PATCH] Added ability to use VerticalLayoutReorder without scroll. --- ui/wrap/vertical_layout_reorder.cpp | 14 ++++++++++++-- ui/wrap/vertical_layout_reorder.h | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ui/wrap/vertical_layout_reorder.cpp b/ui/wrap/vertical_layout_reorder.cpp index e8f778b..a750dfa 100644 --- a/ui/wrap/vertical_layout_reorder.cpp +++ b/ui/wrap/vertical_layout_reorder.cpp @@ -28,6 +28,10 @@ VerticalLayoutReorder::VerticalLayoutReorder( , _scrollAnimation([=] { updateScrollCallback(); }) { } +VerticalLayoutReorder::VerticalLayoutReorder(not_null layout) +: _layout(layout) { +} + void VerticalLayoutReorder::cancel() { if (_currentWidget) { cancelCurrent(indexOf(_currentWidget)); @@ -183,7 +187,9 @@ void VerticalLayoutReorder::cancelCurrent(int index) { } void VerticalLayoutReorder::finishReordering() { - _scrollAnimation.stop(); + if (_scroll) { + _scrollAnimation.stop(); + } finishCurrent(); } @@ -281,6 +287,9 @@ auto VerticalLayoutReorder::updates() const -> rpl::producer { } void VerticalLayoutReorder::updateScrollCallback() { + if (!_scroll) { + return; + } const auto delta = deltaFromEdge(); const auto oldTop = _scroll->scrollTop(); _scroll->scrollToY(oldTop + delta); @@ -293,7 +302,7 @@ void VerticalLayoutReorder::updateScrollCallback() { } void VerticalLayoutReorder::checkForScrollAnimation() { - if (!deltaFromEdge() || _scrollAnimation.animating()) { + if (!_scroll || !deltaFromEdge() || _scrollAnimation.animating()) { return; } _scrollAnimation.start(); @@ -301,6 +310,7 @@ void VerticalLayoutReorder::checkForScrollAnimation() { int VerticalLayoutReorder::deltaFromEdge() { Expects(_currentWidget != nullptr); + Expects(_scroll); const auto globalPosition = _currentWidget->mapToGlobal(QPoint(0, 0)); const auto localTop = _scroll->mapFromGlobal(globalPosition).y(); diff --git a/ui/wrap/vertical_layout_reorder.h b/ui/wrap/vertical_layout_reorder.h index 502031c..1b28e76 100644 --- a/ui/wrap/vertical_layout_reorder.h +++ b/ui/wrap/vertical_layout_reorder.h @@ -31,6 +31,7 @@ public: VerticalLayoutReorder( not_null layout, not_null scroll); + VerticalLayoutReorder(not_null layout); void start(); void cancel(); @@ -68,7 +69,7 @@ private: int deltaFromEdge(); const not_null _layout; - const not_null _scroll; + Ui::ScrollArea *_scroll = nullptr; Ui::Animations::Basic _scrollAnimation;