diff options
Diffstat (limited to 'src/theme_builder/components/stylers')
4 files changed, 10 insertions, 81 deletions
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); |