aboutsummaryrefslogtreecommitdiff
path: root/src/theme_builder/components/conditions
diff options
context:
space:
mode:
Diffstat (limited to 'src/theme_builder/components/conditions')
-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
4 files changed, 11 insertions, 87 deletions
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(