aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-03-28 21:46:40 +0800
committercrupest <crupest@outlook.com>2022-03-28 21:46:40 +0800
commit91695b78f565239223fc6f3a10b0219b8dc1b6f8 (patch)
tree712e8bebcec4377a7b5b5d8aa80daec08e0fa3b4 /include
parentbfa89c0efd310c07e4255b45f99a2f05338fbe3f (diff)
downloadcru-91695b78f565239223fc6f3a10b0219b8dc1b6f8.tar.gz
cru-91695b78f565239223fc6f3a10b0219b8dc1b6f8.tar.bz2
cru-91695b78f565239223fc6f3a10b0219b8dc1b6f8.zip
...
Diffstat (limited to 'include')
-rw-r--r--include/cru/ui/DeleteLater.h25
-rw-r--r--include/cru/ui/components/Component.h5
-rw-r--r--include/cru/ui/controls/Control.h5
3 files changed, 33 insertions, 2 deletions
diff --git a/include/cru/ui/DeleteLater.h b/include/cru/ui/DeleteLater.h
new file mode 100644
index 00000000..84c0e1c2
--- /dev/null
+++ b/include/cru/ui/DeleteLater.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <memory>
+#include <utility>
+
+namespace cru::ui {
+class DeleteLaterImpl {
+ public:
+ virtual ~DeleteLaterImpl();
+ void DeleteLater();
+};
+
+template <typename T>
+struct DeleteLaterDeleter {
+ void operator()(T* p) const { p->DeleteLater(); }
+};
+
+template <typename T>
+using DeleteLaterPtr = std::unique_ptr<T, DeleteLaterDeleter<T>>;
+
+template <typename T, typename... Args>
+DeleteLaterPtr<T> CreateDeleteLaterPtr(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 34add594..2625f445 100644
--- a/include/cru/ui/components/Component.h
+++ b/include/cru/ui/components/Component.h
@@ -1,5 +1,6 @@
#pragma once
#include "../Base.h"
+#include "../DeleteLater.h"
#include "cru/common/SelfResolvable.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 SelfResolvable<Component> {
+class CRU_UI_API Component : public Object,
+ public SelfResolvable<Component>,
+ public DeleteLaterImpl {
public:
Component() = default;
diff --git a/include/cru/ui/controls/Control.h b/include/cru/ui/controls/Control.h
index 158a1578..8c9f11d3 100644
--- a/include/cru/ui/controls/Control.h
+++ b/include/cru/ui/controls/Control.h
@@ -1,5 +1,6 @@
#pragma once
#include "../Base.h"
+#include "../DeleteLater.h"
#include "../events/UiEvents.h"
#include "../render/RenderObject.h"
#include "../style/StyleRuleSet.h"
@@ -17,7 +18,9 @@ namespace cru::ui::controls {
* - RemoveChild(Control* child)
* The last two methods are totally for convenient control tree management.
*/
-class CRU_UI_API Control : public Object, public SelfResolvable<Control> {
+class CRU_UI_API Control : public Object,
+ public SelfResolvable<Control>,
+ public DeleteLaterImpl {
friend class RootControl;
protected: