diff options
Diffstat (limited to 'src/theme_builder')
15 files changed, 106 insertions, 29 deletions
diff --git a/src/theme_builder/components/MainWindow.cpp b/src/theme_builder/components/MainWindow.cpp index 91c093cc..59e2dae8 100644 --- a/src/theme_builder/components/MainWindow.cpp +++ b/src/theme_builder/components/MainWindow.cpp @@ -19,6 +19,10 @@ MainWindow::MainWindow() { preview_layout_.AddChild(&preview_button_); preview_layout_.SetChildLayoutData( 0, StackChildLayoutData{Alignment::Center, Alignment::Center}); + + style_rule_set_editor_.BindStyleRuleSet( + preview_button_.GetStyleRuleSet()->GetParent()); + main_layout_.AddChild(style_rule_set_editor_.GetRootControl()); } MainWindow::~MainWindow() {} diff --git a/src/theme_builder/components/MainWindow.h b/src/theme_builder/components/MainWindow.h index c6733111..8d1675f3 100644 --- a/src/theme_builder/components/MainWindow.h +++ b/src/theme_builder/components/MainWindow.h @@ -1,4 +1,5 @@ #pragma once +#include "StyleRuleSetEditor.h" #include "cru/ui/components/Component.h" #include "cru/ui/controls/Button.h" #include "cru/ui/controls/FlexLayout.h" @@ -26,5 +27,6 @@ class MainWindow : public ui::components::Component { ui::controls::StackLayout preview_layout_; ui::controls::Button preview_button_; ui::controls::TextBlock preview_button_text_; + StyleRuleSetEditor style_rule_set_editor_; }; } // namespace cru::theme_builder diff --git a/src/theme_builder/components/StyleRuleEditor.cpp b/src/theme_builder/components/StyleRuleEditor.cpp index 977672e3..7a99900b 100644 --- a/src/theme_builder/components/StyleRuleEditor.cpp +++ b/src/theme_builder/components/StyleRuleEditor.cpp @@ -1,15 +1,37 @@ #include "StyleRuleEditor.h" +#include "conditions/ConditionEditor.h" +#include "cru/ui/style/StyleRule.h" namespace cru::theme_builder { -StyleRuleEditor::StyleRuleEditor() {} +StyleRuleEditor::StyleRuleEditor() { + main_layout_.SetFlexDirection(ui::controls::FlexDirection::Horizontal); + main_layout_.AddChild(&remove_button_); -StyleRuleEditor::~StyleRuleEditor() { main_layout_.RemoveFromParent(); } + remove_button_.SetChild(&remove_button_text_); + remove_button_text_.SetText(u"X"); + + main_layout_.AddChild(&right_layout_); + right_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); -void StyleRuleEditor::BindStyleRule(ui::style::StyleRule *rule) { - style_rule_ = rule; - UpdateView(); + remove_button_.ClickEvent()->AddSpyOnlyHandler( + [this] { remove_event_.Raise(nullptr); }); } -void StyleRuleEditor::UpdateView() {} +StyleRuleEditor::~StyleRuleEditor() { main_layout_.RemoveFromParent(); } + +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) { + right_layout_.ClearChildren(); + condition_editor_ = + components::conditions::CreateConditionEditor(style_rule.GetCondition()); + styler_editor_ = + components::stylers::CreateStylerEditor(style_rule.GetStyler()); + right_layout_.AddChild(condition_editor_->GetRootControl()); + right_layout_.AddChild(styler_editor_->GetRootControl()); +} } // namespace cru::theme_builder diff --git a/src/theme_builder/components/StyleRuleEditor.h b/src/theme_builder/components/StyleRuleEditor.h index 5a14161e..204b65b4 100644 --- a/src/theme_builder/components/StyleRuleEditor.h +++ b/src/theme_builder/components/StyleRuleEditor.h @@ -1,8 +1,11 @@ #pragma once +#include "conditions/ConditionEditor.h" #include "cru/ui/components/Component.h" +#include "cru/ui/controls/Button.h" #include "cru/ui/controls/Control.h" #include "cru/ui/controls/FlexLayout.h" #include "cru/ui/style/StyleRule.h" +#include "stylers/StylerEditor.h" namespace cru::theme_builder { class StyleRuleEditor : public ui::components::Component { @@ -17,14 +20,22 @@ class StyleRuleEditor : public ui::components::Component { public: ui::controls::Control* GetRootControl() override { return &main_layout_; } - void BindStyleRule(ui::style::StyleRule* rule); + ui::style::StyleRule GetValue() const; + void SetValue(const ui::style::StyleRule& style_rule, + bool trigger_change = true); - private: - void UpdateView(); + IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + IEvent<std::nullptr_t>* RemoveEvent() { return &remove_event_; } private: ui::controls::FlexLayout main_layout_; - - ui::style::StyleRule* style_rule_; + ui::controls::Button remove_button_; + ui::controls::TextBlock remove_button_text_; + ui::controls::FlexLayout right_layout_; + std::unique_ptr<components::conditions::ConditionEditor> condition_editor_; + std::unique_ptr<components::stylers::StylerEditor> styler_editor_; + + Event<std::nullptr_t> change_event_; + Event<std::nullptr_t> remove_event_; }; } // namespace cru::theme_builder 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<StyleRuleEditor>()); + 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<ui::style::StyleRuleSet> 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<StyleRuleEditor>(); + 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 diff --git a/src/theme_builder/components/StyleRuleSetEditor.h b/src/theme_builder/components/StyleRuleSetEditor.h index 75597cf4..cb77d71e 100644 --- a/src/theme_builder/components/StyleRuleSetEditor.h +++ b/src/theme_builder/components/StyleRuleSetEditor.h @@ -1,5 +1,7 @@ #pragma once +#include "StyleRuleEditor.h" #include "cru/ui/components/Component.h" +#include "cru/ui/controls/Button.h" #include "cru/ui/controls/Control.h" #include "cru/ui/controls/FlexLayout.h" #include "cru/ui/style/StyleRuleSet.h" @@ -15,16 +17,17 @@ class StyleRuleSetEditor : public ui::components::Component { ~StyleRuleSetEditor() override; public: - ui::controls::Control* GetRootControl() override { return &main_layout_; } + ui::controls::Control* GetRootControl() override { return &container_; } void BindStyleRuleSet(std::shared_ptr<ui::style::StyleRuleSet> rule_set); private: - void UpdateView(); - - private: - ui::controls::FlexLayout main_layout_; - std::shared_ptr<ui::style::StyleRuleSet> style_rule_set_; + + ui::controls::FlexLayout container_; + ui::controls::FlexLayout rules_layout_; + std::vector<std::unique_ptr<StyleRuleEditor>> style_rule_editors_; + ui::controls::Button add_button_; + ui::controls::TextBlock add_button_text_; }; } // namespace cru::theme_builder diff --git a/src/theme_builder/components/conditions/CheckedConditionEditor.h b/src/theme_builder/components/conditions/CheckedConditionEditor.h index e5203770..9e2ebddc 100644 --- a/src/theme_builder/components/conditions/CheckedConditionEditor.h +++ b/src/theme_builder/components/conditions/CheckedConditionEditor.h @@ -22,7 +22,7 @@ class CheckedConditionEditor : public ConditionEditor { return GetValue(); } - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; } private: properties::CheckBoxPropertyEditor checked_check_box_; diff --git a/src/theme_builder/components/conditions/ClickStateConditionEditor.h b/src/theme_builder/components/conditions/ClickStateConditionEditor.h index 78664620..fa4b0c52 100644 --- a/src/theme_builder/components/conditions/ClickStateConditionEditor.h +++ b/src/theme_builder/components/conditions/ClickStateConditionEditor.h @@ -24,7 +24,7 @@ class ClickStateConditionEditor : public ConditionEditor { return GetValue(); } - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; } private: properties::SelectPropertyEditor click_state_select_; diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.h b/src/theme_builder/components/conditions/CompoundConditionEditor.h index bedbdc56..50f745c3 100644 --- a/src/theme_builder/components/conditions/CompoundConditionEditor.h +++ b/src/theme_builder/components/conditions/CompoundConditionEditor.h @@ -42,7 +42,7 @@ class CompoundConditionEditor : public ConditionEditor { void SetChildren(std::vector<ClonablePtr<ui::style::Condition>> children, bool trigger_change = true); - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; } private: ui::controls::FlexLayout children_container_; diff --git a/src/theme_builder/components/conditions/ConditionEditor.h b/src/theme_builder/components/conditions/ConditionEditor.h index 32984810..08128ed1 100644 --- a/src/theme_builder/components/conditions/ConditionEditor.h +++ b/src/theme_builder/components/conditions/ConditionEditor.h @@ -20,6 +20,7 @@ class ConditionEditor : public ui::components::Component { void SetLabel(String label) { label_.SetText(std::move(label)); } virtual ClonablePtr<ui::style::Condition> GetCondition() = 0; + virtual IEvent<std::nullptr_t>* ChangeEvent() = 0; private: ui::controls::FlexLayout container_; diff --git a/src/theme_builder/components/conditions/FocusConditionEditor.h b/src/theme_builder/components/conditions/FocusConditionEditor.h index f96ad821..06cdcf69 100644 --- a/src/theme_builder/components/conditions/FocusConditionEditor.h +++ b/src/theme_builder/components/conditions/FocusConditionEditor.h @@ -22,7 +22,7 @@ class FocusConditionEditor : public ConditionEditor { return GetValue(); } - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; } private: properties::CheckBoxPropertyEditor focus_check_box_; diff --git a/src/theme_builder/components/stylers/BorderStylerEditor.h b/src/theme_builder/components/stylers/BorderStylerEditor.h index 9e2147b4..ec871775 100644 --- a/src/theme_builder/components/stylers/BorderStylerEditor.h +++ b/src/theme_builder/components/stylers/BorderStylerEditor.h @@ -21,7 +21,7 @@ class BorderStylerEditor : public StylerEditor { ClonablePtr<ui::style::Styler> GetStyler() override { return GetValue(); } - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; } private: properties::OptionalPropertyEditor<properties::CornerRadiusPropertyEditor> diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.h b/src/theme_builder/components/stylers/CompoundStylerEditor.h index 5b1f86e0..a5c6fbb2 100644 --- a/src/theme_builder/components/stylers/CompoundStylerEditor.h +++ b/src/theme_builder/components/stylers/CompoundStylerEditor.h @@ -42,7 +42,7 @@ class CompoundStylerEditor : public StylerEditor { ClonablePtr<ui::style::Styler> GetStyler() override { return GetValue(); } - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; } private: ui::controls::FlexLayout children_container_; diff --git a/src/theme_builder/components/stylers/CursorStylerEditor.h b/src/theme_builder/components/stylers/CursorStylerEditor.h index 49b16a89..5c443819 100644 --- a/src/theme_builder/components/stylers/CursorStylerEditor.h +++ b/src/theme_builder/components/stylers/CursorStylerEditor.h @@ -18,7 +18,7 @@ class CursorStylerEditor : public StylerEditor { ClonablePtr<ui::style::Styler> GetStyler() override { return GetValue(); } - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; } private: properties::SelectPropertyEditor cursor_select_; diff --git a/src/theme_builder/components/stylers/StylerEditor.h b/src/theme_builder/components/stylers/StylerEditor.h index 6da0f6fa..b3e0d287 100644 --- a/src/theme_builder/components/stylers/StylerEditor.h +++ b/src/theme_builder/components/stylers/StylerEditor.h @@ -19,6 +19,7 @@ class StylerEditor : public ui::components::Component { void SetLabel(String label) { label_.SetText(std::move(label)); } virtual ClonablePtr<ui::style::Styler> GetStyler() = 0; + virtual IEvent<std::nullptr_t>* ChangeEvent() = 0; private: ui::controls::FlexLayout container_; |