diff options
Diffstat (limited to 'include/cru')
| -rw-r--r-- | include/cru/base/Guard.h | 18 | ||||
| -rw-r--r-- | include/cru/platform/gui/sdl/Window.h | 1 | ||||
| -rw-r--r-- | include/cru/ui/controls/Button.h | 1 | ||||
| -rw-r--r-- | include/cru/ui/controls/CheckBox.h | 1 | ||||
| -rw-r--r-- | include/cru/ui/controls/Control.h | 7 | ||||
| -rw-r--r-- | include/cru/ui/controls/IconButton.h | 1 | ||||
| -rw-r--r-- | include/cru/ui/controls/Window.h | 4 |
7 files changed, 17 insertions, 16 deletions
diff --git a/include/cru/base/Guard.h b/include/cru/base/Guard.h index ae120f5a..6097b4d3 100644 --- a/include/cru/base/Guard.h +++ b/include/cru/base/Guard.h @@ -46,26 +46,21 @@ inline AutoFreePtr<T> MakeAutoFree(T* ptr) { template <typename T, typename Destructor> class AutoDestruct { public: - AutoDestruct() : value_(std::nullopt), auto_destruct_(false) {} + AutoDestruct() : value_(std::nullopt) {} - explicit AutoDestruct(T value, bool auto_destruct = true) - : value_(std::move(value)), auto_destruct_(auto_destruct) {} + explicit AutoDestruct(T value) : value_(std::move(value)) {} CRU_DELETE_COPY(AutoDestruct) AutoDestruct(AutoDestruct&& other) noexcept - : value_(std::move(other.value_)), auto_destruct_(other.auto_destruct_) { + : value_(std::move(other.value_)) { other.value_ = std::nullopt; - other.auto_destruct_ = false; } AutoDestruct& operator=(AutoDestruct&& other) noexcept { if (this != &other) { DoDestruct(); - value_ = other.value_; - auto_destruct_ = other.auto_destruct_; - other.value_ = std::nullopt; - other.auto_destruct_ = false; + value_.swap(other.value_); } return *this; } @@ -96,7 +91,6 @@ class AutoDestruct { CheckValid(); auto value = std::move(*value_); value_ = std::nullopt; - auto_destruct_ = false; return value; } @@ -109,13 +103,13 @@ class AutoDestruct { private: void DoDestruct() { - if (auto_destruct_ && value_) { + if (value_) { Destructor{}(*value_); + value_ = std::nullopt; } } private: std::optional<T> value_; - bool auto_destruct_; }; } // namespace cru diff --git a/include/cru/platform/gui/sdl/Window.h b/include/cru/platform/gui/sdl/Window.h index 48d7c70a..5b8b17a2 100644 --- a/include/cru/platform/gui/sdl/Window.h +++ b/include/cru/platform/gui/sdl/Window.h @@ -104,6 +104,7 @@ class SdlWindow : public SdlResource, public virtual INativeWindow { private: SdlUiApplication* application_; SDL_Window* sdl_window_; + bool sdl_is_popup_; SDL_WindowID sdl_window_id_; Rect client_rect_; SdlWindow* parent_; diff --git a/include/cru/ui/controls/Button.h b/include/cru/ui/controls/Button.h index 80d21d08..5ae3de49 100644 --- a/include/cru/ui/controls/Button.h +++ b/include/cru/ui/controls/Button.h @@ -14,7 +14,6 @@ class CRU_UI_API Button : public SingleChildControl<render::BorderRenderObject>, public: Button(); - ~Button() override; public: helper::ClickState GetClickState() override { diff --git a/include/cru/ui/controls/CheckBox.h b/include/cru/ui/controls/CheckBox.h index 2e4685d5..16fe0725 100644 --- a/include/cru/ui/controls/CheckBox.h +++ b/include/cru/ui/controls/CheckBox.h @@ -15,7 +15,6 @@ class CRU_UI_API CheckBox : public Control, static constexpr auto kControlName = "CheckBox"; CheckBox(); - ~CheckBox() override; render::RenderObject* GetRenderObject() override { return &container_render_object_; diff --git a/include/cru/ui/controls/Control.h b/include/cru/ui/controls/Control.h index 8cd7a375..aa1cef8a 100644 --- a/include/cru/ui/controls/Control.h +++ b/include/cru/ui/controls/Control.h @@ -12,6 +12,11 @@ namespace cru::ui::controls { +struct ControlHostChangeEventArgs { + ControlHost* old_host; + ControlHost* new_host; +}; + /** * \remarks If you want to write a new control. You should override following * methods: @@ -143,6 +148,8 @@ class CRU_UI_API Control : public Object, CRU_DEFINE_ROUTED_EVENT(GainFocus, events::FocusChangeEventArgs) CRU_DEFINE_ROUTED_EVENT(LoseFocus, events::FocusChangeEventArgs) + CRU_DEFINE_EVENT(ControlHostChange, const ControlHostChangeEventArgs&) + //*************** region: tree *************** protected: virtual void OnParentChanged(Control* old_parent, Control* new_parent); diff --git a/include/cru/ui/controls/IconButton.h b/include/cru/ui/controls/IconButton.h index b061bc87..5b0f899d 100644 --- a/include/cru/ui/controls/IconButton.h +++ b/include/cru/ui/controls/IconButton.h @@ -21,7 +21,6 @@ class CRU_UI_API IconButton : public Control, public: IconButton(); IconButton(std::string_view icon_svg_path_data_string, const Rect& view_port); - ~IconButton() override; render::RenderObject* GetRenderObject() override { return &container_render_object_; diff --git a/include/cru/ui/controls/Window.h b/include/cru/ui/controls/Window.h index 131d68a8..355b03a9 100644 --- a/include/cru/ui/controls/Window.h +++ b/include/cru/ui/controls/Window.h @@ -24,8 +24,9 @@ class CRU_UI_API Window Window(); - static Window* CreatePopup(); + static Window* CreatePopup(Control* attached_control); + Control* GetAttachedControl(); void SetAttachedControl(Control* control); platform::gui::INativeWindow* GetNativeWindow(); @@ -36,6 +37,7 @@ class CRU_UI_API Window std::unique_ptr<ControlHost> control_host_; Control* attached_control_; + EventHandlerRevokerGuard parent_window_guard_; EventHandlerRevokerListGuard gain_focus_on_create_and_destroy_when_lose_focus_event_guard_; |
