diff options
author | crupest <crupest@outlook.com> | 2022-02-16 17:30:49 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-16 17:30:49 +0800 |
commit | da6f0bcfc6ec786cf14f67f100b4c50cf2325db4 (patch) | |
tree | 8e9a2c5389ba9f352f5823c0eec525a04993f2b4 | |
parent | 674e8af2e92074b71c77e656a54244ce2693460c (diff) | |
download | cru-da6f0bcfc6ec786cf14f67f100b4c50cf2325db4.tar.gz cru-da6f0bcfc6ec786cf14f67f100b4c50cf2325db4.tar.bz2 cru-da6f0bcfc6ec786cf14f67f100b4c50cf2325db4.zip |
...
9 files changed, 120 insertions, 3 deletions
diff --git a/include/cru/ui/style/Condition.h b/include/cru/ui/style/Condition.h index 1038c34b..446e5bc0 100644 --- a/include/cru/ui/style/Condition.h +++ b/include/cru/ui/style/Condition.h @@ -89,6 +89,8 @@ class CRU_UI_API FocusCondition : public Condition { return new FocusCondition(has_focus_); } + bool IsHasFocus() const { return has_focus_; } + private: bool has_focus_; }; diff --git a/src/theme_builder/CMakeLists.txt b/src/theme_builder/CMakeLists.txt index f4214935..41c3808f 100644 --- a/src/theme_builder/CMakeLists.txt +++ b/src/theme_builder/CMakeLists.txt @@ -5,6 +5,8 @@ add_executable(cru_theme_builder components/StyleRuleSetEditor.cpp components/conditions/ClickStateConditionEditor.cpp components/conditions/ConditionEditor.cpp + components/conditions/FocusConditionEditor.cpp + components/properties/CheckBoxPropertyEditor.cpp components/properties/ColorPropertyEditor.cpp components/properties/CornerRadiusPropertyEditor.cpp components/properties/PointPropertyEditor.cpp diff --git a/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp b/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp index a9170cc5..80d221bd 100644 --- a/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp +++ b/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp @@ -61,7 +61,8 @@ ClickStateConditionEditor::GetValue() const { } void ClickStateConditionEditor::SetValue( - ClonablePtr<ui::style::ClickStateCondition> value, bool trigger_change) { + const ClonablePtr<ui::style::ClickStateCondition>& value, + bool trigger_change) { click_state_select_.SetSelectedIndex( ConvertClickStateToIndex(value->GetClickState()), trigger_change); } diff --git a/src/theme_builder/components/conditions/ClickStateConditionEditor.h b/src/theme_builder/components/conditions/ClickStateConditionEditor.h index f172f029..4e18c423 100644 --- a/src/theme_builder/components/conditions/ClickStateConditionEditor.h +++ b/src/theme_builder/components/conditions/ClickStateConditionEditor.h @@ -13,7 +13,7 @@ class ClickStateConditionEditor : public ConditionEditor { public: ClonablePtr<ui::style::ClickStateCondition> GetValue() const; - void SetValue(ClonablePtr<ui::style::ClickStateCondition> value, + void SetValue(const ClonablePtr<ui::style::ClickStateCondition>& value, bool trigger_change = true); ClonablePtr<ui::style::Condition> GetCondition() override { diff --git a/src/theme_builder/components/conditions/FocusConditionEditor.cpp b/src/theme_builder/components/conditions/FocusConditionEditor.cpp new file mode 100644 index 00000000..d5d864e1 --- /dev/null +++ b/src/theme_builder/components/conditions/FocusConditionEditor.cpp @@ -0,0 +1,23 @@ +#include "FocusConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +FocusConditionEditor::FocusConditionEditor() { + GetContainer()->AddChild(focus_check_box_.GetRootControl()); + + focus_check_box_.ChangeEvent()->AddSpyOnlyHandler( + [this] { change_event_.Raise(nullptr); }); +} + +FocusConditionEditor::~FocusConditionEditor() {} + +ClonablePtr<ui::style::FocusCondition> FocusConditionEditor::GetValue() const { + return ui::style::FocusCondition::Create(focus_check_box_.GetValue()); +} + +void FocusConditionEditor::SetValue( + const ClonablePtr<ui::style::FocusCondition> &value, bool trigger_change) { + focus_check_box_.SetValue(value->IsHasFocus(), trigger_change); +} +} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/FocusConditionEditor.h b/src/theme_builder/components/conditions/FocusConditionEditor.h new file mode 100644 index 00000000..ab5d40c6 --- /dev/null +++ b/src/theme_builder/components/conditions/FocusConditionEditor.h @@ -0,0 +1,29 @@ +#pragma once +#include "../properties/CheckBoxPropertyEditor.h" +#include "ConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +class FocusConditionEditor : public ConditionEditor { + public: + FocusConditionEditor(); + ~FocusConditionEditor() override; + + public: + ClonablePtr<ui::style::FocusCondition> GetValue() const; + void SetValue(const ClonablePtr<ui::style::FocusCondition>& value, + bool trigger_change = true); + + ClonablePtr<ui::style::Condition> GetCondition() override { + return GetValue(); + } + + IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + + private: + properties::CheckBoxPropertyEditor focus_check_box_; + + Event<std::nullptr_t> change_event_; +}; +} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp new file mode 100644 index 00000000..2e921f96 --- /dev/null +++ b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp @@ -0,0 +1,26 @@ +#include "CheckBoxPropertyEditor.h" + +namespace cru::theme_builder::components::properties { +CheckBoxPropertyEditor::CheckBoxPropertyEditor() { + container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal); + container_.AddChild(&label_); + container_.AddChild(&check_box_); + + check_box_.CheckedChangeEvent()->AddSpyOnlyHandler([this] { + if (!suppress_next_change_event_) { + change_event_.Raise(nullptr); + } else { + suppress_next_change_event_ = false; + } + }); +} + +CheckBoxPropertyEditor::~CheckBoxPropertyEditor() { + container_.RemoveFromParent(); +} + +void CheckBoxPropertyEditor::SetValue(bool value, bool trigger_change) { + if (!trigger_change) suppress_next_change_event_ = true; + check_box_.SetChecked(value); +} +} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/CheckBoxPropertyEditor.h b/src/theme_builder/components/properties/CheckBoxPropertyEditor.h new file mode 100644 index 00000000..07ac4fe0 --- /dev/null +++ b/src/theme_builder/components/properties/CheckBoxPropertyEditor.h @@ -0,0 +1,35 @@ +#pragma once +#include "cru/ui/components/Component.h" +#include "cru/ui/controls/CheckBox.h" +#include "cru/ui/controls/Control.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/TextBlock.h" + +namespace cru::theme_builder::components::properties { +class CheckBoxPropertyEditor : public ui::components::Component { + public: + using PropertyType = bool; + + CheckBoxPropertyEditor(); + ~CheckBoxPropertyEditor() override; + + public: + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + bool GetValue() const { return check_box_.IsChecked(); } + void SetValue(bool value, bool trigger_change = true); + + IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + + private: + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::controls::CheckBox check_box_; + + bool suppress_next_change_event_ = false; + Event<std::nullptr_t> change_event_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ui/controls/CheckBox.cpp b/src/ui/controls/CheckBox.cpp index d41d1cb6..cace3dbf 100644 --- a/src/ui/controls/CheckBox.cpp +++ b/src/ui/controls/CheckBox.cpp @@ -15,7 +15,6 @@ CheckBox::CheckBox() CheckBox::~CheckBox() {} void CheckBox::SetChecked(bool checked) { - if (checked == checked_) return; checked_ = checked; checked_change_event_.Raise(checked); } |