From 14d9efc39635dab2c6c0f791d6b0a63c92d941ee Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 22 Jan 2022 22:22:45 +0800 Subject: ... --- include/cru/ui/mapper/BorderStyleMapper.hpp | 20 ++++++++++++++++++++ include/cru/ui/mapper/ColorMapper.hpp | 4 ++-- include/cru/ui/mapper/CornerRadiusMapper.hpp | 3 +-- include/cru/ui/mapper/CursorMapper.hpp | 5 +++++ include/cru/ui/mapper/Mapper.hpp | 14 ++++++++------ include/cru/ui/mapper/PointMapper.hpp | 4 ++-- include/cru/ui/mapper/SizeMapper.hpp | 4 ++-- include/cru/ui/mapper/ThicknessMapper.hpp | 4 ++-- include/cru/ui/mapper/style/BorderStyleMapper.hpp | 20 -------------------- include/cru/ui/style/ApplyBorderStyleInfo.hpp | 5 +++-- 10 files changed, 45 insertions(+), 38 deletions(-) create mode 100644 include/cru/ui/mapper/BorderStyleMapper.hpp create mode 100644 include/cru/ui/mapper/CursorMapper.hpp delete mode 100644 include/cru/ui/mapper/style/BorderStyleMapper.hpp (limited to 'include') diff --git a/include/cru/ui/mapper/BorderStyleMapper.hpp b/include/cru/ui/mapper/BorderStyleMapper.hpp new file mode 100644 index 00000000..4d9ae774 --- /dev/null +++ b/include/cru/ui/mapper/BorderStyleMapper.hpp @@ -0,0 +1,20 @@ +#pragma once +#include "Mapper.hpp" +#include "cru/ui/style/ApplyBorderStyleInfo.hpp" +#include "cru/xml/XmlNode.hpp" + +namespace cru::ui::mapper { +class CRU_UI_API BorderStyleMapper + : BasicMapper { + public: + CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(BorderStyleMapper) + + public: + bool SupportMapFromXml() override { return true; } + bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; + + protected: + ui::style::ApplyBorderStyleInfo DoMapFromXml( + xml::XmlElementNode* node) override; +}; +} // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/ColorMapper.hpp b/include/cru/ui/mapper/ColorMapper.hpp index 33333025..668a4fc2 100644 --- a/include/cru/ui/mapper/ColorMapper.hpp +++ b/include/cru/ui/mapper/ColorMapper.hpp @@ -13,7 +13,7 @@ class ColorMapper : public BasicMapper { bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; protected: - std::unique_ptr DoMapFromString(String str) override; - std::unique_ptr DoMapFromXml(xml::XmlElementNode* node) override; + Color DoMapFromString(String str) override; + Color DoMapFromXml(xml::XmlElementNode* node) override; }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/CornerRadiusMapper.hpp b/include/cru/ui/mapper/CornerRadiusMapper.hpp index b9fe6a52..4d83f2de 100644 --- a/include/cru/ui/mapper/CornerRadiusMapper.hpp +++ b/include/cru/ui/mapper/CornerRadiusMapper.hpp @@ -12,7 +12,6 @@ class CRU_UI_API CornerRadiusMapper : public BasicMapper { bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; protected: - std::unique_ptr DoMapFromXml( - xml::XmlElementNode* node) override; + CornerRadius DoMapFromXml(xml::XmlElementNode* node) override; }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/CursorMapper.hpp b/include/cru/ui/mapper/CursorMapper.hpp new file mode 100644 index 00000000..b4254061 --- /dev/null +++ b/include/cru/ui/mapper/CursorMapper.hpp @@ -0,0 +1,5 @@ +#pragma once +#include "Mapper.hpp" +#include "cru/platform/gui/Cursor.hpp" + +namespace cru::ui::mapper::style {} diff --git a/include/cru/ui/mapper/Mapper.hpp b/include/cru/ui/mapper/Mapper.hpp index 79aa39aa..d15b63aa 100644 --- a/include/cru/ui/mapper/Mapper.hpp +++ b/include/cru/ui/mapper/Mapper.hpp @@ -5,6 +5,7 @@ #include "cru/common/Exception.hpp" #include "cru/xml/XmlNode.hpp" +#include #include #include @@ -41,6 +42,9 @@ class CRU_UI_API MapperBase : public Object { template class CRU_UI_API BasicMapper : public MapperBase { public: + static_assert(std::is_default_constructible_v, + "T must be default constructible."); + BasicMapper() : MapperBase(typeid(T)) {} CRU_DELETE_COPY(BasicMapper) @@ -49,7 +53,7 @@ class CRU_UI_API BasicMapper : public MapperBase { ~BasicMapper() override = default; virtual bool SupportMapFromString() { return false; } - virtual std::unique_ptr MapFromString(String str) { + virtual T MapFromString(String str) { if (!SupportMapFromString()) { throw Exception(u"This mapper does not support map from string."); } @@ -61,7 +65,7 @@ class CRU_UI_API BasicMapper : public MapperBase { virtual bool XmlElementIsOfThisType(xml::XmlElementNode* node) { return false; } - std::unique_ptr MapFromXml(xml::XmlElementNode* node) { + T MapFromXml(xml::XmlElementNode* node) { if (!SupportMapFromXml()) { throw new Exception(u"This mapper does not support map from xml."); } @@ -74,9 +78,7 @@ class CRU_UI_API BasicMapper : public MapperBase { } protected: - virtual std::unique_ptr DoMapFromString(String str) { return nullptr; } - virtual std::unique_ptr DoMapFromXml(xml::XmlElementNode* node) { - return nullptr; - } + virtual T DoMapFromString(String str) { return {}; } + virtual T DoMapFromXml(xml::XmlElementNode* node) { return {}; } }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/PointMapper.hpp b/include/cru/ui/mapper/PointMapper.hpp index 5641af01..b1837fe1 100644 --- a/include/cru/ui/mapper/PointMapper.hpp +++ b/include/cru/ui/mapper/PointMapper.hpp @@ -12,7 +12,7 @@ class CRU_UI_API PointMapper : public BasicMapper { bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; protected: - std::unique_ptr DoMapFromString(String str) override; - std::unique_ptr DoMapFromXml(xml::XmlElementNode* node) override; + Point DoMapFromString(String str) override; + Point DoMapFromXml(xml::XmlElementNode* node) override; }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/SizeMapper.hpp b/include/cru/ui/mapper/SizeMapper.hpp index 20558bf4..6ab4b97d 100644 --- a/include/cru/ui/mapper/SizeMapper.hpp +++ b/include/cru/ui/mapper/SizeMapper.hpp @@ -12,7 +12,7 @@ class CRU_UI_API SizeMapper : public BasicMapper { bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; protected: - std::unique_ptr DoMapFromString(String str) override; - std::unique_ptr DoMapFromXml(xml::XmlElementNode* node) override; + Size DoMapFromString(String str) override; + Size DoMapFromXml(xml::XmlElementNode* node) override; }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/ThicknessMapper.hpp b/include/cru/ui/mapper/ThicknessMapper.hpp index 68bbcf49..4ffbeb9b 100644 --- a/include/cru/ui/mapper/ThicknessMapper.hpp +++ b/include/cru/ui/mapper/ThicknessMapper.hpp @@ -16,7 +16,7 @@ class CRU_UI_API ThicknessMapper : public BasicMapper { bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; protected: - std::unique_ptr DoMapFromString(String str) override; - std::unique_ptr DoMapFromXml(xml::XmlElementNode* node) override; + Thickness DoMapFromString(String str) override; + Thickness DoMapFromXml(xml::XmlElementNode* node) override; }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/style/BorderStyleMapper.hpp b/include/cru/ui/mapper/style/BorderStyleMapper.hpp deleted file mode 100644 index 40a3e883..00000000 --- a/include/cru/ui/mapper/style/BorderStyleMapper.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include "../Mapper.hpp" -#include "cru/ui/style/ApplyBorderStyleInfo.hpp" -#include "cru/xml/XmlNode.hpp" - -namespace cru::ui::mapper::style { -class CRU_UI_API BorderStyleMapper - : BasicMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(BorderStyleMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - protected: - std::unique_ptr DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/style/ApplyBorderStyleInfo.hpp b/include/cru/ui/style/ApplyBorderStyleInfo.hpp index 3923ebb4..7ae5b2c5 100644 --- a/include/cru/ui/style/ApplyBorderStyleInfo.hpp +++ b/include/cru/ui/style/ApplyBorderStyleInfo.hpp @@ -5,9 +5,10 @@ namespace cru::ui::style { struct ApplyBorderStyleInfo { + ApplyBorderStyleInfo() = default; + explicit ApplyBorderStyleInfo( - std::optional> border_brush = - std::nullopt, + std::optional> border_brush, std::optional border_thickness = std::nullopt, std::optional border_radius = std::nullopt, std::optional> -- cgit v1.2.3