From 2eb34dfc3dd3ca718da6ebf049886b4ae140b332 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Wed, 19 Nov 2025 02:59:30 +0800 Subject: Remove all children when control destroyed. --- include/cru/ui/components/Menu.h | 4 ++-- include/cru/ui/controls/ControlHost.h | 4 ++-- include/cru/ui/controls/Window.h | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/cru/ui/components/Menu.h b/include/cru/ui/components/Menu.h index 92731f2e..a8a90ed7 100644 --- a/include/cru/ui/components/Menu.h +++ b/include/cru/ui/components/Menu.h @@ -70,7 +70,7 @@ class CRU_UI_API PopupMenu : public Component { public: controls::Control* GetRootControl() override; - controls::Window* GetPopup() { return popup_; } + controls::Window* GetPopup() { return popup_.get(); } Menu* GetMenu() { return &menu_; } // position relative to screen left top. @@ -86,7 +86,7 @@ class CRU_UI_API PopupMenu : public Component { private: controls::Control* attached_control_; - controls::Window* popup_; + std::unique_ptr popup_; Menu menu_; }; } // namespace cru::ui::components diff --git a/include/cru/ui/controls/ControlHost.h b/include/cru/ui/controls/ControlHost.h index c67e8a72..a27be835 100644 --- a/include/cru/ui/controls/ControlHost.h +++ b/include/cru/ui/controls/ControlHost.h @@ -169,7 +169,8 @@ class CRU_UI_API ControlHost : public Object { } void UpdateCursor(); - void NotifyControlParentChange(Control* control, Control* old_parent, Control* new_parent); + void NotifyControlParentChange(Control* control, Control* old_parent, + Control* new_parent); private: int event_handling_count_; @@ -185,7 +186,6 @@ class CRU_UI_API ControlHost : public Object { bool layout_prefer_to_fill_window_; - platform::gui::TimerAutoCanceler repaint_schedule_canceler_; platform::gui::TimerAutoCanceler relayout_schedule_canceler_; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/Window.h b/include/cru/ui/controls/Window.h index a2ae01f9..3d3ff0b0 100644 --- a/include/cru/ui/controls/Window.h +++ b/include/cru/ui/controls/Window.h @@ -1,5 +1,6 @@ #pragma once #include "../render/StackLayoutRenderObject.h" +#include "ControlHost.h" #include "LayoutControl.h" #include @@ -9,6 +10,8 @@ #include #include +#include + namespace cru::ui::controls { class CRU_UI_API Window : public LayoutControl { @@ -31,7 +34,7 @@ class CRU_UI_API Window void SetGainFocusOnCreateAndDestroyWhenLoseFocus(bool value); private: - std::shared_ptr control_host_; + std::unique_ptr control_host_; Control* attached_control_; -- cgit v1.2.3