diff options
author | crupest <crupest@outlook.com> | 2022-03-29 16:37:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-29 16:37:33 +0800 |
commit | e45106981ba5720947cdb56a3f48ad3e91a996b8 (patch) | |
tree | 77a0300f4badb0dfc888983e75d5d2c1ad1d7c8a | |
parent | 7a564d98db0b7c7be5b3bfac955cb88998a472ac (diff) | |
download | cru-e45106981ba5720947cdb56a3f48ad3e91a996b8.tar.gz cru-e45106981ba5720947cdb56a3f48ad3e91a996b8.tar.bz2 cru-e45106981ba5720947cdb56a3f48ad3e91a996b8.zip |
...
-rw-r--r-- | src/theme_builder/components/StyleRuleSetEditor.cpp | 10 | ||||
-rw-r--r-- | src/theme_builder/components/StyleRuleSetEditor.h | 5 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/theme_builder/components/StyleRuleSetEditor.cpp b/src/theme_builder/components/StyleRuleSetEditor.cpp index 15c88d33..bc28a462 100644 --- a/src/theme_builder/components/StyleRuleSetEditor.cpp +++ b/src/theme_builder/components/StyleRuleSetEditor.cpp @@ -4,6 +4,7 @@ #include <optional> #include "cru/common/Exception.h" #include "cru/common/String.h" +#include "cru/ui/DeleteLater.h" #include "cru/ui/ThemeManager.h" #include "cru/ui/controls/FlexLayout.h" #include "cru/ui/model/IListChangeNotify.h" @@ -54,7 +55,7 @@ void StyleRuleSetEditor::BindStyleRuleSet( Index StyleRuleSetEditor::IndexOfRuleEditor(StyleRuleEditor* editor) { auto iter = std::find_if(style_rule_editors_.cbegin(), style_rule_editors_.cend(), - [editor](const std::unique_ptr<StyleRuleEditor>& p) { + [editor](const ui::DeleteLaterPtr<StyleRuleEditor>& p) { return p.get() == editor; }); return iter - style_rule_editors_.cbegin(); @@ -69,7 +70,7 @@ void StyleRuleSetEditor::UpdateView( for (auto i = change->position; i < change->position + change->count; ++i) { const auto& rule = style_rule_set->GetStyleRule(i); - auto style_rule_editor = std::make_unique<StyleRuleEditor>(); + auto style_rule_editor = ui::MakeDeleteLaterPtr<StyleRuleEditor>(); style_rule_editor->SetValue(rule, false); style_rule_editor->RemoveEvent()->AddSpyOnlyHandler( [this, editor = style_rule_editor.get()] { @@ -77,6 +78,7 @@ void StyleRuleSetEditor::UpdateView( }); style_rule_editor->ChangeEvent()->AddSpyOnlyHandler( [this, editor = style_rule_editor.get()]() { + suppress_next_set_ = true; style_rule_set_->SetStyleRule(IndexOfRuleEditor(editor), editor->GetValue()); }); @@ -95,6 +97,10 @@ void StyleRuleSetEditor::UpdateView( break; } case ui::model::ListChangeType::kItemSet: { + if (suppress_next_set_) { + suppress_next_set_ = false; + break; + } for (auto i = change->position; i < change->position + change->count; ++i) { const auto& rule = style_rule_set->GetStyleRule(i); diff --git a/src/theme_builder/components/StyleRuleSetEditor.h b/src/theme_builder/components/StyleRuleSetEditor.h index c5fe67fd..03148889 100644 --- a/src/theme_builder/components/StyleRuleSetEditor.h +++ b/src/theme_builder/components/StyleRuleSetEditor.h @@ -1,5 +1,6 @@ #pragma once #include "StyleRuleEditor.h" +#include "cru/ui/DeleteLater.h" #include "cru/ui/components/Component.h" #include "cru/ui/controls/Button.h" #include "cru/ui/controls/Control.h" @@ -35,7 +36,9 @@ class StyleRuleSetEditor : public ui::components::Component { ui::controls::ScrollView scroll_view_; ui::controls::FlexLayout container_; ui::controls::FlexLayout rules_layout_; - std::vector<std::unique_ptr<StyleRuleEditor>> style_rule_editors_; + std::vector<ui::DeleteLaterPtr<StyleRuleEditor>> style_rule_editors_; ui::controls::IconButton add_button_; + + bool suppress_next_set_ = false; }; } // namespace cru::theme_builder::components |