diff options
author | crupest <crupest@outlook.com> | 2022-02-24 15:56:01 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-24 15:56:01 +0800 |
commit | 640401bf2f4b3da3708970a1408b27e159f93631 (patch) | |
tree | c9692f9c6e8a3efdadabc5929029837450efd6af /src/theme_builder/components/properties/MeasureLengthPropertyEditor.cpp | |
parent | d9a3b8c14b9ab1bc591ca7c373daaf7141d2d098 (diff) | |
download | cru-640401bf2f4b3da3708970a1408b27e159f93631.tar.gz cru-640401bf2f4b3da3708970a1408b27e159f93631.tar.bz2 cru-640401bf2f4b3da3708970a1408b27e159f93631.zip |
...
Diffstat (limited to 'src/theme_builder/components/properties/MeasureLengthPropertyEditor.cpp')
-rw-r--r-- | src/theme_builder/components/properties/MeasureLengthPropertyEditor.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/theme_builder/components/properties/MeasureLengthPropertyEditor.cpp b/src/theme_builder/components/properties/MeasureLengthPropertyEditor.cpp new file mode 100644 index 00000000..d1f4afce --- /dev/null +++ b/src/theme_builder/components/properties/MeasureLengthPropertyEditor.cpp @@ -0,0 +1,37 @@ +#include "MeasureLengthPropertyEditor.h" +#include "cru/common/Format.h" +#include "cru/ui/mapper/MapperRegistry.h" +#include "cru/ui/render/MeasureRequirement.h" + +namespace cru::theme_builder::components::properties { +MeasureLengthPropertyEditor::MeasureLengthPropertyEditor() { + container_.AddChild(&label_); + container_.AddChild(&text_); + + text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { + auto text = text_.GetTextView(); + auto measure_length_mapper = ui::mapper::MapperRegistry::GetInstance() + ->GetMapper<ui::render::MeasureLength>(); + try { + auto measure_length = + measure_length_mapper->MapFromString(text.ToString()); + measure_length_ = measure_length; + is_text_valid_ = true; + RaiseChangeEvent(); + } catch (const Exception&) { + is_text_valid_ = false; + // TODO: Show error! + } + }); +} + +MeasureLengthPropertyEditor::~MeasureLengthPropertyEditor() {} + +void MeasureLengthPropertyEditor::SetValue( + const ui::render::MeasureLength& value, bool trigger_change) { + if (!trigger_change) SuppressNextChangeEvent(); + text_.SetText(measure_length_.IsNotSpecified() + ? u"unspecified" + : ToString(measure_length_.GetLengthOrUndefined())); +} +} // namespace cru::theme_builder::components::properties |