diff options
7 files changed, 172 insertions, 2 deletions
diff --git a/include/cru/ui/components/Select.h b/include/cru/ui/components/Select.h index cc658092..d5ff0b43 100644 --- a/include/cru/ui/components/Select.h +++ b/include/cru/ui/components/Select.h @@ -13,10 +13,10 @@ class CRU_UI_API Select : public Component { public: ui::controls::Control* GetRootControl() override { return &button_; } - std::vector<String> GetItems() { return items_; } + std::vector<String> GetItems() const { return items_; } void SetItems(std::vector<String> items); - Index GetSelectedIndex() { return selected_index_; } + Index GetSelectedIndex() const { return selected_index_; } void SetSelectedIndex(Index index); IEvent<Index>* ItemSelectedEvent() { return &item_selected_event_; } diff --git a/include/cru/ui/style/Condition.h b/include/cru/ui/style/Condition.h index 14d7e625..1038c34b 100644 --- a/include/cru/ui/style/Condition.h +++ b/include/cru/ui/style/Condition.h @@ -127,6 +127,8 @@ class CRU_UI_API ClickStateCondition : public Condition { return new ClickStateCondition(click_state_); } + helper::ClickState GetClickState() const { return click_state_; } + private: helper::ClickState click_state_; }; 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 |