aboutsummaryrefslogtreecommitdiff
path: root/src/theme_builder
diff options
context:
space:
mode:
Diffstat (limited to 'src/theme_builder')
-rw-r--r--src/theme_builder/CMakeLists.txt1
-rw-r--r--src/theme_builder/components/HeadBodyEditor.cpp30
-rw-r--r--src/theme_builder/components/HeadBodyEditor.h36
-rw-r--r--src/theme_builder/components/conditions/CompoundConditionEditor.cpp40
-rw-r--r--src/theme_builder/components/conditions/CompoundConditionEditor.h23
-rw-r--r--src/theme_builder/components/conditions/ConditionEditor.cpp12
-rw-r--r--src/theme_builder/components/conditions/ConditionEditor.h23
-rw-r--r--src/theme_builder/components/stylers/CompoundStylerEditor.cpp36
-rw-r--r--src/theme_builder/components/stylers/CompoundStylerEditor.h22
-rw-r--r--src/theme_builder/components/stylers/StylerEditor.cpp11
-rw-r--r--src/theme_builder/components/stylers/StylerEditor.h22
11 files changed, 88 insertions, 168 deletions
diff --git a/src/theme_builder/CMakeLists.txt b/src/theme_builder/CMakeLists.txt
index 94de566e..ed9029f0 100644
--- a/src/theme_builder/CMakeLists.txt
+++ b/src/theme_builder/CMakeLists.txt
@@ -2,6 +2,7 @@ add_executable(cru_theme_builder
main.cpp
components/Common.cpp
components/Editor.cpp
+ components/HeadBodyEditor.cpp
components/MainWindow.cpp
components/StyleRuleEditor.cpp
components/StyleRuleSetEditor.cpp
diff --git a/src/theme_builder/components/HeadBodyEditor.cpp b/src/theme_builder/components/HeadBodyEditor.cpp
new file mode 100644
index 00000000..6d7ace66
--- /dev/null
+++ b/src/theme_builder/components/HeadBodyEditor.cpp
@@ -0,0 +1,30 @@
+#include "HeadBodyEditor.h"
+#include "Common.h"
+#include "cru/ui/ThemeManager.h"
+#include "cru/ui/controls/FlexLayout.h"
+
+namespace cru::theme_builder::components {
+HeadBodyEditor::HeadBodyEditor() {
+ border_.SetChild(&container_);
+ border_.SetBackgroundBrush(CreateRandomEditorBackgroundBrush());
+
+ container_.SetFlexDirection(ui::controls::FlexDirection::Vertical);
+ container_.AddChild(&head_container_);
+ container_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Stretch);
+ head_container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal);
+ head_container_.AddChild(&label_);
+
+ remove_button_.GetStyleRuleSet()->SetParent(
+ ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet(
+ u"cru.theme_builder.icon-button.style"));
+ remove_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.close",
+ {0, 0, 16, 16});
+ remove_button_.SetIconFillColor(ui::colors::red);
+ head_container_.AddChild(&remove_button_);
+
+ remove_button_.ClickEvent()->AddSpyOnlyHandler(
+ [this] { remove_event_.Raise(nullptr); });
+}
+
+HeadBodyEditor::~HeadBodyEditor() {}
+} // namespace cru::theme_builder::components
diff --git a/src/theme_builder/components/HeadBodyEditor.h b/src/theme_builder/components/HeadBodyEditor.h
new file mode 100644
index 00000000..8119724f
--- /dev/null
+++ b/src/theme_builder/components/HeadBodyEditor.h
@@ -0,0 +1,36 @@
+#pragma once
+#include "Editor.h"
+#include "cru/common/Event.h"
+#include "cru/ui/controls/Container.h"
+#include "cru/ui/controls/FlexLayout.h"
+#include "cru/ui/controls/IconButton.h"
+#include "cru/ui/controls/TextBlock.h"
+#include "cru/ui/style/Styler.h"
+
+namespace cru::theme_builder::components {
+class HeadBodyEditor : public Editor {
+ public:
+ HeadBodyEditor();
+ ~HeadBodyEditor() override;
+
+ public:
+ ui::controls::Control* GetRootControl() override { return &border_; }
+
+ ui::controls::FlexLayout* GetContainer() { return &container_; }
+ ui::controls::FlexLayout* GetHeadContainer() { return &head_container_; }
+
+ String GetLabel() const { return label_.GetText(); }
+ void SetLabel(String label) { label_.SetText(std::move(label)); }
+
+ IEvent<std::nullptr_t>* RemoveEvent() { return &remove_event_; }
+
+ private:
+ ui::controls::Container border_;
+ ui::controls::FlexLayout container_;
+ ui::controls::FlexLayout head_container_;
+ ui::controls::TextBlock label_;
+ ui::controls::IconButton remove_button_;
+
+ Event<std::nullptr_t> remove_event_;
+};
+} // namespace cru::theme_builder::components
diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp
index 1e149789..69b8ed02 100644
--- a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp
+++ b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp
@@ -12,28 +12,6 @@
#include "cru/ui/style/Condition.h"
namespace cru::theme_builder::components::conditions {
-CompoundConditionEditorChild::CompoundConditionEditorChild(
- std::unique_ptr<ConditionEditor>&& condition_editor)
- : condition_editor_(std::move(condition_editor)) {
- container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal);
- container_.AddChild(&remove_button_);
-
- remove_button_.GetStyleRuleSet()->SetParent(
- ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet(
- u"cru.theme_builder.icon-button.style"));
- remove_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.close",
- {0, 0, 16, 16});
- remove_button_.SetPreferredSize({24, 24});
- remove_button_.SetPadding(ui::Thickness(2));
- remove_button_.SetIconFillColor(ui::colors::red);
-
- container_.AddChild(condition_editor_->GetRootControl());
-
- remove_button_.ClickEvent()->AddSpyOnlyHandler(
- [this] { this->remove_event_.Raise(nullptr); });
-}
-
-CompoundConditionEditorChild::~CompoundConditionEditorChild() {}
CompoundConditionEditor::CompoundConditionEditor() {
SetLabel(u"Compound Condition");
@@ -83,15 +61,13 @@ CompoundConditionEditor::CompoundConditionEditor() {
}
if (editor) {
ConnectChangeEvent(editor.get());
- auto child =
- std::make_unique<CompoundConditionEditorChild>(std::move(editor));
- child->RemoveEvent()->AddSpyOnlyHandler([this, c = child.get()] {
+ editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.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_.push_back(std::move(editor));
children_container_.AddChild(children_.back()->GetRootControl());
RaiseChangeEvent();
}
@@ -104,7 +80,7 @@ std::vector<ClonablePtr<ui::style::Condition>>
CompoundConditionEditor::GetChildren() {
std::vector<ClonablePtr<ui::style::Condition>> children;
for (auto& child : children_) {
- children.push_back(child->GetConditionEditor()->GetCondition());
+ children.push_back(child->GetCondition());
}
return children;
}
@@ -115,17 +91,15 @@ void CompoundConditionEditor::SetChildren(
children_container_.ClearChildren();
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 editor = CreateConditionEditor(condition.get());
+ ConnectChangeEvent(editor.get());
+ editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.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_.push_back(std::move(editor));
children_container_.AddChild(children_.back()->GetRootControl());
}
if (trigger_change) {
diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.h b/src/theme_builder/components/conditions/CompoundConditionEditor.h
index f80896c8..9732d533 100644
--- a/src/theme_builder/components/conditions/CompoundConditionEditor.h
+++ b/src/theme_builder/components/conditions/CompoundConditionEditor.h
@@ -10,27 +10,6 @@
#include "cru/ui/style/Condition.h"
namespace cru::theme_builder::components::conditions {
-class CompoundConditionEditorChild : public ui::components::Component {
- public:
- explicit CompoundConditionEditorChild(
- std::unique_ptr<ConditionEditor>&& editor);
- ~CompoundConditionEditorChild() override;
-
- public:
- ui::controls::Control* GetRootControl() override { return &container_; }
-
- ConditionEditor* GetConditionEditor() { return condition_editor_.get(); }
-
- IEvent<std::nullptr_t>* RemoveEvent() { return &remove_event_; }
-
- private:
- ui::controls::FlexLayout container_;
- ui::controls::IconButton remove_button_;
- std::unique_ptr<ConditionEditor> condition_editor_;
-
- Event<std::nullptr_t> remove_event_;
-};
-
class CompoundConditionEditor : public ConditionEditor {
public:
CompoundConditionEditor();
@@ -44,7 +23,7 @@ class CompoundConditionEditor : public ConditionEditor {
private:
ui::components::PopupMenuIconButton add_child_button_;
ui::controls::FlexLayout children_container_;
- std::vector<std::unique_ptr<CompoundConditionEditorChild>> children_;
+ std::vector<std::unique_ptr<ConditionEditor>> children_;
};
class AndConditionEditor : public CompoundConditionEditor {
diff --git a/src/theme_builder/components/conditions/ConditionEditor.cpp b/src/theme_builder/components/conditions/ConditionEditor.cpp
index 0f842fa8..5b79c639 100644
--- a/src/theme_builder/components/conditions/ConditionEditor.cpp
+++ b/src/theme_builder/components/conditions/ConditionEditor.cpp
@@ -9,17 +9,7 @@
#include "cru/ui/controls/FlexLayout.h"
namespace cru::theme_builder::components::conditions {
-ConditionEditor::ConditionEditor() {
- border_.SetChild(&container_);
- border_.SetBackgroundBrush(CreateRandomEditorBackgroundBrush());
-
- container_.SetFlexDirection(ui::controls::FlexDirection::Vertical);
- container_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start);
- container_.AddChild(&head_container_);
-
- head_container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal);
- head_container_.AddChild(&label_);
-}
+ConditionEditor::ConditionEditor() {}
ConditionEditor::~ConditionEditor() {}
diff --git a/src/theme_builder/components/conditions/ConditionEditor.h b/src/theme_builder/components/conditions/ConditionEditor.h
index eea76972..f20132f6 100644
--- a/src/theme_builder/components/conditions/ConditionEditor.h
+++ b/src/theme_builder/components/conditions/ConditionEditor.h
@@ -1,34 +1,15 @@
#pragma once
-#include "../Editor.h"
-#include "cru/common/ClonablePtr.h"
-#include "cru/ui/controls/Container.h"
-#include "cru/ui/controls/FlexLayout.h"
-#include "cru/ui/controls/TextBlock.h"
+#include "../HeadBodyEditor.h"
#include "cru/ui/style/Condition.h"
namespace cru::theme_builder::components::conditions {
-class ConditionEditor : public Editor {
+class ConditionEditor : public HeadBodyEditor {
public:
ConditionEditor();
~ConditionEditor() override;
public:
- ui::controls::Control* GetRootControl() override { return &border_; }
-
- ui::controls::FlexLayout* GetContainer() { return &container_; }
-
- ui::controls::FlexLayout* GetHeadContainer() { return &head_container_; }
-
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
-
virtual ClonablePtr<ui::style::Condition> GetCondition() = 0;
-
- private:
- ui::controls::Container border_;
- ui::controls::FlexLayout container_;
- ui::controls::FlexLayout head_container_;
- ui::controls::TextBlock label_;
};
std::unique_ptr<ConditionEditor> CreateConditionEditor(
diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp
index f96a9a8f..6b8a5033 100644
--- a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp
+++ b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp
@@ -11,27 +11,6 @@
#include "cru/ui/style/Styler.h"
namespace cru::theme_builder::components::stylers {
-CompoundStylerEditorChild::CompoundStylerEditorChild(
- std::unique_ptr<StylerEditor>&& editor)
- : styler_editor_(std::move(editor)) {
- container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal);
- container_.AddChild(&remove_button_);
-
- remove_button_.GetStyleRuleSet()->SetParent(
- ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet(
- u"cru.theme_builder.icon-button.style"));
- remove_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.close",
- {0, 0, 16, 16});
- remove_button_.SetIconFillColor(ui::colors::red);
-
- container_.AddChild(styler_editor_->GetRootControl());
-
- remove_button_.ClickEvent()->AddSpyOnlyHandler(
- [this] { this->remove_event_.Raise(nullptr); });
-}
-
-CompoundStylerEditorChild::~CompoundStylerEditorChild() {}
-
CompoundStylerEditor::CompoundStylerEditor() {
SetLabel(u"Compound Styler");
GetContainer()->AddChild(&children_container_);
@@ -84,16 +63,14 @@ CompoundStylerEditor::CompoundStylerEditor() {
}
if (editor) {
ConnectChangeEvent(editor.get());
- auto child =
- std::make_unique<CompoundStylerEditorChild>(std::move(editor));
- child->RemoveEvent()->AddSpyOnlyHandler([this, c = child.get()] {
+ editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.get()] {
auto index = this->children_container_.IndexOf(c->GetRootControl());
this->children_.erase(this->children_.begin() + index);
this->children_container_.RemoveChildAt(index);
RaiseChangeEvent();
});
- children_container_.AddChild(child->GetRootControl());
- children_.push_back(std::move(child));
+ children_.push_back(std::move(editor));
+ children_container_.AddChild(editor->GetRootControl());
RaiseChangeEvent();
}
});
@@ -104,7 +81,7 @@ CompoundStylerEditor::~CompoundStylerEditor() {}
ClonablePtr<ui::style::CompoundStyler> CompoundStylerEditor::GetValue() {
std::vector<ClonablePtr<ui::style::Styler>> children_styler;
for (auto& child : children_) {
- children_styler.push_back(child->GetStylerEditor()->GetStyler());
+ children_styler.push_back(child->GetStyler());
}
return ui::style::CompoundStyler::Create(std::move(children_styler));
}
@@ -115,14 +92,13 @@ void CompoundStylerEditor::SetValue(ui::style::CompoundStyler* value,
for (const auto& styler : value->GetChildren()) {
auto editor = CreateStylerEditor(styler.get());
ConnectChangeEvent(editor.get());
- auto child = std::make_unique<CompoundStylerEditorChild>(std::move(editor));
- child->RemoveEvent()->AddSpyOnlyHandler([this, c = child.get()] {
+ editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.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_.push_back(std::move(editor));
children_container_.AddChild(children_.back()->GetRootControl());
}
}
diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.h b/src/theme_builder/components/stylers/CompoundStylerEditor.h
index fe9fb47c..a056e45c 100644
--- a/src/theme_builder/components/stylers/CompoundStylerEditor.h
+++ b/src/theme_builder/components/stylers/CompoundStylerEditor.h
@@ -6,26 +6,6 @@
#include "cru/ui/style/Styler.h"
namespace cru::theme_builder::components::stylers {
-class CompoundStylerEditorChild : public ui::components::Component {
- public:
- explicit CompoundStylerEditorChild(std::unique_ptr<StylerEditor>&& editor);
- ~CompoundStylerEditorChild() override;
-
- public:
- ui::controls::Control* GetRootControl() override { return &container_; }
-
- StylerEditor* GetStylerEditor() { return styler_editor_.get(); }
-
- IEvent<std::nullptr_t>* RemoveEvent() { return &remove_event_; }
-
- private:
- ui::controls::FlexLayout container_;
- ui::controls::IconButton remove_button_;
- std::unique_ptr<StylerEditor> styler_editor_;
-
- Event<std::nullptr_t> remove_event_;
-};
-
class CompoundStylerEditor : public StylerEditor {
public:
CompoundStylerEditor();
@@ -43,7 +23,7 @@ class CompoundStylerEditor : public StylerEditor {
private:
ui::controls::FlexLayout children_container_;
- std::vector<std::unique_ptr<CompoundStylerEditorChild>> children_;
+ std::vector<std::unique_ptr<StylerEditor>> children_;
ui::components::PopupMenuIconButton add_child_button_;
};
} // namespace cru::theme_builder::components::stylers
diff --git a/src/theme_builder/components/stylers/StylerEditor.cpp b/src/theme_builder/components/stylers/StylerEditor.cpp
index 662e5a08..0348adbd 100644
--- a/src/theme_builder/components/stylers/StylerEditor.cpp
+++ b/src/theme_builder/components/stylers/StylerEditor.cpp
@@ -13,16 +13,7 @@
#include "cru/ui/style/Styler.h"
namespace cru::theme_builder::components::stylers {
-StylerEditor::StylerEditor() {
- border_.SetChild(&container_);
- border_.SetBackgroundBrush(CreateRandomEditorBackgroundBrush());
-
- container_.SetFlexDirection(ui::controls::FlexDirection::Vertical);
- container_.AddChild(&head_container_);
- container_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start);
- head_container_.SetFlexDirection(ui::render::FlexDirection::Horizontal);
- head_container_.AddChild(&label_);
-}
+StylerEditor::StylerEditor() {}
StylerEditor::~StylerEditor() {}
diff --git a/src/theme_builder/components/stylers/StylerEditor.h b/src/theme_builder/components/stylers/StylerEditor.h
index 3cbcb5a5..8aa52bda 100644
--- a/src/theme_builder/components/stylers/StylerEditor.h
+++ b/src/theme_builder/components/stylers/StylerEditor.h
@@ -1,33 +1,15 @@
#pragma once
-#include "../Editor.h"
-#include "cru/ui/controls/Container.h"
-#include "cru/ui/controls/FlexLayout.h"
-#include "cru/ui/controls/TextBlock.h"
+#include "../HeadBodyEditor.h"
#include "cru/ui/style/Styler.h"
namespace cru::theme_builder::components::stylers {
-class StylerEditor : public Editor {
+class StylerEditor : public HeadBodyEditor {
public:
StylerEditor();
~StylerEditor() override;
public:
- ui::controls::Control* GetRootControl() override { return &border_; }
-
- ui::controls::FlexLayout* GetContainer() { return &container_; }
-
- ui::controls::FlexLayout* GetHeadContainer() { return &head_container_; }
-
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
-
virtual ClonablePtr<ui::style::Styler> GetStyler() = 0;
-
- private:
- ui::controls::Container border_;
- ui::controls::FlexLayout container_;
- ui::controls::FlexLayout head_container_;
- ui::controls::TextBlock label_;
};
std::unique_ptr<StylerEditor> CreateStylerEditor(ui::style::Styler* styler);