diff options
Diffstat (limited to 'include/cru/ui')
| -rw-r--r-- | include/cru/ui/DeleteLater.h | 40 | ||||
| -rw-r--r-- | include/cru/ui/components/Component.h | 7 | ||||
| -rw-r--r-- | include/cru/ui/controls/Control.h | 4 |
3 files changed, 7 insertions, 44 deletions
diff --git a/include/cru/ui/DeleteLater.h b/include/cru/ui/DeleteLater.h deleted file mode 100644 index 95301bc0..00000000 --- a/include/cru/ui/DeleteLater.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#include "Base.h" - -#include <cru/base/Guard.h> -#include <memory> -#include <utility> - -namespace cru::ui { -class CRU_UI_API DeleteLaterImpl { - CRU_DEFINE_CLASS_LOG_TAG("cru::ui::DeleteLaterImpl") - public: - DeleteLaterImpl(); - virtual ~DeleteLaterImpl(); - void DeleteLater(); - - private: - bool delete_later_scheduled_; -}; - -namespace details { -template <typename T> -struct DeleteLaterPtrDeleter { - void operator()(T* p) const noexcept { p->DeleteLater(); } -}; -} // namespace details - -template <typename T> -using DeleteLaterPtr = std::unique_ptr<T, details::DeleteLaterPtrDeleter<T>>; - -template <typename T> -DeleteLaterPtr<T> ToDeleteLaterPtr(std::unique_ptr<T>&& p) { - return DeleteLaterPtr<T>(p.release()); -} - -template <typename T, typename... Args> -DeleteLaterPtr<T> MakeDeleteLater(Args&&... args) { - return DeleteLaterPtr<T>(new T(std::forward<Args>(args)...)); -} - -} // namespace cru::ui diff --git a/include/cru/ui/components/Component.h b/include/cru/ui/components/Component.h index d8966a89..1e002e5f 100644 --- a/include/cru/ui/components/Component.h +++ b/include/cru/ui/components/Component.h @@ -1,6 +1,7 @@ #pragma once #include "../Base.h" -#include "../DeleteLater.h" + +#include <cru/platform/gui/DeleteLater.h> namespace cru::ui::components { /** @@ -8,7 +9,9 @@ namespace cru::ui::components { * \remarks Component should respect children's Component::IsDeleteByParent * value and decide whether to delete it. */ -class CRU_UI_API Component : public Object, public DeleteLaterImpl { +class CRU_UI_API Component + : public Object, + public cru::platform::gui::DeleteLaterImpl<Component> { public: virtual controls::Control* GetRootControl() = 0; diff --git a/include/cru/ui/controls/Control.h b/include/cru/ui/controls/Control.h index 9e5e86b8..6a85d25a 100644 --- a/include/cru/ui/controls/Control.h +++ b/include/cru/ui/controls/Control.h @@ -1,6 +1,5 @@ #pragma once #include "../Base.h" -#include "../DeleteLater.h" #include "../events/KeyEventArgs.h" #include "../events/MouseWheelEventArgs.h" #include "../events/UiEvents.h" @@ -9,6 +8,7 @@ #include "../style/StyleRuleSet.h" #include <cru/base/SelfResolvable.h> +#include <cru/platform/gui/DeleteLater.h> namespace cru::ui::controls { @@ -22,7 +22,7 @@ namespace cru::ui::controls { * The last two methods are totally for convenient control tree management. */ class CRU_UI_API Control : public Object, - public DeleteLaterImpl, + public cru::platform::gui::DeleteLaterImpl<Control>, public SelfResolvable<Control> { friend class ControlHost; |
