diff options
author | crupest <crupest@outlook.com> | 2022-02-16 23:41:28 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-16 23:41:28 +0800 |
commit | 77e0fd5cf7dd35324a7c3a43f2004fb923c6254c (patch) | |
tree | 0d66fd74fa61bb680ac0ae35c9faa4e5d853f295 /src/ui | |
parent | 9307bd1af7c52aaf9c6d25b598bf3069a63c32a1 (diff) | |
download | cru-77e0fd5cf7dd35324a7c3a43f2004fb923c6254c.tar.gz cru-77e0fd5cf7dd35324a7c3a43f2004fb923c6254c.tar.bz2 cru-77e0fd5cf7dd35324a7c3a43f2004fb923c6254c.zip |
...
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/components/Menu.cpp | 4 | ||||
-rw-r--r-- | src/ui/components/PopupButton.cpp | 2 | ||||
-rw-r--r-- | src/ui/components/Select.cpp | 2 | ||||
-rw-r--r-- | src/ui/controls/Control.cpp | 19 |
4 files changed, 15 insertions, 12 deletions
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp index ae00a2b2..f62138cd 100644 --- a/src/ui/components/Menu.cpp +++ b/src/ui/components/Menu.cpp @@ -23,7 +23,7 @@ MenuItem::MenuItem() { MenuItem::MenuItem(String text) : MenuItem() { SetText(std::move(text)); } -MenuItem::~MenuItem() { container_.RemoveFromParent(); } +MenuItem::~MenuItem() {} void MenuItem::SetText(String text) { text_.SetText(std::move(text)); } @@ -33,8 +33,6 @@ Menu::~Menu() { for (auto item : items_) { delete item; } - - container_.RemoveFromParent(); } void Menu::AddItemAt(Component* item, gsl::index index) { diff --git a/src/ui/components/PopupButton.cpp b/src/ui/components/PopupButton.cpp index 8eed7c09..f09bf2d1 100644 --- a/src/ui/components/PopupButton.cpp +++ b/src/ui/components/PopupButton.cpp @@ -12,7 +12,7 @@ PopupMenuTextButton::PopupMenuTextButton() : popup_menu_(&button_) { }); } -PopupMenuTextButton::~PopupMenuTextButton() { button_.RemoveFromParent(); } +PopupMenuTextButton::~PopupMenuTextButton() {} void PopupMenuTextButton::SetMenuItems(std::vector<String> items) { popup_menu_.GetMenu()->ClearItems(); diff --git a/src/ui/components/Select.cpp b/src/ui/components/Select.cpp index 6a316717..90b49d30 100644 --- a/src/ui/components/Select.cpp +++ b/src/ui/components/Select.cpp @@ -13,7 +13,7 @@ Select::Select() { }); } -Select::~Select() { button_.RemoveFromParent(); } +Select::~Select() {} void Select::SetItems(std::vector<String> items) { items_ = items; diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index 43faba69..f2d4760e 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -27,7 +27,10 @@ Control::Control() { }); } -Control::~Control() { RemoveFromParent(); } +Control::~Control() { + in_destruction_ = true; + RemoveFromParent(); +} void Control::SetParent(Control* parent) { if (parent_ == parent) return; @@ -111,7 +114,7 @@ void Control::OnParentChangedCore(Control* old_parent, Control* new_parent) { OnWindowHostChangedCore(old_host, new_window_host); } - OnParentChanged(old_parent, new_parent); + if (!in_destruction_) OnParentChanged(old_parent, new_parent); } void Control::OnWindowHostChangedCore(host::WindowHost* old_host, @@ -125,10 +128,12 @@ void Control::OnWindowHostChangedCore(host::WindowHost* old_host, } } - ForEachChild([old_host, new_host](Control* child) { - child->window_host_ = new_host; - child->OnWindowHostChangedCore(old_host, new_host); - }); - OnWindowHostChanged(old_host, new_host); + if (!in_destruction_) { + ForEachChild([old_host, new_host](Control* child) { + child->window_host_ = new_host; + child->OnWindowHostChangedCore(old_host, new_host); + }); + OnWindowHostChanged(old_host, new_host); + } } } // namespace cru::ui::controls |