aboutsummaryrefslogtreecommitdiff
path: root/src/theme_builder/components/properties/PointPropertyEditor.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-02-12 18:17:52 +0800
committercrupest <crupest@outlook.com>2022-02-12 18:17:52 +0800
commitb7946e28a08c945e26d39f095d2e55c952a936c4 (patch)
tree1e3df327fd8d36c88aa9840ff711545f316e3129 /src/theme_builder/components/properties/PointPropertyEditor.cpp
parent2fd37d41bb804a06acc8e2d341d5ce5d8370184b (diff)
downloadcru-b7946e28a08c945e26d39f095d2e55c952a936c4.tar.gz
cru-b7946e28a08c945e26d39f095d2e55c952a936c4.tar.bz2
cru-b7946e28a08c945e26d39f095d2e55c952a936c4.zip
...
Diffstat (limited to 'src/theme_builder/components/properties/PointPropertyEditor.cpp')
-rw-r--r--src/theme_builder/components/properties/PointPropertyEditor.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/theme_builder/components/properties/PointPropertyEditor.cpp b/src/theme_builder/components/properties/PointPropertyEditor.cpp
new file mode 100644
index 00000000..a8549c8d
--- /dev/null
+++ b/src/theme_builder/components/properties/PointPropertyEditor.cpp
@@ -0,0 +1,39 @@
+#include "PointPropertyEditor.h"
+#include "cru/common/Format.h"
+#include "cru/ui/mapper/MapperRegistry.h"
+#include "cru/ui/mapper/PointMapper.h"
+
+namespace cru::theme_builder::components::properties {
+PointPropertyEditor::PointPropertyEditor() {
+ container_.AddChild(&label_);
+ container_.AddChild(&text_);
+
+ text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) {
+ auto text = text_.GetTextView();
+ auto point_mapper =
+ ui::mapper::MapperRegistry::GetInstance()->GetMapper<ui::Point>();
+ try {
+ auto point = point_mapper->MapFromString(text.ToString());
+ point_ = point;
+ is_text_valid_ = true;
+ point_change_event_.Raise(point);
+ } catch (const Exception&) {
+ is_text_valid_ = false;
+ // TODO: Show error!
+ }
+ });
+}
+
+PointPropertyEditor::~PointPropertyEditor() {}
+
+void PointPropertyEditor::SetPoint(const ui::Point& point) {
+ point_ = point;
+ text_.SetText(ConvertPointToString(point));
+ is_text_valid_ = true;
+ point_change_event_.Raise(point);
+}
+
+String PointPropertyEditor::ConvertPointToString(const ui::Point& point) {
+ return Format(u"{} {}", point.x, point.y);
+}
+} // namespace cru::theme_builder::components::properties