diff options
author | crupest <crupest@outlook.com> | 2022-03-10 18:03:49 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-10 18:03:49 +0800 |
commit | 1cf1002f1d3cd81ddb920eb7196a067b566f11e2 (patch) | |
tree | 8a299d16f0f5074d876175a602190f477bd498ea /include/cru/ui/components | |
parent | 51f87e3ff980e62f9cb5ee656e5591412e2766eb (diff) | |
download | cru-1cf1002f1d3cd81ddb920eb7196a067b566f11e2.tar.gz cru-1cf1002f1d3cd81ddb920eb7196a067b566f11e2.tar.bz2 cru-1cf1002f1d3cd81ddb920eb7196a067b566f11e2.zip |
...
Diffstat (limited to 'include/cru/ui/components')
-rw-r--r-- | include/cru/ui/components/Input.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/include/cru/ui/components/Input.h b/include/cru/ui/components/Input.h new file mode 100644 index 00000000..e808afd7 --- /dev/null +++ b/include/cru/ui/components/Input.h @@ -0,0 +1,77 @@ +#pragma once +#include "../controls/TextBox.h" +#include "Component.h" + +namespace cru::ui::components { +struct CRU_UI_API InputValidateResult { + bool valid; + String message; +}; + +struct CRU_UI_API IInputValidator : public virtual Interface { + virtual InputValidateResult Validate(StringView text) const = 0; +}; + +struct CRU_UI_API InputChangeEventArgs { + String text; + bool valid; + String message; +}; + +class CRU_UI_API Input : public Component { + public: + Input(); + ~Input() override; + + public: + controls::Control* GetRootControl() override; + + String GetText() const; + void SetText(String text); + + IInputValidator* GetValidator() const; + void SetValidator(IInputValidator* validator); + + InputValidateResult Validate(); + InputValidateResult GetLastValidateResult() const; + + IEvent<InputChangeEventArgs>* ChangeEvent() { return &change_event_; } + + private: + controls::TextBox text_box_; + IInputValidator* validator_; + InputValidateResult last_validate_result_; + + Event<InputChangeEventArgs> change_event_; +}; + +class CRU_UI_API FloatInputValidator : public Object, + public virtual IInputValidator { + public: + InputValidateResult Validate(StringView text) const override; + + std::optional<float> min; + std::optional<float> max; +}; + +class CRU_UI_API FloatInput : public Input { + public: + FloatInput(); + ~FloatInput() override; + + public: + float GetValue() const; + void SetValue(float value); + + std::optional<float> GetMax() const; + void SetMax(std::optional<float> max); + + std::optional<float> GetMin() const; + void SetMin(std::optional<float> min); + + private: + float value_; + + FloatInputValidator validator_; +}; +} // namespace cru::ui::components |