diff options
author | crupest <crupest@outlook.com> | 2022-01-20 22:49:41 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-01-20 22:49:41 +0800 |
commit | c0f802594e17efd5b93d4019431bf1a6d24249c3 (patch) | |
tree | 408c1a212f02a11ba84eb3911137f272f3862799 | |
parent | 6f26995173d8ad46e347afc2ebd27573cee98ce7 (diff) | |
download | cru-c0f802594e17efd5b93d4019431bf1a6d24249c3.tar.gz cru-c0f802594e17efd5b93d4019431bf1a6d24249c3.tar.bz2 cru-c0f802594e17efd5b93d4019431bf1a6d24249c3.zip |
...
-rw-r--r-- | include/cru/ui/mapper/PointMapper.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/mapper/SizeMapper.hpp | 18 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/ui/mapper/SizeMapper.cpp | 27 |
4 files changed, 46 insertions, 2 deletions
diff --git a/include/cru/ui/mapper/PointMapper.hpp b/include/cru/ui/mapper/PointMapper.hpp index 0fcb733f..5641af01 100644 --- a/include/cru/ui/mapper/PointMapper.hpp +++ b/include/cru/ui/mapper/PointMapper.hpp @@ -5,8 +5,6 @@ namespace cru::ui::mapper { class CRU_UI_API PointMapper : public BasicMapper<Point> { public: CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(PointMapper) - CRU_DELETE_COPY(PointMapper) - CRU_DELETE_MOVE(PointMapper) public: bool SupportMapFromString() override { return true; } diff --git a/include/cru/ui/mapper/SizeMapper.hpp b/include/cru/ui/mapper/SizeMapper.hpp new file mode 100644 index 00000000..20558bf4 --- /dev/null +++ b/include/cru/ui/mapper/SizeMapper.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "Mapper.hpp" + +namespace cru::ui::mapper { +class CRU_UI_API SizeMapper : public BasicMapper<Size> { + public: + CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(SizeMapper) + + public: + bool SupportMapFromString() override { return true; } + bool SupportMapFromXml() override { return true; } + bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; + + protected: + std::unique_ptr<Size> DoMapFromString(String str) override; + std::unique_ptr<Size> DoMapFromXml(xml::XmlElementNode* node) override; +}; +} // namespace cru::ui::mapper diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 9dbe9b3c..ce71e89b 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -29,6 +29,7 @@ add_library(cru_ui SHARED mapper/Mapper.cpp mapper/MapperRegistry.cpp mapper/PointMapper.cpp + mapper/SizeMapper.cpp mapper/ThicknessMapper.cpp render/BorderRenderObject.cpp render/CanvasRenderObject.cpp diff --git a/src/ui/mapper/SizeMapper.cpp b/src/ui/mapper/SizeMapper.cpp new file mode 100644 index 00000000..4f9dc208 --- /dev/null +++ b/src/ui/mapper/SizeMapper.cpp @@ -0,0 +1,27 @@ +#include "cru/ui/mapper/SizeMapper.hpp" + +namespace cru::ui::mapper { +bool SizeMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { + if (node->GetTag() == u"Size") { + return true; + } + return false; +} + +std::unique_ptr<Size> SizeMapper::DoMapFromString(String str) { + std::vector<float> values = str.ParseToFloatList(); + if (values.size() == 2) { + return std::make_unique<Size>(values[0], values[1]); + } else if (values.size() == 1) { + return std::make_unique<Size>(values[0], values[0]); + } else { + throw Exception(u"Invalid Point string."); + } +} + +std::unique_ptr<Size> SizeMapper::DoMapFromXml(xml::XmlElementNode* node) { + auto value_attr = node->GetOptionalAttribute(u"value"); + if (!value_attr) return std::make_unique<Size>(); + return DoMapFromString(*value_attr); +} +} // namespace cru::ui::mapper |