Added ability to use VerticalLayoutReorder without scroll.
This commit is contained in:
parent
6af9023eb7
commit
dbbec068a8
2 changed files with 14 additions and 3 deletions
|
|
@ -28,6 +28,10 @@ VerticalLayoutReorder::VerticalLayoutReorder(
|
||||||
, _scrollAnimation([=] { updateScrollCallback(); }) {
|
, _scrollAnimation([=] { updateScrollCallback(); }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VerticalLayoutReorder::VerticalLayoutReorder(not_null<VerticalLayout*> layout)
|
||||||
|
: _layout(layout) {
|
||||||
|
}
|
||||||
|
|
||||||
void VerticalLayoutReorder::cancel() {
|
void VerticalLayoutReorder::cancel() {
|
||||||
if (_currentWidget) {
|
if (_currentWidget) {
|
||||||
cancelCurrent(indexOf(_currentWidget));
|
cancelCurrent(indexOf(_currentWidget));
|
||||||
|
|
@ -183,7 +187,9 @@ void VerticalLayoutReorder::cancelCurrent(int index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VerticalLayoutReorder::finishReordering() {
|
void VerticalLayoutReorder::finishReordering() {
|
||||||
_scrollAnimation.stop();
|
if (_scroll) {
|
||||||
|
_scrollAnimation.stop();
|
||||||
|
}
|
||||||
finishCurrent();
|
finishCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,6 +287,9 @@ auto VerticalLayoutReorder::updates() const -> rpl::producer<Single> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VerticalLayoutReorder::updateScrollCallback() {
|
void VerticalLayoutReorder::updateScrollCallback() {
|
||||||
|
if (!_scroll) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto delta = deltaFromEdge();
|
const auto delta = deltaFromEdge();
|
||||||
const auto oldTop = _scroll->scrollTop();
|
const auto oldTop = _scroll->scrollTop();
|
||||||
_scroll->scrollToY(oldTop + delta);
|
_scroll->scrollToY(oldTop + delta);
|
||||||
|
|
@ -293,7 +302,7 @@ void VerticalLayoutReorder::updateScrollCallback() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VerticalLayoutReorder::checkForScrollAnimation() {
|
void VerticalLayoutReorder::checkForScrollAnimation() {
|
||||||
if (!deltaFromEdge() || _scrollAnimation.animating()) {
|
if (!_scroll || !deltaFromEdge() || _scrollAnimation.animating()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_scrollAnimation.start();
|
_scrollAnimation.start();
|
||||||
|
|
@ -301,6 +310,7 @@ void VerticalLayoutReorder::checkForScrollAnimation() {
|
||||||
|
|
||||||
int VerticalLayoutReorder::deltaFromEdge() {
|
int VerticalLayoutReorder::deltaFromEdge() {
|
||||||
Expects(_currentWidget != nullptr);
|
Expects(_currentWidget != nullptr);
|
||||||
|
Expects(_scroll);
|
||||||
|
|
||||||
const auto globalPosition = _currentWidget->mapToGlobal(QPoint(0, 0));
|
const auto globalPosition = _currentWidget->mapToGlobal(QPoint(0, 0));
|
||||||
const auto localTop = _scroll->mapFromGlobal(globalPosition).y();
|
const auto localTop = _scroll->mapFromGlobal(globalPosition).y();
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ public:
|
||||||
VerticalLayoutReorder(
|
VerticalLayoutReorder(
|
||||||
not_null<VerticalLayout*> layout,
|
not_null<VerticalLayout*> layout,
|
||||||
not_null<ScrollArea*> scroll);
|
not_null<ScrollArea*> scroll);
|
||||||
|
VerticalLayoutReorder(not_null<VerticalLayout*> layout);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
@ -68,7 +69,7 @@ private:
|
||||||
int deltaFromEdge();
|
int deltaFromEdge();
|
||||||
|
|
||||||
const not_null<Ui::VerticalLayout*> _layout;
|
const not_null<Ui::VerticalLayout*> _layout;
|
||||||
const not_null<Ui::ScrollArea*> _scroll;
|
Ui::ScrollArea *_scroll = nullptr;
|
||||||
|
|
||||||
Ui::Animations::Basic _scrollAnimation;
|
Ui::Animations::Basic _scrollAnimation;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue