aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-03-28 19:38:58 +0800
committercrupest <crupest@outlook.com>2022-03-28 19:38:58 +0800
commitbfa89c0efd310c07e4255b45f99a2f05338fbe3f (patch)
treec2f22c63b1c80fe2c8f299034aeb709c5a63276f
parent7320f082c4bce5939cfa7c9a23765249dac55d07 (diff)
downloadcru-bfa89c0efd310c07e4255b45f99a2f05338fbe3f.tar.gz
cru-bfa89c0efd310c07e4255b45f99a2f05338fbe3f.tar.bz2
cru-bfa89c0efd310c07e4255b45f99a2f05338fbe3f.zip
...
-rw-r--r--src/theme_builder/components/StyleRuleSetEditor.cpp19
-rw-r--r--src/theme_builder/components/StyleRuleSetEditor.h2
2 files changed, 18 insertions, 3 deletions
diff --git a/src/theme_builder/components/StyleRuleSetEditor.cpp b/src/theme_builder/components/StyleRuleSetEditor.cpp
index 5e942827..15c88d33 100644
--- a/src/theme_builder/components/StyleRuleSetEditor.cpp
+++ b/src/theme_builder/components/StyleRuleSetEditor.cpp
@@ -1,4 +1,5 @@
#include "StyleRuleSetEditor.h"
+#include <algorithm>
#include <memory>
#include <optional>
#include "cru/common/Exception.h"
@@ -50,6 +51,15 @@ 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) {
+ return p.get() == editor;
+ });
+ return iter - style_rule_editors_.cbegin();
+}
+
void StyleRuleSetEditor::UpdateView(
ui::style::StyleRuleSet* style_rule_set,
std::optional<ui::model::ListChange> change) {
@@ -62,10 +72,13 @@ void StyleRuleSetEditor::UpdateView(
auto style_rule_editor = std::make_unique<StyleRuleEditor>();
style_rule_editor->SetValue(rule, false);
style_rule_editor->RemoveEvent()->AddSpyOnlyHandler(
- [this, i] { style_rule_set_->RemoveStyleRule(i); });
+ [this, editor = style_rule_editor.get()] {
+ style_rule_set_->RemoveStyleRule(IndexOfRuleEditor(editor));
+ });
style_rule_editor->ChangeEvent()->AddSpyOnlyHandler(
- [this, i, editor = style_rule_editor.get()]() {
- style_rule_set_->SetStyleRule(i, editor->GetValue());
+ [this, editor = style_rule_editor.get()]() {
+ style_rule_set_->SetStyleRule(IndexOfRuleEditor(editor),
+ editor->GetValue());
});
style_rule_editors_.insert(style_rule_editors_.cbegin() + i,
std::move(style_rule_editor));
diff --git a/src/theme_builder/components/StyleRuleSetEditor.h b/src/theme_builder/components/StyleRuleSetEditor.h
index 864262eb..c5fe67fd 100644
--- a/src/theme_builder/components/StyleRuleSetEditor.h
+++ b/src/theme_builder/components/StyleRuleSetEditor.h
@@ -24,6 +24,8 @@ class StyleRuleSetEditor : public ui::components::Component {
void BindStyleRuleSet(std::shared_ptr<ui::style::StyleRuleSet> rule_set);
private:
+ Index IndexOfRuleEditor(StyleRuleEditor* editor);
+
void UpdateView(ui::style::StyleRuleSet* style_rule_set,
std::optional<ui::model::ListChange> change = std::nullopt);