aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-02-17 18:32:52 +0800
committercrupest <crupest@outlook.com>2022-02-17 18:32:52 +0800
commitada641977cd57a50fc862243ba256c58efc065b8 (patch)
tree0f2124b88496f42e2cce2e3aaa64211131c18b37 /src
parent9b3b13f78fffefb18f64aad88891d36009a8052e (diff)
downloadcru-ada641977cd57a50fc862243ba256c58efc065b8.tar.gz
cru-ada641977cd57a50fc862243ba256c58efc065b8.tar.bz2
cru-ada641977cd57a50fc862243ba256c58efc065b8.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/theme_builder/CMakeLists.txt1
-rw-r--r--src/theme_builder/components/Editor.cpp23
-rw-r--r--src/theme_builder/components/Editor.h25
-rw-r--r--src/theme_builder/components/conditions/CheckedConditionEditor.cpp3
-rw-r--r--src/theme_builder/components/conditions/CheckedConditionEditor.h4
-rw-r--r--src/theme_builder/components/conditions/ClickStateConditionEditor.cpp3
-rw-r--r--src/theme_builder/components/conditions/ClickStateConditionEditor.h4
-rw-r--r--src/theme_builder/components/conditions/CompoundConditionEditor.cpp10
-rw-r--r--src/theme_builder/components/conditions/CompoundConditionEditor.h4
-rw-r--r--src/theme_builder/components/conditions/ConditionEditor.h5
-rw-r--r--src/theme_builder/components/conditions/FocusConditionEditor.cpp4
-rw-r--r--src/theme_builder/components/conditions/FocusConditionEditor.h4
-rw-r--r--src/theme_builder/components/conditions/NoConditionEditor.h5
-rw-r--r--src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp11
-rw-r--r--src/theme_builder/components/properties/CheckBoxPropertyEditor.h10
-rw-r--r--src/theme_builder/components/properties/ColorPropertyEditor.cpp6
-rw-r--r--src/theme_builder/components/properties/ColorPropertyEditor.h8
-rw-r--r--src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp32
-rw-r--r--src/theme_builder/components/properties/CornerRadiusPropertyEditor.h12
-rw-r--r--src/theme_builder/components/properties/OptionalPropertyEditor.h14
-rw-r--r--src/theme_builder/components/properties/PointPropertyEditor.cpp30
-rw-r--r--src/theme_builder/components/properties/PointPropertyEditor.h9
-rw-r--r--src/theme_builder/components/properties/SelectPropertyEditor.cpp10
-rw-r--r--src/theme_builder/components/properties/SelectPropertyEditor.h11
-rw-r--r--src/theme_builder/components/properties/ThicknessPropertyEditor.cpp14
-rw-r--r--src/theme_builder/components/properties/ThicknessPropertyEditor.h8
-rw-r--r--src/theme_builder/components/stylers/BorderStylerEditor.cpp17
-rw-r--r--src/theme_builder/components/stylers/BorderStylerEditor.h4
-rw-r--r--src/theme_builder/components/stylers/CompoundStylerEditor.cpp29
-rw-r--r--src/theme_builder/components/stylers/CompoundStylerEditor.h4
-rw-r--r--src/theme_builder/components/stylers/CursorStylerEditor.cpp4
-rw-r--r--src/theme_builder/components/stylers/CursorStylerEditor.h4
-rw-r--r--src/theme_builder/components/stylers/StylerEditor.h5
33 files changed, 142 insertions, 195 deletions
diff --git a/src/theme_builder/CMakeLists.txt b/src/theme_builder/CMakeLists.txt
index cbd180bf..6bdd44b2 100644
--- a/src/theme_builder/CMakeLists.txt
+++ b/src/theme_builder/CMakeLists.txt
@@ -1,5 +1,6 @@
add_executable(cru_theme_builder
main.cpp
+ components/Editor.cpp
components/MainWindow.cpp
components/StyleRuleEditor.cpp
components/StyleRuleSetEditor.cpp
diff --git a/src/theme_builder/components/Editor.cpp b/src/theme_builder/components/Editor.cpp
new file mode 100644
index 00000000..89e27e83
--- /dev/null
+++ b/src/theme_builder/components/Editor.cpp
@@ -0,0 +1,23 @@
+#include "Editor.h"
+
+namespace cru::theme_builder::components {
+
+void Editor::RaiseChangeEvent() {
+ if (suppress_next_change_event_) {
+ suppress_next_change_event_ = false;
+ } else {
+ change_event_.Raise(nullptr);
+ }
+}
+
+void Editor::SuppressNextChangeEvent() { suppress_next_change_event_ = true; }
+
+void Editor::ConnectChangeEvent(IEvent<std::nullptr_t>* event) {
+ event->AddHandler([this](std::nullptr_t) { RaiseChangeEvent(); });
+}
+
+void Editor::ConnectChangeEvent(Editor* editor) {
+ ConnectChangeEvent(editor->ChangeEvent());
+}
+
+} // namespace cru::theme_builder::components
diff --git a/src/theme_builder/components/Editor.h b/src/theme_builder/components/Editor.h
new file mode 100644
index 00000000..29809c82
--- /dev/null
+++ b/src/theme_builder/components/Editor.h
@@ -0,0 +1,25 @@
+#pragma once
+#include "cru/common/Event.h"
+#include "cru/ui/components/Component.h"
+
+namespace cru::theme_builder::components {
+class Editor : public ui::components::Component {
+ public:
+ Editor() = default;
+ ~Editor() override = default;
+
+ public:
+ IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; }
+
+ protected:
+ void RaiseChangeEvent();
+ void SuppressNextChangeEvent();
+ void ConnectChangeEvent(IEvent<std::nullptr_t>* event);
+ void ConnectChangeEvent(Editor* editor);
+ void ConnectChangeEvent(Editor& editor) { ConnectChangeEvent(&editor); }
+
+ private:
+ bool suppress_next_change_event_ = false;
+ Event<std::nullptr_t> change_event_;
+};
+} // namespace cru::theme_builder::components
diff --git a/src/theme_builder/components/conditions/CheckedConditionEditor.cpp b/src/theme_builder/components/conditions/CheckedConditionEditor.cpp
index bd2dbe0c..64370981 100644
--- a/src/theme_builder/components/conditions/CheckedConditionEditor.cpp
+++ b/src/theme_builder/components/conditions/CheckedConditionEditor.cpp
@@ -9,8 +9,7 @@ CheckedConditionEditor::CheckedConditionEditor() {
checked_check_box_.SetLabel(u"Checked");
GetContainer()->AddChild(checked_check_box_.GetRootControl());
- checked_check_box_.ChangeEvent()->AddSpyOnlyHandler(
- [this] { change_event_.Raise(nullptr); });
+ ConnectChangeEvent(checked_check_box_);
}
CheckedConditionEditor::~CheckedConditionEditor() {}
diff --git a/src/theme_builder/components/conditions/CheckedConditionEditor.h b/src/theme_builder/components/conditions/CheckedConditionEditor.h
index 9e2ebddc..7cf14912 100644
--- a/src/theme_builder/components/conditions/CheckedConditionEditor.h
+++ b/src/theme_builder/components/conditions/CheckedConditionEditor.h
@@ -22,11 +22,7 @@ class CheckedConditionEditor : public ConditionEditor {
return GetValue();
}
- IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; }
-
private:
properties::CheckBoxPropertyEditor checked_check_box_;
-
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::conditions
diff --git a/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp b/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp
index 3929c29c..a8d5cc87 100644
--- a/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp
+++ b/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp
@@ -50,8 +50,7 @@ ClickStateConditionEditor::ClickStateConditionEditor() {
click_state_select_.SetItems(kClickStates);
click_state_select_.SetSelectedIndex(0, false);
- click_state_select_.ChangeEvent()->AddSpyOnlyHandler(
- [this] { change_event_.Raise(nullptr); });
+ ConnectChangeEvent(click_state_select_);
}
ClickStateConditionEditor::~ClickStateConditionEditor() {}
diff --git a/src/theme_builder/components/conditions/ClickStateConditionEditor.h b/src/theme_builder/components/conditions/ClickStateConditionEditor.h
index fa4b0c52..454a1346 100644
--- a/src/theme_builder/components/conditions/ClickStateConditionEditor.h
+++ b/src/theme_builder/components/conditions/ClickStateConditionEditor.h
@@ -24,11 +24,7 @@ class ClickStateConditionEditor : public ConditionEditor {
return GetValue();
}
- IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; }
-
private:
properties::SelectPropertyEditor click_state_select_;
-
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::conditions
diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp
index ae72b51f..b7f54f77 100644
--- a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp
+++ b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp
@@ -59,17 +59,18 @@ CompoundConditionEditor::CompoundConditionEditor() {
break;
}
if (editor) {
+ ConnectChangeEvent(editor.get());
auto child =
std::make_unique<CompoundConditionEditorChild>(std::move(editor));
child->RemoveEvent()->AddSpyOnlyHandler([this, c = child.get()] {
auto index = this->children_container_.IndexOf(c->GetRootControl());
this->children_.erase(this->children_.begin() + index);
this->children_container_.RemoveChildAt(index);
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
});
children_.push_back(std::move(child));
children_container_.AddChild(children_.back()->GetRootControl());
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
}
});
}
@@ -92,19 +93,20 @@ void CompoundConditionEditor::SetChildren(
children_.clear();
for (const auto& condition : children) {
auto condition_editor = CreateConditionEditor(condition.get());
+ ConnectChangeEvent(condition_editor.get());
auto child = std::make_unique<CompoundConditionEditorChild>(
std::move(condition_editor));
child->RemoveEvent()->AddSpyOnlyHandler([this, c = child.get()] {
auto index = this->children_container_.IndexOf(c->GetRootControl());
this->children_.erase(this->children_.begin() + index);
this->children_container_.RemoveChildAt(index);
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
});
children_.push_back(std::move(child));
children_container_.AddChild(children_.back()->GetRootControl());
}
if (trigger_change) {
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
}
}
} // namespace cru::theme_builder::components::conditions
diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.h b/src/theme_builder/components/conditions/CompoundConditionEditor.h
index 50f745c3..771d694f 100644
--- a/src/theme_builder/components/conditions/CompoundConditionEditor.h
+++ b/src/theme_builder/components/conditions/CompoundConditionEditor.h
@@ -42,14 +42,10 @@ class CompoundConditionEditor : public ConditionEditor {
void SetChildren(std::vector<ClonablePtr<ui::style::Condition>> children,
bool trigger_change = true);
- IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; }
-
private:
ui::controls::FlexLayout children_container_;
ui::components::PopupMenuTextButton add_child_button_;
std::vector<std::unique_ptr<CompoundConditionEditorChild>> children_;
-
- Event<std::nullptr_t> change_event_;
};
class AndConditionEditor : public CompoundConditionEditor {
diff --git a/src/theme_builder/components/conditions/ConditionEditor.h b/src/theme_builder/components/conditions/ConditionEditor.h
index 08128ed1..426e6ba8 100644
--- a/src/theme_builder/components/conditions/ConditionEditor.h
+++ b/src/theme_builder/components/conditions/ConditionEditor.h
@@ -1,12 +1,12 @@
#pragma once
+#include "../Editor.h"
#include "cru/common/ClonablePtr.h"
-#include "cru/ui/components/Component.h"
#include "cru/ui/controls/FlexLayout.h"
#include "cru/ui/controls/TextBlock.h"
#include "cru/ui/style/Condition.h"
namespace cru::theme_builder::components::conditions {
-class ConditionEditor : public ui::components::Component {
+class ConditionEditor : public Editor {
public:
ConditionEditor();
~ConditionEditor() override;
@@ -20,7 +20,6 @@ class ConditionEditor : public ui::components::Component {
void SetLabel(String label) { label_.SetText(std::move(label)); }
virtual ClonablePtr<ui::style::Condition> GetCondition() = 0;
- virtual IEvent<std::nullptr_t>* ChangeEvent() = 0;
private:
ui::controls::FlexLayout container_;
diff --git a/src/theme_builder/components/conditions/FocusConditionEditor.cpp b/src/theme_builder/components/conditions/FocusConditionEditor.cpp
index 7e650071..1fb99d64 100644
--- a/src/theme_builder/components/conditions/FocusConditionEditor.cpp
+++ b/src/theme_builder/components/conditions/FocusConditionEditor.cpp
@@ -8,8 +8,8 @@ FocusConditionEditor::FocusConditionEditor() {
GetContainer()->AddChild(focus_check_box_.GetRootControl());
focus_check_box_.SetLabel(u"Focus");
- focus_check_box_.ChangeEvent()->AddSpyOnlyHandler(
- [this] { change_event_.Raise(nullptr); });
+
+ ConnectChangeEvent(focus_check_box_);
}
FocusConditionEditor::~FocusConditionEditor() {}
diff --git a/src/theme_builder/components/conditions/FocusConditionEditor.h b/src/theme_builder/components/conditions/FocusConditionEditor.h
index 06cdcf69..1faf4d7d 100644
--- a/src/theme_builder/components/conditions/FocusConditionEditor.h
+++ b/src/theme_builder/components/conditions/FocusConditionEditor.h
@@ -22,11 +22,7 @@ class FocusConditionEditor : public ConditionEditor {
return GetValue();
}
- IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; }
-
private:
properties::CheckBoxPropertyEditor focus_check_box_;
-
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::conditions
diff --git a/src/theme_builder/components/conditions/NoConditionEditor.h b/src/theme_builder/components/conditions/NoConditionEditor.h
index da5f99b0..19616319 100644
--- a/src/theme_builder/components/conditions/NoConditionEditor.h
+++ b/src/theme_builder/components/conditions/NoConditionEditor.h
@@ -13,10 +13,5 @@ class NoConditionEditor : public ConditionEditor {
ClonablePtr<ui::style::Condition> GetCondition() override {
return ui::style::NoCondition::Create();
}
-
- IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; }
-
- private:
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::conditions
diff --git a/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp
index 3b96b716..fb6f4705 100644
--- a/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp
+++ b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp
@@ -6,19 +6,14 @@ CheckBoxPropertyEditor::CheckBoxPropertyEditor() {
container_.AddChild(&label_);
container_.AddChild(&check_box_);
- check_box_.CheckedChangeEvent()->AddSpyOnlyHandler([this] {
- if (!suppress_next_change_event_) {
- change_event_.Raise(nullptr);
- } else {
- suppress_next_change_event_ = false;
- }
- });
+ check_box_.CheckedChangeEvent()->AddSpyOnlyHandler(
+ [this] { RaiseChangeEvent(); });
}
CheckBoxPropertyEditor::~CheckBoxPropertyEditor() {}
void CheckBoxPropertyEditor::SetValue(bool value, bool trigger_change) {
- if (!trigger_change) suppress_next_change_event_ = true;
+ if (!trigger_change) SuppressNextChangeEvent();
check_box_.SetChecked(value);
}
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/CheckBoxPropertyEditor.h b/src/theme_builder/components/properties/CheckBoxPropertyEditor.h
index 07ac4fe0..f78ed6c9 100644
--- a/src/theme_builder/components/properties/CheckBoxPropertyEditor.h
+++ b/src/theme_builder/components/properties/CheckBoxPropertyEditor.h
@@ -1,12 +1,11 @@
#pragma once
-#include "cru/ui/components/Component.h"
+#include "../Editor.h"
#include "cru/ui/controls/CheckBox.h"
-#include "cru/ui/controls/Control.h"
#include "cru/ui/controls/FlexLayout.h"
#include "cru/ui/controls/TextBlock.h"
namespace cru::theme_builder::components::properties {
-class CheckBoxPropertyEditor : public ui::components::Component {
+class CheckBoxPropertyEditor : public Editor {
public:
using PropertyType = bool;
@@ -22,14 +21,9 @@ class CheckBoxPropertyEditor : public ui::components::Component {
bool GetValue() const { return check_box_.IsChecked(); }
void SetValue(bool value, bool trigger_change = true);
- IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; }
-
private:
ui::controls::FlexLayout container_;
ui::controls::TextBlock label_;
ui::controls::CheckBox check_box_;
-
- bool suppress_next_change_event_ = false;
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/ColorPropertyEditor.cpp b/src/theme_builder/components/properties/ColorPropertyEditor.cpp
index d6577abb..49911f77 100644
--- a/src/theme_builder/components/properties/ColorPropertyEditor.cpp
+++ b/src/theme_builder/components/properties/ColorPropertyEditor.cpp
@@ -21,7 +21,7 @@ ColorPropertyEditor::ColorPropertyEditor() {
color_ = *color;
color_cube_brush_->SetColor(*color);
is_color_text_valid_ = true;
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
} else {
is_color_text_valid_ = false;
// TODO: Show error!
@@ -33,9 +33,7 @@ ColorPropertyEditor::~ColorPropertyEditor() {}
void ColorPropertyEditor::SetValue(const ui::Color &color,
bool trigger_change) {
- color_cube_brush_->SetColor(color);
+ if (!trigger_change) SuppressNextChangeEvent();
color_text_.SetText(color.ToString());
- is_color_text_valid_ = true;
- if (trigger_change) change_event_.Raise(nullptr);
}
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/ColorPropertyEditor.h b/src/theme_builder/components/properties/ColorPropertyEditor.h
index 3265e8e9..aa6cfcfa 100644
--- a/src/theme_builder/components/properties/ColorPropertyEditor.h
+++ b/src/theme_builder/components/properties/ColorPropertyEditor.h
@@ -1,13 +1,13 @@
#pragma once
+#include "../Editor.h"
#include "cru/platform/graphics/Base.h"
-#include "cru/ui/components/Component.h"
#include "cru/ui/controls/Container.h"
#include "cru/ui/controls/FlexLayout.h"
#include "cru/ui/controls/TextBlock.h"
#include "cru/ui/controls/TextBox.h"
namespace cru::theme_builder::components::properties {
-class ColorPropertyEditor : public ui::components::Component {
+class ColorPropertyEditor : public Editor {
public:
using PropertyType = ui::Color;
@@ -23,8 +23,6 @@ class ColorPropertyEditor : public ui::components::Component {
ui::Color GetValue() const { return color_; }
void SetValue(const ui::Color& color, bool trigger_change = true);
- IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; }
-
private:
ui::Color color_ = ui::colors::transparent;
@@ -34,7 +32,5 @@ class ColorPropertyEditor : public ui::components::Component {
std::shared_ptr<platform::graphics::ISolidColorBrush> color_cube_brush_;
ui::controls::TextBox color_text_;
bool is_color_text_valid_;
-
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp
index d124b8fe..91e2c614 100644
--- a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp
+++ b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp
@@ -1,4 +1,5 @@
#include "CornerRadiusPropertyEditor.h"
+#include "cru/ui/Base.h"
namespace cru::theme_builder::components::properties {
CornerRadiusPropertyEditor::CornerRadiusPropertyEditor() {
@@ -13,35 +14,26 @@ CornerRadiusPropertyEditor::CornerRadiusPropertyEditor() {
container_.AddChild(left_bottom_editor_.GetRootControl());
container_.AddChild(right_bottom_editor_.GetRootControl());
- left_top_editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) {
- corner_radius_.left_top = left_top_editor_.GetValue();
- change_event_.Raise(nullptr);
- });
-
- right_top_editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) {
- corner_radius_.right_top = left_top_editor_.GetValue();
- change_event_.Raise(nullptr);
- });
-
- left_bottom_editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) {
- corner_radius_.left_bottom = left_bottom_editor_.GetValue();
- change_event_.Raise(nullptr);
- });
-
- right_bottom_editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) {
- corner_radius_.right_bottom = right_bottom_editor_.GetValue();
- change_event_.Raise(nullptr);
- });
+ ConnectChangeEvent(left_top_editor_);
+ ConnectChangeEvent(right_top_editor_);
+ ConnectChangeEvent(left_bottom_editor_);
+ ConnectChangeEvent(right_bottom_editor_);
}
CornerRadiusPropertyEditor::~CornerRadiusPropertyEditor() {}
+ui::CornerRadius CornerRadiusPropertyEditor::GetValue() const {
+ return ui::CornerRadius(
+ left_top_editor_.GetValue(), right_top_editor_.GetValue(),
+ left_bottom_editor_.GetValue(), right_bottom_editor_.GetValue());
+}
+
void CornerRadiusPropertyEditor::SetValue(const ui::CornerRadius& corner_radius,
bool trigger_change) {
left_top_editor_.SetValue(corner_radius.left_top, false);
right_top_editor_.SetValue(corner_radius.right_top, false);
left_bottom_editor_.SetValue(corner_radius.left_bottom, false);
right_bottom_editor_.SetValue(corner_radius.right_bottom, false);
- if (trigger_change) change_event_.Raise(nullptr);
+ if (trigger_change) RaiseChangeEvent();
}
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h
index 06e1f024..6b6833d1 100644
--- a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h
+++ b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h
@@ -1,11 +1,11 @@
#pragma once
+#include "../Editor.h"
#include "PointPropertyEditor.h"
#include "cru/ui/Base.h"
-#include "cru/ui/components/Component.h"
#include "cru/ui/controls/FlexLayout.h"
namespace cru::theme_builder::components::properties {
-class CornerRadiusPropertyEditor : public ui::components::Component {
+class CornerRadiusPropertyEditor : public Editor {
public:
using PropertyType = ui::CornerRadius;
@@ -14,21 +14,15 @@ class CornerRadiusPropertyEditor : public ui::components::Component {
ui::controls::Control* GetRootControl() override { return &container_; }
- ui::CornerRadius GetValue() const { return corner_radius_; }
+ ui::CornerRadius GetValue() const;
void SetValue(const ui::CornerRadius& corner_radius,
bool trigger_change = true);
- IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; }
-
private:
- ui::CornerRadius corner_radius_;
-
ui::controls::FlexLayout container_;
PointPropertyEditor left_top_editor_;
PointPropertyEditor right_top_editor_;
PointPropertyEditor left_bottom_editor_;
PointPropertyEditor right_bottom_editor_;
-
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/OptionalPropertyEditor.h b/src/theme_builder/components/properties/OptionalPropertyEditor.h
index 4467d4de..d7362d50 100644
--- a/src/theme_builder/components/properties/OptionalPropertyEditor.h
+++ b/src/theme_builder/components/properties/OptionalPropertyEditor.h
@@ -1,5 +1,5 @@
#pragma once
-#include "cru/ui/components/Component.h"
+#include "../Editor.h"
#include "cru/ui/controls/CheckBox.h"
#include "cru/ui/controls/FlexLayout.h"
@@ -7,7 +7,7 @@
namespace cru::theme_builder::components::properties {
template <typename TEditor>
-class OptionalPropertyEditor : public ui::components::Component {
+class OptionalPropertyEditor : public Editor {
public:
using PropertyType = typename TEditor::PropertyType;
@@ -17,7 +17,7 @@ class OptionalPropertyEditor : public ui::components::Component {
editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) {
if (IsEnabled()) {
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
}
});
}
@@ -29,7 +29,7 @@ class OptionalPropertyEditor : public ui::components::Component {
void SetEnabled(bool enabled, bool trigger_change = true) {
check_box_.SetChecked(enabled);
if (trigger_change) {
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
}
}
@@ -42,7 +42,7 @@ class OptionalPropertyEditor : public ui::components::Component {
if (value) {
SetEnabled(true, false);
editor_.SetValue(*value, false);
- if (trigger_change) change_event_.Raise(nullptr);
+ if (trigger_change) RaiseChangeEvent();
} else {
SetEnabled(false, trigger_change);
}
@@ -50,13 +50,9 @@ class OptionalPropertyEditor : public ui::components::Component {
TEditor* GetEditor() { return &editor_; }
- IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; }
-
private:
ui::controls::FlexLayout container_;
ui::controls::CheckBox check_box_;
TEditor editor_;
-
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/PointPropertyEditor.cpp b/src/theme_builder/components/properties/PointPropertyEditor.cpp
index 60f3c06c..6d4277aa 100644
--- a/src/theme_builder/components/properties/PointPropertyEditor.cpp
+++ b/src/theme_builder/components/properties/PointPropertyEditor.cpp
@@ -9,21 +9,17 @@ PointPropertyEditor::PointPropertyEditor() {
container_.AddChild(&text_);
text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) {
- if (!suppress_next_change_event_) {
- auto text = text_.GetTextView();
- auto point_mapper =
- ui::mapper::MapperRegistry::GetInstance()->GetMapper<ui::Point>();
- try {
- auto point = point_mapper->MapFromString(text.ToString());
- point_ = point;
- is_text_valid_ = true;
- change_event_.Raise(nullptr);
- } catch (const Exception&) {
- is_text_valid_ = false;
- // TODO: Show error!
- }
- } else {
- suppress_next_change_event_ = false;
+ auto text = text_.GetTextView();
+ auto point_mapper =
+ ui::mapper::MapperRegistry::GetInstance()->GetMapper<ui::Point>();
+ try {
+ auto point = point_mapper->MapFromString(text.ToString());
+ point_ = point;
+ is_text_valid_ = true;
+ RaiseChangeEvent();
+ } catch (const Exception&) {
+ is_text_valid_ = false;
+ // TODO: Show error!
}
});
}
@@ -32,9 +28,7 @@ PointPropertyEditor::~PointPropertyEditor() {}
void PointPropertyEditor::SetValue(const ui::Point& point,
bool trigger_change) {
- point_ = point;
- is_text_valid_ = true;
- if (!trigger_change) suppress_next_change_event_ = true;
+ if (!trigger_change) SuppressNextChangeEvent();
text_.SetText(ConvertPointToString(point));
}
diff --git a/src/theme_builder/components/properties/PointPropertyEditor.h b/src/theme_builder/components/properties/PointPropertyEditor.h
index e4604c84..bd852e3a 100644
--- a/src/theme_builder/components/properties/PointPropertyEditor.h
+++ b/src/theme_builder/components/properties/PointPropertyEditor.h
@@ -1,11 +1,11 @@
#pragma once
-#include "cru/ui/components/Component.h"
+#include "../Editor.h"
#include "cru/ui/controls/FlexLayout.h"
#include "cru/ui/controls/TextBlock.h"
#include "cru/ui/controls/TextBox.h"
namespace cru::theme_builder::components::properties {
-class PointPropertyEditor : public ui::components::Component {
+class PointPropertyEditor : public Editor {
public:
using PropertyType = ui::Point;
@@ -21,8 +21,6 @@ class PointPropertyEditor : public ui::components::Component {
ui::Point GetValue() const { return point_; }
void SetValue(const ui::Point& point, bool trigger_change = true);
- IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; }
-
private:
static String ConvertPointToString(const ui::Point& point);
@@ -33,8 +31,5 @@ class PointPropertyEditor : public ui::components::Component {
ui::controls::TextBlock label_;
ui::controls::TextBox text_;
bool is_text_valid_;
-
- bool suppress_next_change_event_ = false;
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/SelectPropertyEditor.cpp b/src/theme_builder/components/properties/SelectPropertyEditor.cpp
index 243f6035..835b2d12 100644
--- a/src/theme_builder/components/properties/SelectPropertyEditor.cpp
+++ b/src/theme_builder/components/properties/SelectPropertyEditor.cpp
@@ -7,15 +7,9 @@ SelectPropertyEditor::SelectPropertyEditor() {
container_.AddChild(&label_);
container_.AddChild(select_.GetRootControl());
- select_.ItemSelectedEvent()->AddHandler([this](Index index) {
- if (!suppress_next_change_event_) {
- change_event_.Raise(nullptr);
- } else {
- suppress_next_change_event_ = false;
- }
- });
+ select_.ItemSelectedEvent()->AddHandler(
+ [this](Index index) { RaiseChangeEvent(); });
}
SelectPropertyEditor::~SelectPropertyEditor() {}
-
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/SelectPropertyEditor.h b/src/theme_builder/components/properties/SelectPropertyEditor.h
index a67cb80f..475d2d0a 100644
--- a/src/theme_builder/components/properties/SelectPropertyEditor.h
+++ b/src/theme_builder/components/properties/SelectPropertyEditor.h
@@ -1,11 +1,11 @@
#pragma once
-#include "cru/ui/components/Component.h"
+#include "../Editor.h"
#include "cru/ui/components/Select.h"
#include "cru/ui/controls/FlexLayout.h"
#include "cru/ui/controls/TextBlock.h"
namespace cru::theme_builder::components::properties {
-class SelectPropertyEditor : public ui::components::Component {
+class SelectPropertyEditor : public Editor {
public:
using PropertyType = Index;
@@ -20,7 +20,7 @@ class SelectPropertyEditor : public ui::components::Component {
Index GetSelectedIndex() const { return select_.GetSelectedIndex(); }
void SetSelectedIndex(Index index, bool trigger_change = true) {
- if (trigger_change == false) suppress_next_change_event_ = true;
+ if (trigger_change == false) SuppressNextChangeEvent();
select_.SetSelectedIndex(index);
}
@@ -34,14 +34,9 @@ class SelectPropertyEditor : public ui::components::Component {
SetSelectedIndex(value, trigger_change);
}
- IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; }
-
private:
ui::controls::FlexLayout container_;
ui::controls::TextBlock label_;
ui::components::Select select_;
-
- bool suppress_next_change_event_ = false;
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp b/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp
index c5e5f658..3e022bb1 100644
--- a/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp
+++ b/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp
@@ -8,14 +8,14 @@ ThicknessPropertyEditor::ThicknessPropertyEditor() {
container_.AddChild(&text_);
text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) {
- auto text = text_.GetTextView();
+ auto text = text_.GetText();
auto thickness_mapper =
ui::mapper::MapperRegistry::GetInstance()->GetMapper<ui::Thickness>();
try {
- auto thickness = thickness_mapper->MapFromString(text.ToString());
+ auto thickness = thickness_mapper->MapFromString(text);
thickness_ = thickness;
is_text_valid_ = true;
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
} catch (const Exception &) {
is_text_valid_ = false;
// TODO: Show error!
@@ -27,10 +27,8 @@ ThicknessPropertyEditor::~ThicknessPropertyEditor() {}
void ThicknessPropertyEditor::SetValue(const ui::Thickness &thickness,
bool trigger_change) {
- thickness_ = thickness;
- text_.SetText(Format(u"{} {} {} {}", thickness_.left, thickness_.top,
- thickness_.right, thickness_.bottom));
- is_text_valid_ = true;
- if (trigger_change) change_event_.Raise(nullptr);
+ if (!trigger_change) SuppressNextChangeEvent();
+ text_.SetText(Format(u"{} {} {} {}", thickness.left, thickness.top,
+ thickness.right, thickness.bottom));
}
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/ThicknessPropertyEditor.h b/src/theme_builder/components/properties/ThicknessPropertyEditor.h
index 87b160c6..cea9ae9d 100644
--- a/src/theme_builder/components/properties/ThicknessPropertyEditor.h
+++ b/src/theme_builder/components/properties/ThicknessPropertyEditor.h
@@ -1,11 +1,11 @@
#pragma once
-#include "cru/ui/components/Component.h"
+#include "../Editor.h"
#include "cru/ui/controls/FlexLayout.h"
#include "cru/ui/controls/TextBlock.h"
#include "cru/ui/controls/TextBox.h"
namespace cru::theme_builder::components::properties {
-class ThicknessPropertyEditor : public ui::components::Component {
+class ThicknessPropertyEditor : public Editor {
public:
using PropertyType = ui::Thickness;
@@ -20,8 +20,6 @@ class ThicknessPropertyEditor : public ui::components::Component {
ui::Thickness GetValue() const { return thickness_; }
void SetValue(const ui::Thickness& thickness, bool trigger_change = true);
- IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; }
-
private:
ui::Thickness thickness_;
@@ -29,7 +27,5 @@ class ThicknessPropertyEditor : public ui::components::Component {
ui::controls::TextBlock label_;
ui::controls::TextBox text_;
bool is_text_valid_;
-
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/stylers/BorderStylerEditor.cpp b/src/theme_builder/components/stylers/BorderStylerEditor.cpp
index 2b169dcf..b2522786 100644
--- a/src/theme_builder/components/stylers/BorderStylerEditor.cpp
+++ b/src/theme_builder/components/stylers/BorderStylerEditor.cpp
@@ -15,16 +15,11 @@ BorderStylerEditor::BorderStylerEditor() {
GetContainer()->AddChild(foreground_brush_editor_.GetRootControl());
GetContainer()->AddChild(background_brush_editor_.GetRootControl());
- auto connect = [this](IEvent<std::nullptr_t>* event) {
- event->AddHandler(
- [this](std::nullptr_t) { this->change_event_.Raise(nullptr); });
- };
-
- connect(corner_radius_editor_.ChangeEvent());
- connect(thickness_editor_.ChangeEvent());
- connect(brush_editor_.ChangeEvent());
- connect(foreground_brush_editor_.ChangeEvent());
- connect(background_brush_editor_.ChangeEvent());
+ ConnectChangeEvent(corner_radius_editor_);
+ ConnectChangeEvent(thickness_editor_);
+ ConnectChangeEvent(brush_editor_);
+ ConnectChangeEvent(foreground_brush_editor_);
+ ConnectChangeEvent(background_brush_editor_);
}
BorderStylerEditor::~BorderStylerEditor() {}
@@ -93,7 +88,7 @@ void BorderStylerEditor::SetValue(ui::style::BorderStyler* styler,
}
if (trigger_change) {
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
}
}
diff --git a/src/theme_builder/components/stylers/BorderStylerEditor.h b/src/theme_builder/components/stylers/BorderStylerEditor.h
index ec871775..539262d6 100644
--- a/src/theme_builder/components/stylers/BorderStylerEditor.h
+++ b/src/theme_builder/components/stylers/BorderStylerEditor.h
@@ -21,8 +21,6 @@ class BorderStylerEditor : public StylerEditor {
ClonablePtr<ui::style::Styler> GetStyler() override { return GetValue(); }
- IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; }
-
private:
properties::OptionalPropertyEditor<properties::CornerRadiusPropertyEditor>
corner_radius_editor_;
@@ -34,7 +32,5 @@ class BorderStylerEditor : public StylerEditor {
foreground_brush_editor_;
properties::OptionalPropertyEditor<properties::ColorPropertyEditor>
background_brush_editor_;
-
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::stylers
diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp
index 568c34f3..ac1cc0ea 100644
--- a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp
+++ b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp
@@ -12,7 +12,7 @@ CompoundStylerEditorChild::CompoundStylerEditorChild(
container_.AddChild(&remove_button_);
remove_button_.SetChild(&remove_button_text_);
- remove_button_text_.SetText(u"-");
+ remove_button_text_.SetText(u"X");
container_.AddChild(styler_editor_->GetRootControl());
@@ -49,17 +49,18 @@ CompoundStylerEditor::CompoundStylerEditor() {
break;
}
if (editor) {
+ ConnectChangeEvent(editor.get());
auto child =
std::make_unique<CompoundStylerEditorChild>(std::move(editor));
child->RemoveEvent()->AddSpyOnlyHandler([this, c = child.get()] {
auto index = this->children_container_.IndexOf(c->GetRootControl());
this->children_.erase(this->children_.begin() + index);
this->children_container_.RemoveChildAt(index);
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
});
children_container_.AddChild(child->GetRootControl());
children_.push_back(std::move(child));
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
}
});
}
@@ -80,18 +81,16 @@ void CompoundStylerEditor::SetValue(ui::style::CompoundStyler* value,
children_container_.ClearChildren();
for (const auto& styler : value->GetChildren()) {
auto editor = CreateStylerEditor(styler.get());
- if (editor) {
- auto child =
- std::make_unique<CompoundStylerEditorChild>(std::move(editor));
- child->RemoveEvent()->AddSpyOnlyHandler([this, c = child.get()] {
- auto index = this->children_container_.IndexOf(c->GetRootControl());
- this->children_.erase(this->children_.begin() + index);
- this->children_container_.RemoveChildAt(index);
- change_event_.Raise(nullptr);
- });
- children_.push_back(std::move(child));
- children_container_.AddChild(children_.back()->GetRootControl());
- }
+ ConnectChangeEvent(editor.get());
+ auto child = std::make_unique<CompoundStylerEditorChild>(std::move(editor));
+ child->RemoveEvent()->AddSpyOnlyHandler([this, c = child.get()] {
+ auto index = this->children_container_.IndexOf(c->GetRootControl());
+ this->children_.erase(this->children_.begin() + index);
+ this->children_container_.RemoveChildAt(index);
+ RaiseChangeEvent();
+ });
+ children_.push_back(std::move(child));
+ children_container_.AddChild(children_.back()->GetRootControl());
}
}
} // namespace cru::theme_builder::components::stylers
diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.h b/src/theme_builder/components/stylers/CompoundStylerEditor.h
index a5c6fbb2..33a3d7cf 100644
--- a/src/theme_builder/components/stylers/CompoundStylerEditor.h
+++ b/src/theme_builder/components/stylers/CompoundStylerEditor.h
@@ -42,13 +42,9 @@ class CompoundStylerEditor : public StylerEditor {
ClonablePtr<ui::style::Styler> GetStyler() override { return GetValue(); }
- IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; }
-
private:
ui::controls::FlexLayout children_container_;
std::vector<std::unique_ptr<CompoundStylerEditorChild>> children_;
ui::components::PopupMenuTextButton add_child_button_;
-
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::stylers
diff --git a/src/theme_builder/components/stylers/CursorStylerEditor.cpp b/src/theme_builder/components/stylers/CursorStylerEditor.cpp
index d7e5c351..9984d81a 100644
--- a/src/theme_builder/components/stylers/CursorStylerEditor.cpp
+++ b/src/theme_builder/components/stylers/CursorStylerEditor.cpp
@@ -10,6 +10,8 @@ CursorStylerEditor::CursorStylerEditor() {
cursor_select_.SetLabel(u"Cursor");
cursor_select_.SetItems({u"arrow", u"hand", u"ibeam"});
cursor_select_.SetSelectedIndex(0);
+
+ ConnectChangeEvent(cursor_select_);
}
CursorStylerEditor::~CursorStylerEditor() {}
@@ -57,7 +59,7 @@ void CursorStylerEditor::SetValue(ui::style::CursorStyler* styler,
}
if (trigger_change) {
- change_event_.Raise(nullptr);
+ RaiseChangeEvent();
}
}
} // namespace cru::theme_builder::components::stylers
diff --git a/src/theme_builder/components/stylers/CursorStylerEditor.h b/src/theme_builder/components/stylers/CursorStylerEditor.h
index 5c443819..552619a0 100644
--- a/src/theme_builder/components/stylers/CursorStylerEditor.h
+++ b/src/theme_builder/components/stylers/CursorStylerEditor.h
@@ -18,11 +18,7 @@ class CursorStylerEditor : public StylerEditor {
ClonablePtr<ui::style::Styler> GetStyler() override { return GetValue(); }
- IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; }
-
private:
properties::SelectPropertyEditor cursor_select_;
-
- Event<std::nullptr_t> change_event_;
};
} // namespace cru::theme_builder::components::stylers
diff --git a/src/theme_builder/components/stylers/StylerEditor.h b/src/theme_builder/components/stylers/StylerEditor.h
index b3e0d287..02005481 100644
--- a/src/theme_builder/components/stylers/StylerEditor.h
+++ b/src/theme_builder/components/stylers/StylerEditor.h
@@ -1,11 +1,11 @@
#pragma once
-#include "cru/ui/components/Component.h"
+#include "../Editor.h"
#include "cru/ui/controls/FlexLayout.h"
#include "cru/ui/controls/TextBlock.h"
#include "cru/ui/style/Styler.h"
namespace cru::theme_builder::components::stylers {
-class StylerEditor : public ui::components::Component {
+class StylerEditor : public Editor {
public:
StylerEditor();
~StylerEditor() override;
@@ -19,7 +19,6 @@ class StylerEditor : public ui::components::Component {
void SetLabel(String label) { label_.SetText(std::move(label)); }
virtual ClonablePtr<ui::style::Styler> GetStyler() = 0;
- virtual IEvent<std::nullptr_t>* ChangeEvent() = 0;
private:
ui::controls::FlexLayout container_;