From 2711b7032cafdc9bdbd6ae06db0325c91e6e7f63 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 16 Feb 2022 21:17:09 +0800 Subject: ... --- .../components/StyleRuleSetEditor.cpp | 43 +++++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'src/theme_builder/components/StyleRuleSetEditor.cpp') diff --git a/src/theme_builder/components/StyleRuleSetEditor.cpp b/src/theme_builder/components/StyleRuleSetEditor.cpp index 072b8307..57671776 100644 --- a/src/theme_builder/components/StyleRuleSetEditor.cpp +++ b/src/theme_builder/components/StyleRuleSetEditor.cpp @@ -1,17 +1,50 @@ #include "StyleRuleSetEditor.h" #include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/style/Condition.h" +#include "cru/ui/style/Styler.h" namespace cru::theme_builder { using namespace cru::ui::controls; -StyleRuleSetEditor::StyleRuleSetEditor() {} +StyleRuleSetEditor::StyleRuleSetEditor() { + container_.AddChild(&rules_layout_); + container_.AddChild(&add_button_); -StyleRuleSetEditor::~StyleRuleSetEditor() { main_layout_.RemoveFromParent(); } + add_button_.SetChild(&add_button_text_); + add_button_text_.SetText(u"+"); + + add_button_.ClickEvent()->AddSpyOnlyHandler([this] { + auto rule_set = ui::style::StyleRule(ui::style::AndCondition::Create({}), + ui::style::CompoundStyler::Create({})); + style_rule_set_->AddStyleRule(rule_set); + style_rule_editors_.push_back(std::make_unique()); + style_rule_editors_.back()->SetValue(rule_set); + rules_layout_.AddChild(style_rule_editors_.back()->GetRootControl()); + }); +} + +StyleRuleSetEditor::~StyleRuleSetEditor() { rules_layout_.RemoveFromParent(); } void StyleRuleSetEditor::BindStyleRuleSet( std::shared_ptr rule_set) { style_rule_set_ = std::move(rule_set); - UpdateView(); -} -void StyleRuleSetEditor::UpdateView() {} + rules_layout_.ClearChildren(); + style_rule_editors_.clear(); + + for (Index i = 0; i < style_rule_set_->GetSize(); ++i) { + const auto& rule = style_rule_set_->GetStyleRule(i); + auto style_rule_editor = std::make_unique(); + style_rule_editor->SetValue(rule, false); + style_rule_editor->RemoveEvent()->AddSpyOnlyHandler([this, i] { + style_rule_set_->RemoveStyleRule(i); + style_rule_editors_.erase(style_rule_editors_.begin() + i); + }); + style_rule_editor->ChangeEvent()->AddSpyOnlyHandler( + [this, i, editor = style_rule_editor.get()]() { + style_rule_set_->SetStyleRule(i, editor->GetValue()); + }); + style_rule_editors_.push_back(std::move(style_rule_editor)); + rules_layout_.AddChild(style_rule_editors_.back()->GetRootControl()); + } +} } // namespace cru::theme_builder -- cgit v1.2.3