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 | |
parent | 9307bd1af7c52aaf9c6d25b598bf3069a63c32a1 (diff) | |
download | cru-77e0fd5cf7dd35324a7c3a43f2004fb923c6254c.tar.gz cru-77e0fd5cf7dd35324a7c3a43f2004fb923c6254c.tar.bz2 cru-77e0fd5cf7dd35324a7c3a43f2004fb923c6254c.zip |
...
20 files changed, 33 insertions, 39 deletions
diff --git a/include/cru/ui/components/Component.h b/include/cru/ui/components/Component.h index 795d0db0..64c3ef47 100644 --- a/include/cru/ui/components/Component.h +++ b/include/cru/ui/components/Component.h @@ -4,9 +4,8 @@ namespace cru::ui::components { /** * \brief A component is a composition of controls. - * \remarks In destructor, component should remove root control from its parent - * by calling Control::RemoveFromParent. It should respect children's - * Component::IsDeleteByParent value and decide whether to delete it. + * \remarks Component should respect children's Component::IsDeleteByParent + * value and decide whether to delete it. */ class CRU_UI_API Component : public Object { public: diff --git a/include/cru/ui/controls/Control.h b/include/cru/ui/controls/Control.h index 4dad4549..3293969d 100644 --- a/include/cru/ui/controls/Control.h +++ b/include/cru/ui/controls/Control.h @@ -157,6 +157,8 @@ class CRU_UI_API Control : public Object { host::WindowHost* new_host); private: + bool in_destruction_ = false; + Control* parent_ = nullptr; host::WindowHost* window_host_ = nullptr; diff --git a/src/theme_builder/components/StyleRuleEditor.cpp b/src/theme_builder/components/StyleRuleEditor.cpp index 7a99900b..b697f92c 100644 --- a/src/theme_builder/components/StyleRuleEditor.cpp +++ b/src/theme_builder/components/StyleRuleEditor.cpp @@ -17,7 +17,7 @@ StyleRuleEditor::StyleRuleEditor() { [this] { remove_event_.Raise(nullptr); }); } -StyleRuleEditor::~StyleRuleEditor() { main_layout_.RemoveFromParent(); } +StyleRuleEditor::~StyleRuleEditor() {} ui::style::StyleRule StyleRuleEditor::GetValue() const { return ui::style::StyleRule(condition_editor_->GetCondition(), diff --git a/src/theme_builder/components/StyleRuleSetEditor.cpp b/src/theme_builder/components/StyleRuleSetEditor.cpp index b5e6de91..dde7f3b8 100644 --- a/src/theme_builder/components/StyleRuleSetEditor.cpp +++ b/src/theme_builder/components/StyleRuleSetEditor.cpp @@ -25,7 +25,7 @@ StyleRuleSetEditor::StyleRuleSetEditor() { }); } -StyleRuleSetEditor::~StyleRuleSetEditor() { scroll_view_.RemoveFromParent(); } +StyleRuleSetEditor::~StyleRuleSetEditor() {} void StyleRuleSetEditor::BindStyleRuleSet( std::shared_ptr<ui::style::StyleRuleSet> rule_set) { diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp index b4f0b458..ae72b51f 100644 --- a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp +++ b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp @@ -23,9 +23,7 @@ CompoundConditionEditorChild::CompoundConditionEditorChild( [this] { this->remove_event_.Raise(nullptr); }); } -CompoundConditionEditorChild::~CompoundConditionEditorChild() { - container_.RemoveFromParent(); -} +CompoundConditionEditorChild::~CompoundConditionEditorChild() {} CompoundConditionEditor::CompoundConditionEditor() { SetLabel(u"Compound Condition"); diff --git a/src/theme_builder/components/conditions/ConditionEditor.cpp b/src/theme_builder/components/conditions/ConditionEditor.cpp index 8ffd33a5..2840b250 100644 --- a/src/theme_builder/components/conditions/ConditionEditor.cpp +++ b/src/theme_builder/components/conditions/ConditionEditor.cpp @@ -13,7 +13,7 @@ ConditionEditor::ConditionEditor() { container_.AddChild(&label_); } -ConditionEditor::~ConditionEditor() { container_.RemoveFromParent(); } +ConditionEditor::~ConditionEditor() {} std::unique_ptr<ConditionEditor> CreateConditionEditor( ui::style::Condition* condition) { diff --git a/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp index 2e921f96..3b96b716 100644 --- a/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp +++ b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp @@ -15,9 +15,7 @@ CheckBoxPropertyEditor::CheckBoxPropertyEditor() { }); } -CheckBoxPropertyEditor::~CheckBoxPropertyEditor() { - container_.RemoveFromParent(); -} +CheckBoxPropertyEditor::~CheckBoxPropertyEditor() {} void CheckBoxPropertyEditor::SetValue(bool value, bool trigger_change) { if (!trigger_change) suppress_next_change_event_ = true; diff --git a/src/theme_builder/components/properties/ColorPropertyEditor.cpp b/src/theme_builder/components/properties/ColorPropertyEditor.cpp index 7c3b9b46..d6577abb 100644 --- a/src/theme_builder/components/properties/ColorPropertyEditor.cpp +++ b/src/theme_builder/components/properties/ColorPropertyEditor.cpp @@ -29,7 +29,7 @@ ColorPropertyEditor::ColorPropertyEditor() { }); } -ColorPropertyEditor::~ColorPropertyEditor() { container_.RemoveFromParent(); } +ColorPropertyEditor::~ColorPropertyEditor() {} void ColorPropertyEditor::SetValue(const ui::Color &color, bool trigger_change) { diff --git a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp index 9dc8d20e..635069fe 100644 --- a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp +++ b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp @@ -34,9 +34,7 @@ CornerRadiusPropertyEditor::CornerRadiusPropertyEditor() { }); } -CornerRadiusPropertyEditor::~CornerRadiusPropertyEditor() { - container_.RemoveFromParent(); -} +CornerRadiusPropertyEditor::~CornerRadiusPropertyEditor() {} void CornerRadiusPropertyEditor::SetValue(const ui::CornerRadius& corner_radius, bool trigger_change) { diff --git a/src/theme_builder/components/properties/OptionalPropertyEditor.h b/src/theme_builder/components/properties/OptionalPropertyEditor.h index 03eb759c..98b9786d 100644 --- a/src/theme_builder/components/properties/OptionalPropertyEditor.h +++ b/src/theme_builder/components/properties/OptionalPropertyEditor.h @@ -21,7 +21,7 @@ class OptionalPropertyEditor : public ui::components::Component { } }); } - ~OptionalPropertyEditor() override { container_.RemoveFromParent(); } + ~OptionalPropertyEditor() override {} ui::controls::Control* GetRootControl() override { return &container_; } diff --git a/src/theme_builder/components/properties/PointPropertyEditor.cpp b/src/theme_builder/components/properties/PointPropertyEditor.cpp index 9b5a5e83..702b26e8 100644 --- a/src/theme_builder/components/properties/PointPropertyEditor.cpp +++ b/src/theme_builder/components/properties/PointPropertyEditor.cpp @@ -24,7 +24,7 @@ PointPropertyEditor::PointPropertyEditor() { }); } -PointPropertyEditor::~PointPropertyEditor() { container_.RemoveFromParent(); } +PointPropertyEditor::~PointPropertyEditor() {} void PointPropertyEditor::SetValue(const ui::Point& point, bool trigger_change) { diff --git a/src/theme_builder/components/properties/SelectPropertyEditor.cpp b/src/theme_builder/components/properties/SelectPropertyEditor.cpp index 10011d65..243f6035 100644 --- a/src/theme_builder/components/properties/SelectPropertyEditor.cpp +++ b/src/theme_builder/components/properties/SelectPropertyEditor.cpp @@ -16,6 +16,6 @@ SelectPropertyEditor::SelectPropertyEditor() { }); } -SelectPropertyEditor::~SelectPropertyEditor() { container_.RemoveFromParent(); } +SelectPropertyEditor::~SelectPropertyEditor() {} } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/TextPropertyEditor.cpp b/src/theme_builder/components/properties/TextPropertyEditor.cpp index 916e907b..9854019c 100644 --- a/src/theme_builder/components/properties/TextPropertyEditor.cpp +++ b/src/theme_builder/components/properties/TextPropertyEditor.cpp @@ -12,7 +12,7 @@ TextPropertyEditor::TextPropertyEditor() { }); } -TextPropertyEditor::~TextPropertyEditor() { container_.RemoveFromParent(); } +TextPropertyEditor::~TextPropertyEditor() {} bool TextPropertyEditor::Validate(StringView text, String* error_message) { return true; diff --git a/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp b/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp index 2d922b69..c5e5f658 100644 --- a/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp +++ b/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp @@ -23,9 +23,7 @@ ThicknessPropertyEditor::ThicknessPropertyEditor() { }); } -ThicknessPropertyEditor::~ThicknessPropertyEditor() { - container_.RemoveFromParent(); -} +ThicknessPropertyEditor::~ThicknessPropertyEditor() {} void ThicknessPropertyEditor::SetValue(const ui::Thickness &thickness, bool trigger_change) { diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp index 69fd0824..568c34f3 100644 --- a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp +++ b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp @@ -20,9 +20,7 @@ CompoundStylerEditorChild::CompoundStylerEditorChild( [this] { this->remove_event_.Raise(nullptr); }); } -CompoundStylerEditorChild::~CompoundStylerEditorChild() { - container_.RemoveFromParent(); -} +CompoundStylerEditorChild::~CompoundStylerEditorChild() {} CompoundStylerEditor::CompoundStylerEditor() { SetLabel(u"Compound Styler"); diff --git a/src/theme_builder/components/stylers/StylerEditor.cpp b/src/theme_builder/components/stylers/StylerEditor.cpp index 4f3238e2..99eaebad 100644 --- a/src/theme_builder/components/stylers/StylerEditor.cpp +++ b/src/theme_builder/components/stylers/StylerEditor.cpp @@ -10,7 +10,7 @@ StylerEditor::StylerEditor() { container_.AddChild(&label_); } -StylerEditor::~StylerEditor() { container_.RemoveFromParent(); } +StylerEditor::~StylerEditor() {} std::unique_ptr<StylerEditor> CreateStylerEditor(ui::style::Styler* styler) { if (auto compound_styler = dynamic_cast<ui::style::CompoundStyler*>(styler)) { 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 |