From 2df47ffbfff02fb6b64d19e404adc41a93677afe Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 28 Oct 2020 16:58:56 +0800 Subject: ... --- include/cru/platform/native/UiApplication.hpp | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'include/cru/platform/native') diff --git a/include/cru/platform/native/UiApplication.hpp b/include/cru/platform/native/UiApplication.hpp index 135e95c3..4c1b3456 100644 --- a/include/cru/platform/native/UiApplication.hpp +++ b/include/cru/platform/native/UiApplication.hpp @@ -1,6 +1,7 @@ #pragma once #include "../Resource.hpp" #include "Base.hpp" +#include "cru/common/Base.hpp" #include #include @@ -53,6 +54,60 @@ struct IUiApplication : public virtual INativeResource { virtual IInputMethodManager* GetInputMethodManager() = 0; }; +class TimerAutoCanceler { + public: + TimerAutoCanceler() : id_(0) {} + explicit TimerAutoCanceler(long long id) : id_(id) {} + + CRU_DELETE_COPY(TimerAutoCanceler) + + TimerAutoCanceler(TimerAutoCanceler&& other) : id_(other.id_) { + other.id_ = 0; + } + + TimerAutoCanceler& operator=(TimerAutoCanceler&& other) { + Reset(other.id_); + other.id_ = 0; + return *this; + } + + ~TimerAutoCanceler() { Reset(); } + + long long Release() { + auto temp = id_; + id_ = 0; + return temp; + } + + void Reset(long long id = 0) { + if (id_ > 0) IUiApplication::GetInstance()->CancelTimer(id_); + id_ = id; + } + + private: + long long id_; +}; + +class TimerListAutoCanceler { + public: + TimerListAutoCanceler() = default; + CRU_DELETE_COPY(TimerListAutoCanceler) + CRU_DEFAULT_MOVE(TimerListAutoCanceler) + ~TimerListAutoCanceler() = default; + + TimerListAutoCanceler& operator+=(long long id) { + list_.push_back(TimerAutoCanceler(id)); + return *this; + } + + void Clear() { list_.clear(); } + + bool IsEmpty() const { return list_.empty(); } + + private: + std::vector list_; +}; + // Bootstrap from this. std::unique_ptr CreateUiApplication(); } // namespace cru::platform::native -- cgit v1.2.3