diff --git a/ui/layers/box_content.cpp b/ui/layers/box_content.cpp index f4aae48..d669d80 100644 --- a/ui/layers/box_content.cpp +++ b/ui/layers/box_content.cpp @@ -98,6 +98,12 @@ void BoxContent::finishScrollCreate() { updateInnerVisibleTopBottom(); updateShadowsVisibility(); }, lifetime()); + _draggingScroll.scrolls( + ) | rpl::start_with_next([=](int delta) { + if (_scroll) { + _scroll->scrollToY(_scroll->scrollTop() + delta); + } + }, lifetime()); } void BoxContent::scrollToWidget(not_null widget) { @@ -117,24 +123,7 @@ void BoxContent::scrollToY(int top, int bottom) { } void BoxContent::scrollByDraggingDelta(int delta) { - _draggingScrollDelta = _scroll ? delta : 0; - if (_draggingScrollDelta) { - if (!_draggingScrollTimer) { - _draggingScrollTimer = std::make_unique([=] { - draggingScrollTimerCallback(); - }); - } - _draggingScrollTimer->callEach(15); - } else { - _draggingScrollTimer = nullptr; - } -} - -void BoxContent::draggingScrollTimerCallback() { - const auto delta = (_draggingScrollDelta > 0) - ? qMin(_draggingScrollDelta * 3 / 20 + 1, int32(kMaxScrollSpeed)) - : qMax(_draggingScrollDelta * 3 / 20 - 1, -int32(kMaxScrollSpeed)); - _scroll->scrollToY(_scroll->scrollTop() + delta); + _draggingScroll.checkDeltaScroll(_scroll ? delta : 0); } void BoxContent::updateInnerVisibleTopBottom() { diff --git a/ui/layers/box_content.h b/ui/layers/box_content.h index 9426d88..e1a5bb4 100644 --- a/ui/layers/box_content.h +++ b/ui/layers/box_content.h @@ -8,6 +8,7 @@ #include "base/unique_qptr.h" #include "base/flags.h" +#include "ui/dragging_scroll_manager.h" #include "ui/wrap/padding_wrap.h" #include "ui/widgets/labels.h" #include "ui/layers/layer_widget.h" @@ -287,8 +288,6 @@ private: void updateShadowsVisibility(); object_ptr doTakeInnerWidget(); - void draggingScrollTimerCallback(); - BoxContentDelegate *_delegate = nullptr; bool _preparing = false; @@ -300,8 +299,7 @@ private: object_ptr _topShadow = { nullptr }; object_ptr _bottomShadow = { nullptr }; - std::unique_ptr _draggingScrollTimer; - int _draggingScrollDelta = 0; + Ui::DraggingScrollManager _draggingScroll; rpl::event_stream<> _boxClosingStream;