From 34a64e6ffefaab007578932ddbab931a25f1d56e Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 15 May 2022 14:15:31 +0800 Subject: ... --- src/ThemeBuilder/components/StyleRuleEditor.cpp | 62 +++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/ThemeBuilder/components/StyleRuleEditor.cpp (limited to 'src/ThemeBuilder/components/StyleRuleEditor.cpp') diff --git a/src/ThemeBuilder/components/StyleRuleEditor.cpp b/src/ThemeBuilder/components/StyleRuleEditor.cpp new file mode 100644 index 00000000..dcb33184 --- /dev/null +++ b/src/ThemeBuilder/components/StyleRuleEditor.cpp @@ -0,0 +1,62 @@ +#include "StyleRuleEditor.h" +#include "Common.h" +#include "conditions/ConditionEditor.h" +#include "cru/ui/ThemeManager.h" +#include "cru/ui/style/StyleRule.h" + +namespace cru::theme_builder::components { +StyleRuleEditor::StyleRuleEditor() { + container_.SetChild(&main_layout_); + container_.SetBackgroundBrush(CreateRandomEditorBackgroundBrush()); + + main_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); + main_layout_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start); + + main_layout_.AddChild(&head_layout_); + + label_.SetText(u"Style Rule"); + head_layout_.AddChild(&label_); + head_layout_.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); + + main_layout_.AddChild(&body_layout_); + body_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); + body_layout_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start); + body_layout_.SetMargin({10, 0, 0, 0}); + + remove_button_.ClickEvent()->AddSpyOnlyHandler( + [this] { remove_event_.Raise(nullptr); }); +} + +StyleRuleEditor::~StyleRuleEditor() {} + +ui::style::StyleRule StyleRuleEditor::GetValue() const { + return ui::style::StyleRule(condition_editor_->GetCondition(), + styler_editor_->GetStyler()); +} + +void StyleRuleEditor::SetValue(const ui::style::StyleRule& style_rule, + bool trigger_change) { + body_layout_.ClearChildren(); + condition_editor_ = + components::conditions::CreateConditionEditor(style_rule.GetCondition()); + styler_editor_ = + components::stylers::CreateStylerEditor(style_rule.GetStyler()); + body_layout_.AddChild(condition_editor_->GetRootControl()); + body_layout_.AddChild(styler_editor_->GetRootControl()); + condition_editor_->ChangeEvent()->AddSpyOnlyHandler( + [this] { change_event_.Raise(nullptr); }); + styler_editor_->ChangeEvent()->AddSpyOnlyHandler( + [this] { change_event_.Raise(nullptr); }); + + if (trigger_change) { + change_event_.Raise(nullptr); + } +} +} // namespace cru::theme_builder::components -- cgit v1.2.3