Moved base::Timer to std::unique_ptr in DraggingScrollManager.
This commit is contained in:
parent
443191045b
commit
d27e4803a1
2 changed files with 18 additions and 13 deletions
|
|
@ -7,13 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "ui/dragging_scroll_manager.h"
|
||||
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "base/timer.h"
|
||||
#include "ui/widgets/scroll_area.h" // kMaxScrollSpeed.
|
||||
|
||||
namespace Ui {
|
||||
|
||||
DraggingScrollManager::DraggingScrollManager()
|
||||
: _timer([=] { scrollByTimer(); }) {
|
||||
}
|
||||
DraggingScrollManager::DraggingScrollManager() = default;
|
||||
|
||||
void DraggingScrollManager::scrollByTimer() {
|
||||
const auto d = (_delta > 0)
|
||||
|
|
@ -25,9 +24,12 @@ void DraggingScrollManager::scrollByTimer() {
|
|||
void DraggingScrollManager::checkDeltaScroll(int delta) {
|
||||
_delta = delta;
|
||||
if (_delta) {
|
||||
_timer.callEach(15);
|
||||
if (!_timer) {
|
||||
_timer = std::make_unique<base::Timer>([=] { scrollByTimer(); });
|
||||
}
|
||||
_timer->callEach(15);
|
||||
} else {
|
||||
_timer.cancel();
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -44,10 +46,13 @@ void DraggingScrollManager::checkDeltaScroll(
|
|||
}
|
||||
|
||||
void DraggingScrollManager::cancel() {
|
||||
_timer.cancel();
|
||||
if (_timer) {
|
||||
_timer->cancel();
|
||||
_timer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
rpl::producer<int> DraggingScrollManager::scrolls() {
|
||||
rpl::producer<int> DraggingScrollManager::scrolls() const {
|
||||
return _scrolls.events();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/timer.h"
|
||||
namespace base {
|
||||
class Timer;
|
||||
} // namespace base
|
||||
|
||||
namespace Ui {
|
||||
|
||||
class ScrollArea;
|
||||
|
||||
class DraggingScrollManager final {
|
||||
public:
|
||||
DraggingScrollManager();
|
||||
|
|
@ -21,12 +21,12 @@ public:
|
|||
void checkDeltaScroll(const QPoint &point, int top, int bottom);
|
||||
void cancel();
|
||||
|
||||
rpl::producer<int> scrolls();
|
||||
[[nodiscard]] rpl::producer<int> scrolls() const;
|
||||
|
||||
private:
|
||||
void scrollByTimer();
|
||||
|
||||
base::Timer _timer;
|
||||
std::unique_ptr<base::Timer> _timer;
|
||||
int _delta = 0;
|
||||
rpl::event_stream<int> _scrolls;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue