From 6e6ba5a14947242ae0de3296fd650a3b3338728e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 14 Mar 2022 17:19:59 +0300 Subject: [PATCH] Moved Ui::SelectScrollManager to lib_ui. --- CMakeLists.txt | 2 ++ ui/dragging_scroll_manager.cpp | 50 ++++++++++++++++++++++++++++++++++ ui/dragging_scroll_manager.h | 34 +++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 ui/dragging_scroll_manager.cpp create mode 100644 ui/dragging_scroll_manager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c6651f..cc6654b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,6 +219,8 @@ PRIVATE ui/click_handler.h ui/delayed_activation.cpp ui/delayed_activation.h + ui/dragging_scroll_manager.cpp + ui/dragging_scroll_manager.h ui/emoji_config.cpp ui/emoji_config.h ui/focus_persister.h diff --git a/ui/dragging_scroll_manager.cpp b/ui/dragging_scroll_manager.cpp new file mode 100644 index 0000000..e62d3a3 --- /dev/null +++ b/ui/dragging_scroll_manager.cpp @@ -0,0 +1,50 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "ui/dragging_scroll_manager.h" + +#include "ui/widgets/scroll_area.h" + +namespace Ui { + +DraggingScrollManager::DraggingScrollManager() +: _timer([=] { scrollByTimer(); }) { +} + +void DraggingScrollManager::scrollByTimer() { + const auto d = (_delta > 0) + ? std::min(_delta * 3 / 20 + 1, kMaxScrollSpeed) + : std::max(_delta * 3 / 20 - 1, -kMaxScrollSpeed); + _scrolls.fire_copy(d); +} + +void DraggingScrollManager::checkDeltaScroll( + const QPoint &point, + int top, + int bottom) { + const auto diff = point.y() - top; + _delta = (diff < 0) + ? diff + : (point.y() >= bottom) + ? (point.y() - bottom + 1) + : 0; + if (_delta) { + _timer.callEach(15); + } else { + _timer.cancel(); + } +} + +void DraggingScrollManager::cancel() { + _timer.cancel(); +} + +rpl::producer DraggingScrollManager::scrolls() { + return _scrolls.events(); +} + +} // namespace Ui diff --git a/ui/dragging_scroll_manager.h b/ui/dragging_scroll_manager.h new file mode 100644 index 0000000..5102bff --- /dev/null +++ b/ui/dragging_scroll_manager.h @@ -0,0 +1,34 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "base/timer.h" + +namespace Ui { + +class ScrollArea; + +class DraggingScrollManager final { +public: + DraggingScrollManager(); + + void checkDeltaScroll(const QPoint &point, int top, int bottom); + void cancel(); + + rpl::producer scrolls(); + +private: + void scrollByTimer(); + + base::Timer _timer; + int _delta = 0; + rpl::event_stream _scrolls; + +}; + +} // namespace Ui