diff options
author | crupest <crupest@outlook.com> | 2022-02-16 17:00:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-16 17:00:33 +0800 |
commit | 674e8af2e92074b71c77e656a54244ce2693460c (patch) | |
tree | d109201e4204011fe9e714ff81490674b2f7b042 /src/theme_builder | |
parent | 43a297f30c03180427db435bb25a1a4b51ea847a (diff) | |
download | cru-674e8af2e92074b71c77e656a54244ce2693460c.tar.gz cru-674e8af2e92074b71c77e656a54244ce2693460c.tar.bz2 cru-674e8af2e92074b71c77e656a54244ce2693460c.zip |
...
Diffstat (limited to 'src/theme_builder')
5 files changed, 168 insertions, 0 deletions
diff --git a/src/theme_builder/CMakeLists.txt b/src/theme_builder/CMakeLists.txt index 902173fd..f4214935 100644 --- a/src/theme_builder/CMakeLists.txt +++ b/src/theme_builder/CMakeLists.txt @@ -3,10 +3,12 @@ add_executable(cru_theme_builder components/MainWindow.cpp components/StyleRuleEditor.cpp components/StyleRuleSetEditor.cpp + components/conditions/ClickStateConditionEditor.cpp components/conditions/ConditionEditor.cpp components/properties/ColorPropertyEditor.cpp components/properties/CornerRadiusPropertyEditor.cpp components/properties/PointPropertyEditor.cpp + components/properties/SelectPropertyEditor.cpp components/properties/TextPropertyEditor.cpp components/properties/ThicknessPropertyEditor.cpp components/stylers/BorderStylerEditor.cpp diff --git a/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp b/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp new file mode 100644 index 00000000..a9170cc5 --- /dev/null +++ b/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp @@ -0,0 +1,68 @@ +#include "ClickStateConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/helper/ClickDetector.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +using ui::helper::ClickState; +namespace { +const std::vector<String> kClickStates{ + u"None", + u"Hover", + u"Press", + u"PressInactive", +}; + +Index ConvertClickStateToIndex(ClickState click_state) { + switch (click_state) { + case ClickState::None: + return 0; + case ClickState::Hover: + return 1; + case ClickState::Press: + return 2; + case ClickState::PressInactive: + return 3; + } + return -1; +} + +ClickState ConvertIndexToClickState(Index index) { + switch (index) { + case 0: + return ClickState::None; + case 1: + return ClickState::Hover; + case 2: + return ClickState::Press; + case 3: + return ClickState::PressInactive; + } + return ClickState::None; +} +} // namespace + +ClickStateConditionEditor::ClickStateConditionEditor() { + GetContainer()->AddChild(click_state_select_.GetRootControl()); + + click_state_select_.SetItems(kClickStates); + click_state_select_.SetSelectedIndex(0, false); + + click_state_select_.ChangeEvent()->AddSpyOnlyHandler( + [this] { change_event_.Raise(nullptr); }); +} + +ClickStateConditionEditor::~ClickStateConditionEditor() {} + +ClonablePtr<ui::style::ClickStateCondition> +ClickStateConditionEditor::GetValue() const { + return ui::style::ClickStateCondition::Create( + ConvertIndexToClickState(click_state_select_.GetSelectedIndex())); +} + +void ClickStateConditionEditor::SetValue( + ClonablePtr<ui::style::ClickStateCondition> value, bool trigger_change) { + click_state_select_.SetSelectedIndex( + ConvertClickStateToIndex(value->GetClickState()), trigger_change); +} +} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/ClickStateConditionEditor.h b/src/theme_builder/components/conditions/ClickStateConditionEditor.h new file mode 100644 index 00000000..f172f029 --- /dev/null +++ b/src/theme_builder/components/conditions/ClickStateConditionEditor.h @@ -0,0 +1,30 @@ +#pragma once +#include "../properties/SelectPropertyEditor.h" +#include "ConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/common/Event.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +class ClickStateConditionEditor : public ConditionEditor { + public: + ClickStateConditionEditor(); + ~ClickStateConditionEditor(); + + public: + ClonablePtr<ui::style::ClickStateCondition> GetValue() const; + void SetValue(ClonablePtr<ui::style::ClickStateCondition> value, + bool trigger_change = true); + + ClonablePtr<ui::style::Condition> GetCondition() override { + return GetValue(); + } + + IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + + private: + properties::SelectPropertyEditor click_state_select_; + + Event<std::nullptr_t> change_event_; +}; +} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/properties/SelectPropertyEditor.cpp b/src/theme_builder/components/properties/SelectPropertyEditor.cpp new file mode 100644 index 00000000..10011d65 --- /dev/null +++ b/src/theme_builder/components/properties/SelectPropertyEditor.cpp @@ -0,0 +1,21 @@ +#include "SelectPropertyEditor.h" +#include "cru/ui/controls/FlexLayout.h" + +namespace cru::theme_builder::components::properties { +SelectPropertyEditor::SelectPropertyEditor() { + container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal); + container_.AddChild(&label_); + container_.AddChild(select_.GetRootControl()); + + select_.ItemSelectedEvent()->AddHandler([this](Index index) { + if (!suppress_next_change_event_) { + change_event_.Raise(nullptr); + } else { + suppress_next_change_event_ = false; + } + }); +} + +SelectPropertyEditor::~SelectPropertyEditor() { container_.RemoveFromParent(); } + +} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/SelectPropertyEditor.h b/src/theme_builder/components/properties/SelectPropertyEditor.h new file mode 100644 index 00000000..a67cb80f --- /dev/null +++ b/src/theme_builder/components/properties/SelectPropertyEditor.h @@ -0,0 +1,47 @@ +#pragma once +#include "cru/ui/components/Component.h" +#include "cru/ui/components/Select.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/TextBlock.h" + +namespace cru::theme_builder::components::properties { +class SelectPropertyEditor : public ui::components::Component { + public: + using PropertyType = Index; + + SelectPropertyEditor(); + ~SelectPropertyEditor() override; + + public: + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + Index GetSelectedIndex() const { return select_.GetSelectedIndex(); } + void SetSelectedIndex(Index index, bool trigger_change = true) { + if (trigger_change == false) suppress_next_change_event_ = true; + select_.SetSelectedIndex(index); + } + + std::vector<String> GetItems() const { return select_.GetItems(); } + void SetItems(std::vector<String> items) { + select_.SetItems(std::move(items)); + } + + Index GetValue() const { return GetSelectedIndex(); } + void SetValue(Index value, bool trigger_change = true) { + SetSelectedIndex(value, trigger_change); + } + + IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + + private: + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::components::Select select_; + + bool suppress_next_change_event_ = false; + Event<std::nullptr_t> change_event_; +}; +} // namespace cru::theme_builder::components::properties |