init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
This commit is contained in:
63
Telegram/lib_ui/ui/dragging_scroll_manager.cpp
Normal file
63
Telegram/lib_ui/ui/dragging_scroll_manager.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// This file is part of Desktop App Toolkit,
|
||||
// a set of libraries for developing nice desktop applications.
|
||||
//
|
||||
// For license and copyright information please follow this link:
|
||||
// https://github.com/desktop-app/legal/blob/master/LEGAL
|
||||
//
|
||||
#include "ui/dragging_scroll_manager.h"
|
||||
|
||||
#include "base/timer.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace {
|
||||
|
||||
// 37px per 15ms while select-by-drag.
|
||||
inline constexpr auto kMaxScrollSpeed = 37;
|
||||
|
||||
} // namespace
|
||||
|
||||
DraggingScrollManager::DraggingScrollManager() = default;
|
||||
|
||||
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(int delta) {
|
||||
_delta = delta;
|
||||
if (_delta) {
|
||||
if (!_timer) {
|
||||
_timer = std::make_unique<base::Timer>([=] { scrollByTimer(); });
|
||||
}
|
||||
_timer->callEach(15);
|
||||
} else {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void DraggingScrollManager::checkDeltaScroll(
|
||||
const QPoint &point,
|
||||
int top,
|
||||
int bottom) {
|
||||
const auto diff = point.y() - top;
|
||||
checkDeltaScroll((diff < 0)
|
||||
? diff
|
||||
: (point.y() >= bottom)
|
||||
? (point.y() - bottom + 1)
|
||||
: 0);
|
||||
}
|
||||
|
||||
void DraggingScrollManager::cancel() {
|
||||
if (_timer) {
|
||||
_timer->cancel();
|
||||
_timer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
rpl::producer<int> DraggingScrollManager::scrolls() const {
|
||||
return _scrolls.events();
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
Reference in New Issue
Block a user