diff options
author | crupest <crupest@outlook.com> | 2022-02-11 17:46:20 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-11 17:46:20 +0800 |
commit | 2fd37d41bb804a06acc8e2d341d5ce5d8370184b (patch) | |
tree | 4a87909043189928c38ee325377ee600d5321b19 /src/theme_builder | |
parent | 85746e9f053432bdcfb99b21997efa040eac1bc3 (diff) | |
download | cru-2fd37d41bb804a06acc8e2d341d5ce5d8370184b.tar.gz cru-2fd37d41bb804a06acc8e2d341d5ce5d8370184b.tar.bz2 cru-2fd37d41bb804a06acc8e2d341d5ce5d8370184b.zip |
...
Diffstat (limited to 'src/theme_builder')
-rw-r--r-- | src/theme_builder/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/theme_builder/components/conditions/CompoundConditionEditor.h (renamed from src/theme_builder/components/conditions/CompoundConditionEditor.hpp) | 0 | ||||
-rw-r--r-- | src/theme_builder/components/properties/TextPropertyEditor.cpp | 22 | ||||
-rw-r--r-- | src/theme_builder/components/properties/TextPropertyEditor.h | 31 |
4 files changed, 54 insertions, 0 deletions
diff --git a/src/theme_builder/CMakeLists.txt b/src/theme_builder/CMakeLists.txt index 8e1dc244..108281a1 100644 --- a/src/theme_builder/CMakeLists.txt +++ b/src/theme_builder/CMakeLists.txt @@ -4,6 +4,7 @@ add_executable(cru_theme_builder components/StyleRuleEditor.cpp components/StyleRuleSetEditor.cpp components/conditions/ConditionEditor.cpp + components/properties/TextPropertyEditor.cpp ) if(APPLE) diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.hpp b/src/theme_builder/components/conditions/CompoundConditionEditor.h index 00f73e09..00f73e09 100644 --- a/src/theme_builder/components/conditions/CompoundConditionEditor.hpp +++ b/src/theme_builder/components/conditions/CompoundConditionEditor.h diff --git a/src/theme_builder/components/properties/TextPropertyEditor.cpp b/src/theme_builder/components/properties/TextPropertyEditor.cpp new file mode 100644 index 00000000..9854019c --- /dev/null +++ b/src/theme_builder/components/properties/TextPropertyEditor.cpp @@ -0,0 +1,22 @@ +#include "TextPropertyEditor.h" + +namespace cru::theme_builder::components::properties { +TextPropertyEditor::TextPropertyEditor() { + editor_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { + auto text_view = editor_.GetTextView(); + String error_message; + auto validation_result = Validate(text_view, &error_message); + if (validation_result) { + OnTextChanged(text_view); + } + }); +} + +TextPropertyEditor::~TextPropertyEditor() {} + +bool TextPropertyEditor::Validate(StringView text, String* error_message) { + return true; +} + +void TextPropertyEditor::OnTextChanged(StringView text) {} +} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/TextPropertyEditor.h b/src/theme_builder/components/properties/TextPropertyEditor.h new file mode 100644 index 00000000..c4944228 --- /dev/null +++ b/src/theme_builder/components/properties/TextPropertyEditor.h @@ -0,0 +1,31 @@ +#pragma once +#include "cru/ui/components/Component.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/TextBlock.h" +#include "cru/ui/controls/TextBox.h" + +namespace cru::theme_builder::components::properties { +class TextPropertyEditor : public ui::components::Component { + public: + TextPropertyEditor(); + ~TextPropertyEditor() override; + + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + String GetText() const { return editor_.GetText(); } + StringView GetTextView() const { return editor_.GetTextView(); } + void SetText(String text) { editor_.SetText(std::move(text)); } + + protected: + virtual bool Validate(StringView text, String* error_message); + virtual void OnTextChanged(StringView text); + + private: + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::controls::TextBox editor_; +}; +} // namespace cru::theme_builder::components::properties |