From 2fd37d41bb804a06acc8e2d341d5ce5d8370184b Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 11 Feb 2022 17:46:20 +0800 Subject: ... --- include/cru/platform/graphics/Base.h | 2 -- include/cru/ui/Base.h | 5 ---- include/cru/ui/controls/TextBox.h | 8 ++++++ include/cru/ui/controls/TextHostControlService.h | 4 +++ src/theme_builder/CMakeLists.txt | 1 + .../conditions/CompoundConditionEditor.h | 7 +++++ .../conditions/CompoundConditionEditor.hpp | 7 ----- .../components/properties/TextPropertyEditor.cpp | 22 +++++++++++++++ .../components/properties/TextPropertyEditor.h | 31 ++++++++++++++++++++++ src/ui/controls/TextHostControlService.cpp | 3 +++ 10 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 src/theme_builder/components/conditions/CompoundConditionEditor.h delete mode 100644 src/theme_builder/components/conditions/CompoundConditionEditor.hpp create mode 100644 src/theme_builder/components/properties/TextPropertyEditor.cpp create mode 100644 src/theme_builder/components/properties/TextPropertyEditor.h diff --git a/include/cru/platform/graphics/Base.h b/include/cru/platform/graphics/Base.h index a134fb33..3bb9b7b4 100644 --- a/include/cru/platform/graphics/Base.h +++ b/include/cru/platform/graphics/Base.h @@ -4,8 +4,6 @@ #include "../Matrix.h" #include "../Resource.h" -#include - #ifdef CRU_PLATFORM_WINDOWS #ifdef CRU_PLATFORM_GRAPHICS_EXPORT_API #define CRU_PLATFORM_GRAPHICS_API __declspec(dllexport) diff --git a/include/cru/ui/Base.h b/include/cru/ui/Base.h index 4316fbbb..5e62d785 100644 --- a/include/cru/ui/Base.h +++ b/include/cru/ui/Base.h @@ -3,11 +3,6 @@ #include "cru/platform/graphics/Base.h" #include "cru/platform/gui/Base.h" -#include -#include -#include -#include - #ifdef CRU_PLATFORM_WINDOWS #ifdef CRU_UI_EXPORT_API #define CRU_UI_API __declspec(dllexport) diff --git a/include/cru/ui/controls/TextBox.h b/include/cru/ui/controls/TextBox.h index 94a1ac0c..3e041880 100644 --- a/include/cru/ui/controls/TextBox.h +++ b/include/cru/ui/controls/TextBox.h @@ -32,6 +32,14 @@ class CRU_UI_API TextBox : public NoChildControl, void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override; + String GetText() const { return service_->GetText(); } + StringView GetTextView() const { return service_->GetTextView(); } + void SetText(String text) { service_->SetText(std::move(text)); } + + IEvent* TextChangeEvent() { + return service_->TextChangeEvent(); + } + private: std::unique_ptr border_render_object_; std::unique_ptr scroll_render_object_; diff --git a/include/cru/ui/controls/TextHostControlService.h b/include/cru/ui/controls/TextHostControlService.h index 0d4a20cf..74da1e19 100644 --- a/include/cru/ui/controls/TextHostControlService.h +++ b/include/cru/ui/controls/TextHostControlService.h @@ -147,6 +147,8 @@ class CRU_UI_API TextHostControlService : public Object { void Copy(); void Paste(); + IEvent* TextChangeEvent() { return &text_change_event_; } + gsl::not_null GetTextRenderObject(); render::ScrollRenderObject* GetScrollRenderObject(); @@ -192,6 +194,8 @@ class CRU_UI_API TextHostControlService : public Object { gsl::not_null control_; gsl::not_null text_host_control_; + Event text_change_event_; + EventRevokerListGuard event_guard_; EventRevokerListGuard input_method_context_event_guard_; 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.h b/src/theme_builder/components/conditions/CompoundConditionEditor.h new file mode 100644 index 00000000..00f73e09 --- /dev/null +++ b/src/theme_builder/components/conditions/CompoundConditionEditor.h @@ -0,0 +1,7 @@ +#pragma once +#include "ConditionEditor.h" + +namespace cru::theme_builder::components::conditions { +class CompoundConditionEditor : public ConditionEditor {}; + +} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.hpp b/src/theme_builder/components/conditions/CompoundConditionEditor.hpp deleted file mode 100644 index 00f73e09..00000000 --- a/src/theme_builder/components/conditions/CompoundConditionEditor.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include "ConditionEditor.h" - -namespace cru::theme_builder::components::conditions { -class CompoundConditionEditor : public ConditionEditor {}; - -} // namespace cru::theme_builder::components::conditions 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 diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp index c537a86e..81365a8b 100644 --- a/src/ui/controls/TextHostControlService.cpp +++ b/src/ui/controls/TextHostControlService.cpp @@ -220,6 +220,7 @@ void TextHostControlService::SetText(String text, bool stop_composition) { CancelComposition(); } SyncTextRenderObject(); + text_change_event_.Raise(nullptr); } void TextHostControlService::InsertText(gsl::index position, StringView text, @@ -233,6 +234,7 @@ void TextHostControlService::InsertText(gsl::index position, StringView text, CancelComposition(); } SyncTextRenderObject(); + text_change_event_.Raise(nullptr); } void TextHostControlService::DeleteChar(gsl::index position, @@ -281,6 +283,7 @@ void TextHostControlService::DeleteText(TextRange range, CancelComposition(); } this->SyncTextRenderObject(); + text_change_event_.Raise(nullptr); } platform::gui::IInputMethodContext* -- cgit v1.2.3