diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-12-15 21:27:33 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-12-15 21:27:33 +0800 |
| commit | c77072d586bf7aca58e6465ceab3d11a0be0021f (patch) | |
| tree | 83605be90fd32104ef74bbd1d84d900aaf0271ce /include | |
| parent | bc3fa9650699046f3a87a620282ee43f26b2fa75 (diff) | |
| download | cru-c77072d586bf7aca58e6465ceab3d11a0be0021f.tar.gz cru-c77072d586bf7aca58e6465ceab3d11a0be0021f.tar.bz2 cru-c77072d586bf7aca58e6465ceab3d11a0be0021f.zip | |
Clean up mapper codes.
Diffstat (limited to 'include')
33 files changed, 183 insertions, 587 deletions
diff --git a/include/cru/base/xml/XmlNode.h b/include/cru/base/xml/XmlNode.h index e9090b40..02358fb4 100644 --- a/include/cru/base/xml/XmlNode.h +++ b/include/cru/base/xml/XmlNode.h @@ -69,6 +69,10 @@ class CRU_BASE_API XmlElementNode : public XmlNode { public: std::string GetTag() const { return tag_; } + bool HasTag(std::string_view tag, bool case_sensitive = false) { + return case_sensitive ? tag_ == tag + : cru::string::CaseInsensitiveCompare(tag_, tag) == 0; + } void SetTag(std::string tag) { tag_ = std::move(tag); } const std::unordered_map<std::string, std::string>& GetAttributes() const { return attributes_; diff --git a/include/cru/ui/mapper/BorderStyleMapper.h b/include/cru/ui/mapper/BorderStyleMapper.h index fd84b0b0..41bbeff5 100644 --- a/include/cru/ui/mapper/BorderStyleMapper.h +++ b/include/cru/ui/mapper/BorderStyleMapper.h @@ -1,20 +1,25 @@ #pragma once +#include "../style/ApplyBorderStyleInfo.h" #include "Mapper.h" -#include "cru/ui/style/ApplyBorderStyleInfo.h" -#include "cru/base/xml/XmlNode.h" + +#include <cru/base/xml/XmlNode.h> namespace cru::ui::mapper { +/** + * Example xml: + * ```xml + * <BorderStyle> + * <Thickness value="1" /> + * <CornerRadius all="1" /> + * <Brush><Color value=""/></Brush> + * <Brush name="foreground"><Color value="transparent"/></Brush> + * <Brush name="background"><Color value="#eeeeeeff"/></Brush> + * </BorderStyle> + * ``` + */ class CRU_UI_API BorderStyleMapper : public BasicMapper<ui::style::ApplyBorderStyleInfo> { - 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; + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(BorderStyle, + ui::style::ApplyBorderStyleInfo) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/BrushMapper.h b/include/cru/ui/mapper/BrushMapper.h index 3972d6ff..3917e3f8 100644 --- a/include/cru/ui/mapper/BrushMapper.h +++ b/include/cru/ui/mapper/BrushMapper.h @@ -1,20 +1,20 @@ #pragma once #include "Mapper.h" -#include "cru/base/Base.h" -#include "cru/platform/graphics/Brush.h" -#include "cru/base/xml/XmlNode.h" + +#include <cru/base/xml/XmlNode.h> +#include <cru/platform/graphics/Brush.h> namespace cru::ui::mapper { +/** + * Color element can be used as a brush. + * + * Or example xml: + * ```xml + * <Brush><Color value="black"/></Brush> + * ``` + */ class BrushMapper : public BasicSharedPtrMapper<platform::graphics::IBrush> { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(BrushMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - protected: - std::shared_ptr<platform::graphics::IBrush> DoMapFromXml( - xml::XmlElementNode* node) override; + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT( + std::shared_ptr<platform::graphics::IBrush>) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/ColorMapper.h b/include/cru/ui/mapper/ColorMapper.h index 9555bf5a..2715e292 100644 --- a/include/cru/ui/mapper/ColorMapper.h +++ b/include/cru/ui/mapper/ColorMapper.h @@ -1,19 +1,12 @@ #pragma once #include "Mapper.h" -#include "cru/base/xml/XmlNode.h" + +#include <cru/base/xml/XmlNode.h> +#include <cru/platform/Color.h> namespace cru::ui::mapper { class CRU_UI_API ColorMapper : public BasicMapper<Color> { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(ColorMapper) - - public: - bool SupportMapFromString() override { return true; } - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - protected: - Color DoMapFromString(std::string str) override; - Color DoMapFromXml(xml::XmlElementNode* node) override; + CRU_UI_DECLARE_CAN_MAP_FROM_STRING(Color) + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(Color, Color) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/CornerRadiusMapper.h b/include/cru/ui/mapper/CornerRadiusMapper.h index b8998a1b..eb8867af 100644 --- a/include/cru/ui/mapper/CornerRadiusMapper.h +++ b/include/cru/ui/mapper/CornerRadiusMapper.h @@ -4,14 +4,6 @@ namespace cru::ui::mapper { class CRU_UI_API CornerRadiusMapper : public BasicMapper<CornerRadius> { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(CornerRadiusMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - protected: - CornerRadius DoMapFromXml(xml::XmlElementNode* node) override; + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(CornerRadius, CornerRadius) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/CursorMapper.h b/include/cru/ui/mapper/CursorMapper.h index 4d55f849..2b7a899d 100644 --- a/include/cru/ui/mapper/CursorMapper.h +++ b/include/cru/ui/mapper/CursorMapper.h @@ -1,21 +1,13 @@ #pragma once #include "Mapper.h" -#include "cru/platform/gui/Cursor.h" -#include "cru/base/xml/XmlNode.h" -namespace cru::ui::mapper { -class CRU_UI_API CursorMapper : public BasicSharedPtrMapper<platform::gui::ICursor> { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(CursorMapper); - - public: - bool SupportMapFromString() override { return true; } - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; +#include <cru/platform/gui/Cursor.h> - protected: - std::shared_ptr<platform::gui::ICursor> DoMapFromString(std::string str) override; - std::shared_ptr<platform::gui::ICursor> DoMapFromXml( - xml::XmlElementNode* node) override; +namespace cru::ui::mapper { +class CRU_UI_API CursorMapper + : public BasicSharedPtrMapper<platform::gui::ICursor> { + CRU_UI_DECLARE_CAN_MAP_FROM_STRING(std::shared_ptr<platform::gui::ICursor>) + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG( + Cursor, std::shared_ptr<platform::gui::ICursor>) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/FontMapper.h b/include/cru/ui/mapper/FontMapper.h index f8b10047..738f63ef 100644 --- a/include/cru/ui/mapper/FontMapper.h +++ b/include/cru/ui/mapper/FontMapper.h @@ -1,19 +1,11 @@ #pragma once #include "Mapper.h" -#include "cru/base/Base.h" -#include "cru/platform/graphics/Font.h" + +#include <cru/platform/graphics/Font.h> namespace cru::ui::mapper { class FontMapper : public BasicSharedPtrMapper<platform::graphics::IFont> { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(FontMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - protected: - std::shared_ptr<platform::graphics::IFont> DoMapFromXml( - xml::XmlElementNode* node) override; + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG( + Font, std::shared_ptr<platform::graphics::IFont>) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/Mapper.h b/include/cru/ui/mapper/Mapper.h index 164329d3..68ad2ab0 100644 --- a/include/cru/ui/mapper/Mapper.h +++ b/include/cru/ui/mapper/Mapper.h @@ -1,49 +1,35 @@ #pragma once #include "../Base.h" -#include "cru/base/ClonePtr.h" -#include "cru/base/xml/XmlNode.h" +#include <cru/base/Base.h> +#include <cru/base/ClonePtr.h> +#include <cru/base/xml/XmlNode.h> #include <memory> #include <type_traits> #include <typeindex> -#include <typeinfo> namespace cru::ui::mapper { -template <typename T> -class BasicMapper; +class CRU_UI_API MapException : public Exception { + public: + using Exception::Exception; +}; class CRU_UI_API MapperBase : public Object { public: explicit MapperBase(std::type_index type_index); - ~MapperBase() override = default; public: std::type_index GetTypeIndex() const { return type_index_; } - template <typename T> - BasicMapper<T>* StaticCast() { - return static_cast<BasicMapper<T>*>(this); - } - - template <typename T> - BasicMapper<T>* DynamicCast() { - return dynamic_cast<BasicMapper<T>*>(this); - } - virtual bool SupportMapFromString() { return false; } virtual bool SupportMapFromXml() { return false; } - virtual bool XmlElementIsOfThisType(xml::XmlElementNode* node); - - protected: - void SetAllowedTags(std::vector<std::string> allowed_tags) { - allowed_tags_ = std::move(allowed_tags); + virtual bool XmlElementIsOfThisType(xml::XmlElementNode* node) { + return false; } private: std::type_index type_index_; - - std::vector<std::string> allowed_tags_; }; template <typename T> @@ -54,11 +40,6 @@ class CRU_UI_API BasicMapper : public MapperBase { BasicMapper() : MapperBase(typeid(T)) {} - CRU_DELETE_COPY(BasicMapper) - CRU_DELETE_MOVE(BasicMapper) - - ~BasicMapper() override = default; - virtual T MapFromString(std::string str) { if (!SupportMapFromString()) { throw Exception("This mapper does not support map from string."); @@ -90,3 +71,28 @@ using BasicSharedPtrMapper = BasicMapper<std::shared_ptr<T>>; template <typename T> using BasicClonePtrMapper = BasicMapper<ClonePtr<T>>; } // namespace cru::ui::mapper + +#define CRU_UI_DECLARE_CAN_MAP_FROM_STRING(type) \ + public: \ + bool SupportMapFromString() override { return true; } \ + \ + protected: \ + type DoMapFromString(std::string str) override; + +#define CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT(type) \ + public: \ + bool SupportMapFromXml() override { return true; } \ + bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; \ + \ + protected: \ + type DoMapFromXml(xml::XmlElementNode* node) override; + +#define CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(xml_tag, type) \ + public: \ + bool SupportMapFromXml() override { return true; } \ + bool XmlElementIsOfThisType(xml::XmlElementNode* node) override { \ + return node->HasTag(#xml_tag); \ + } \ + \ + protected: \ + type DoMapFromXml(xml::XmlElementNode* node) override; diff --git a/include/cru/ui/mapper/MeasureLengthMapper.h b/include/cru/ui/mapper/MeasureLengthMapper.h index 347d69ae..b7ef8e97 100644 --- a/include/cru/ui/mapper/MeasureLengthMapper.h +++ b/include/cru/ui/mapper/MeasureLengthMapper.h @@ -5,16 +5,8 @@ namespace cru::ui::mapper { class CRU_UI_API MeasureLengthMapper : public BasicMapper<render::MeasureLength> { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(MeasureLengthMapper) - - public: - bool SupportMapFromString() override { return true; } - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - protected: - render::MeasureLength DoMapFromString(std::string str) override; - render::MeasureLength DoMapFromXml(xml::XmlElementNode* node) override; + CRU_UI_DECLARE_CAN_MAP_FROM_STRING(render::MeasureLength) + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(MeasureLength, + render::MeasureLength) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/PointMapper.h b/include/cru/ui/mapper/PointMapper.h index b3c97df0..65e2af13 100644 --- a/include/cru/ui/mapper/PointMapper.h +++ b/include/cru/ui/mapper/PointMapper.h @@ -3,16 +3,7 @@ namespace cru::ui::mapper { class CRU_UI_API PointMapper : public BasicMapper<Point> { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(PointMapper) - - public: - bool SupportMapFromString() override { return true; } - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - protected: - Point DoMapFromString(std::string str) override; - Point DoMapFromXml(xml::XmlElementNode* node) override; + CRU_UI_DECLARE_CAN_MAP_FROM_STRING(Point) + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(Point, Point) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/SizeMapper.h b/include/cru/ui/mapper/SizeMapper.h index 4d781ee3..5c6eed2e 100644 --- a/include/cru/ui/mapper/SizeMapper.h +++ b/include/cru/ui/mapper/SizeMapper.h @@ -3,16 +3,7 @@ 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: - Size DoMapFromString(std::string str) override; - Size DoMapFromXml(xml::XmlElementNode* node) override; + CRU_UI_DECLARE_CAN_MAP_FROM_STRING(Size) + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(Size, Size) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/StringMapper.h b/include/cru/ui/mapper/StringMapper.h index e41ee0f9..63045eef 100644 --- a/include/cru/ui/mapper/StringMapper.h +++ b/include/cru/ui/mapper/StringMapper.h @@ -5,16 +5,7 @@ namespace cru::ui::mapper { class CRU_UI_API StringMapper : public BasicMapper<std::string> { - public: - StringMapper(); - ~StringMapper(); - - public: - bool SupportMapFromString() override { return true; } - bool SupportMapFromXml() override { return true; } - - protected: - std::string DoMapFromString(std::string str) override; - std::string DoMapFromXml(xml::XmlElementNode* node) override; + CRU_UI_DECLARE_CAN_MAP_FROM_STRING(std::string) + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(String, std::string) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/ThicknessMapper.h b/include/cru/ui/mapper/ThicknessMapper.h index 25885cbf..57b57a2c 100644 --- a/include/cru/ui/mapper/ThicknessMapper.h +++ b/include/cru/ui/mapper/ThicknessMapper.h @@ -1,22 +1,9 @@ #pragma once #include "Mapper.h" -#include "../Base.h" -#include "cru/base/Base.h" -#include "cru/base/xml/XmlNode.h" - namespace cru::ui::mapper { class CRU_UI_API ThicknessMapper : public BasicMapper<Thickness> { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(ThicknessMapper) - - public: - bool SupportMapFromString() override { return true; } - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - protected: - Thickness DoMapFromString(std::string str) override; - Thickness DoMapFromXml(xml::XmlElementNode* node) override; + CRU_UI_DECLARE_CAN_MAP_FROM_STRING(Thickness) + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(Thickness, Thickness) }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/mapper/style/AndConditionMapper.h b/include/cru/ui/mapper/style/AndConditionMapper.h deleted file mode 100644 index 5569e0fc..00000000 --- a/include/cru/ui/mapper/style/AndConditionMapper.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "IConditionMapper.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API AndConditionMapper - : public BasicClonePtrMapper<ui::style::AndCondition>, - public virtual IConditionMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(AndConditionMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - ClonePtr<ui::style::Condition> MapConditionFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::AndCondition> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/BorderStylerMapper.h b/include/cru/ui/mapper/style/BorderStylerMapper.h deleted file mode 100644 index c1554255..00000000 --- a/include/cru/ui/mapper/style/BorderStylerMapper.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/ui/mapper/style/IStylerMapper.h" -#include "cru/ui/style/Styler.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API BorderStylerMapper - : public BasicClonePtrMapper<ui::style::BorderStyler>, - public virtual IStylerMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(BorderStylerMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - ClonePtr<ui::style::Styler> MapStylerFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::BorderStyler> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/CheckedConditionMapper.h b/include/cru/ui/mapper/style/CheckedConditionMapper.h deleted file mode 100644 index 87d892a7..00000000 --- a/include/cru/ui/mapper/style/CheckedConditionMapper.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "IConditionMapper.h" -#include "cru/ui/style/Condition.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API CheckedConditionMapper - : public BasicClonePtrMapper<ui::style::CheckedCondition>, - public virtual IConditionMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(CheckedConditionMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - ClonePtr<ui::style::Condition> MapConditionFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::CheckedCondition> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/ClickStateConditionMapper.h b/include/cru/ui/mapper/style/ClickStateConditionMapper.h deleted file mode 100644 index 13c72a36..00000000 --- a/include/cru/ui/mapper/style/ClickStateConditionMapper.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "IConditionMapper.h" -#include "cru/ui/style/Condition.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API ClickStateConditionMapper - : public BasicClonePtrMapper<ui::style::ClickStateCondition>, - public virtual IConditionMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(ClickStateConditionMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - ClonePtr<ui::style::Condition> MapConditionFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - public: - ClonePtr<ui::style::ClickStateCondition> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/ConditionMapper.h b/include/cru/ui/mapper/style/ConditionMapper.h new file mode 100644 index 00000000..a7bddefb --- /dev/null +++ b/include/cru/ui/mapper/style/ConditionMapper.h @@ -0,0 +1,41 @@ +#pragma once +#include "../../Base.h" +#include "../../style/Condition.h" +#include "../Mapper.h" + +#include <cru/base/ClonePtr.h> +#include <cru/base/xml/XmlNode.h> + +namespace cru::ui::mapper::style { +using ui::style::Condition; + +struct CRU_UI_API IConditionMapper : virtual Interface { + virtual bool XmlElementIsOfThisType(xml::XmlElementNode* node) = 0; + virtual ClonePtr<Condition> MapConditionFromXml( + xml::XmlElementNode* node) = 0; +}; + +#define CRU_DECLARE_CONDITION_MAPPER(condition_name) \ + using ui::style::condition_name##Condition; \ + class CRU_UI_API condition_name##ConditionMapper \ + : public BasicClonePtrMapper<condition_name##Condition>, \ + public virtual IConditionMapper { \ + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG( \ + condition_name##Condition, ClonePtr<condition_name##Condition>) \ + \ + ClonePtr<Condition> MapConditionFromXml( \ + xml::XmlElementNode* node) override { \ + return MapFromXml(node); \ + } \ + }; + +CRU_DECLARE_CONDITION_MAPPER(No) +CRU_DECLARE_CONDITION_MAPPER(And) +CRU_DECLARE_CONDITION_MAPPER(Or) +CRU_DECLARE_CONDITION_MAPPER(ClickState) +CRU_DECLARE_CONDITION_MAPPER(Checked) +CRU_DECLARE_CONDITION_MAPPER(Focus) +CRU_DECLARE_CONDITION_MAPPER(Hover) + +#undef CRU_DECLARE_CONDITION_MAPPER +} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/ContentBrushStylerMapper.h b/include/cru/ui/mapper/style/ContentBrushStylerMapper.h deleted file mode 100644 index d15eb28a..00000000 --- a/include/cru/ui/mapper/style/ContentBrushStylerMapper.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "IStylerMapper.h" - -namespace cru::ui::mapper::style { -class ContentBrushStylerMapper - : public BasicClonePtrMapper<ui::style::ContentBrushStyler>, - public virtual IStylerMapper { - public: - ContentBrushStylerMapper(); - ~ContentBrushStylerMapper() override; - - public: - bool SupportMapFromXml() override { return true; } - - ClonePtr<ui::style::Styler> MapStylerFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::ContentBrushStyler> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/CursorStylerMapper.h b/include/cru/ui/mapper/style/CursorStylerMapper.h deleted file mode 100644 index 54ade7f0..00000000 --- a/include/cru/ui/mapper/style/CursorStylerMapper.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "cru/ui/mapper/style/IStylerMapper.h" -#include "cru/ui/style/Styler.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API CursorStylerMapper - : public BasicClonePtrMapper<ui::style::CursorStyler>, - public virtual IStylerMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(CursorStylerMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - ClonePtr<ui::style::Styler> MapStylerFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::CursorStyler> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/FocusConditionMapper.h b/include/cru/ui/mapper/style/FocusConditionMapper.h deleted file mode 100644 index e18150cf..00000000 --- a/include/cru/ui/mapper/style/FocusConditionMapper.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "IConditionMapper.h" -#include "cru/ui/style/Condition.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API FocusConditionMapper - : public BasicClonePtrMapper<ui::style::FocusCondition>, - public virtual IConditionMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(FocusConditionMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - ClonePtr<ui::style::Condition> MapConditionFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::FocusCondition> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/FontStylerMapper.h b/include/cru/ui/mapper/style/FontStylerMapper.h deleted file mode 100644 index 6a79eb99..00000000 --- a/include/cru/ui/mapper/style/FontStylerMapper.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "IStylerMapper.h" - -namespace cru::ui::mapper::style { -class FontStylerMapper : public BasicClonePtrMapper<ui::style::FontStyler>, - public virtual IStylerMapper { - public: - FontStylerMapper(); - ~FontStylerMapper() override; - - public: - bool SupportMapFromXml() override { return true; } - - ClonePtr<ui::style::Styler> MapStylerFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::FontStyler> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/HoverConditionMapper.h b/include/cru/ui/mapper/style/HoverConditionMapper.h deleted file mode 100644 index faa889e7..00000000 --- a/include/cru/ui/mapper/style/HoverConditionMapper.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "IConditionMapper.h" -#include "cru/ui/style/Condition.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API HoverConditionMapper - : public BasicClonePtrMapper<ui::style::HoverCondition>, - public virtual IConditionMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(HoverConditionMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - ClonePtr<ui::style::Condition> MapConditionFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::HoverCondition> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/IConditionMapper.h b/include/cru/ui/mapper/style/IConditionMapper.h deleted file mode 100644 index 27c09e82..00000000 --- a/include/cru/ui/mapper/style/IConditionMapper.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "../../Base.h" -#include "cru/base/ClonePtr.h" -#include "cru/ui/mapper/Mapper.h" -#include "cru/ui/style/Condition.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -struct CRU_UI_API IConditionMapper : virtual Interface { - bool XmlElementIsOfThisType(xml::XmlElementNode* node) { - return dynamic_cast<MapperBase*>(this)->XmlElementIsOfThisType(node); - } - - virtual ClonePtr<ui::style::Condition> MapConditionFromXml( - xml::XmlElementNode* node) = 0; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/IStylerMapper.h b/include/cru/ui/mapper/style/IStylerMapper.h deleted file mode 100644 index ce9c4243..00000000 --- a/include/cru/ui/mapper/style/IStylerMapper.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "../../Base.h" -#include "cru/base/ClonePtr.h" -#include "cru/ui/mapper/Mapper.h" -#include "cru/ui/style/Styler.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -struct CRU_UI_API IStylerMapper : virtual Interface { - bool XmlElementIsOfThisType(xml::XmlElementNode* node) { - return dynamic_cast<MapperBase*>(this)->XmlElementIsOfThisType(node); - } - - virtual ClonePtr<ui::style::Styler> MapStylerFromXml( - xml::XmlElementNode* node) = 0; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/MarginStylerMapper.h b/include/cru/ui/mapper/style/MarginStylerMapper.h deleted file mode 100644 index b20452a9..00000000 --- a/include/cru/ui/mapper/style/MarginStylerMapper.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "cru/ui/mapper/style/IStylerMapper.h" -#include "cru/ui/style/Styler.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API MarginStylerMapper - : public BasicClonePtrMapper<ui::style::MarginStyler>, - public virtual IStylerMapper { - public: - MarginStylerMapper(); - ~MarginStylerMapper(); - - public: - bool SupportMapFromXml() override { return true; } - - ClonePtr<ui::style::Styler> MapStylerFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::MarginStyler> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/NoConditionMapper.h b/include/cru/ui/mapper/style/NoConditionMapper.h deleted file mode 100644 index 8acb79e0..00000000 --- a/include/cru/ui/mapper/style/NoConditionMapper.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "IConditionMapper.h" -#include "cru/base/Base.h" -#include "cru/base/ClonePtr.h" -#include "cru/ui/style/Condition.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API NoConditionMapper - : public BasicClonePtrMapper<ui::style::NoCondition>, - public virtual IConditionMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(NoConditionMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - ClonePtr<ui::style::Condition> MapConditionFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::NoCondition> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/OrConditionMapper.h b/include/cru/ui/mapper/style/OrConditionMapper.h deleted file mode 100644 index 0aa5b241..00000000 --- a/include/cru/ui/mapper/style/OrConditionMapper.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "IConditionMapper.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API OrConditionMapper - : public BasicClonePtrMapper<ui::style::OrCondition>, - public virtual IConditionMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(OrConditionMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - ClonePtr<ui::style::Condition> MapConditionFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::OrCondition> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/PaddingStylerMapper.h b/include/cru/ui/mapper/style/PaddingStylerMapper.h deleted file mode 100644 index bf0c5650..00000000 --- a/include/cru/ui/mapper/style/PaddingStylerMapper.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "cru/ui/mapper/style/IStylerMapper.h" -#include "cru/ui/style/Styler.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API PaddingStylerMapper - : public BasicClonePtrMapper<ui::style::PaddingStyler>, - public virtual IStylerMapper { - public: - PaddingStylerMapper(); - ~PaddingStylerMapper(); - - public: - bool SupportMapFromXml() override { return true; } - - ClonePtr<ui::style::Styler> MapStylerFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::PaddingStyler> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/PreferredSizeStylerMapper.h b/include/cru/ui/mapper/style/PreferredSizeStylerMapper.h deleted file mode 100644 index ee4f5705..00000000 --- a/include/cru/ui/mapper/style/PreferredSizeStylerMapper.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "../Mapper.h" -#include "cru/ui/mapper/style/IStylerMapper.h" -#include "cru/ui/style/Styler.h" - -namespace cru::ui::mapper::style { -class CRU_UI_API PreferredSizeStylerMapper - : public BasicClonePtrMapper<ui::style::PreferredSizeStyler>, - public virtual IStylerMapper { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(PreferredSizeStylerMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - ClonePtr<ui::style::Styler> MapStylerFromXml( - xml::XmlElementNode* node) override { - return MapFromXml(node); - } - - protected: - ClonePtr<ui::style::PreferredSizeStyler> DoMapFromXml( - xml::XmlElementNode* node) override; -}; -} // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/StyleRuleMapper.h b/include/cru/ui/mapper/style/StyleRuleMapper.h index 37790058..8ca47cce 100644 --- a/include/cru/ui/mapper/style/StyleRuleMapper.h +++ b/include/cru/ui/mapper/style/StyleRuleMapper.h @@ -1,24 +1,11 @@ #pragma once +#include "../../style/StyleRule.h" #include "../Mapper.h" -#include "cru/base/Base.h" -#include "cru/base/ClonePtr.h" -#include "cru/ui/style/StyleRule.h" -#include "cru/base/xml/XmlNode.h" namespace cru::ui::mapper::style { -class CRU_UI_API StyleRuleMapper : public BasicClonePtrMapper<ui::style::StyleRule> { - private: - constexpr static auto kLogTag = "StyleRuleMapper"; - - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(StyleRuleMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - protected: - ClonePtr<ui::style::StyleRule> DoMapFromXml( - xml::XmlElementNode* node) override; +class CRU_UI_API StyleRuleMapper + : public BasicClonePtrMapper<ui::style::StyleRule> { + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(StyleRule, + ClonePtr<ui::style::StyleRule>) }; } // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/StyleRuleSetMapper.h b/include/cru/ui/mapper/style/StyleRuleSetMapper.h index 6b848458..06084e73 100644 --- a/include/cru/ui/mapper/style/StyleRuleSetMapper.h +++ b/include/cru/ui/mapper/style/StyleRuleSetMapper.h @@ -1,21 +1,12 @@ #pragma once -#include <memory> #include "../../style/StyleRuleSet.h" #include "../Mapper.h" namespace cru::ui::mapper::style { class CRU_UI_API StyleRuleSetMapper : public BasicSharedPtrMapper<ui::style::StyleRuleSet> { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(StyleRuleSetMapper) - - public: - bool SupportMapFromXml() override { return true; } - bool XmlElementIsOfThisType(xml::XmlElementNode* node) override; - - protected: - std::shared_ptr<ui::style::StyleRuleSet> DoMapFromXml( - xml::XmlElementNode* node) override; + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG( + StyleRuleSet, std::shared_ptr<ui::style::StyleRuleSet>) }; ; } // namespace cru::ui::mapper::style diff --git a/include/cru/ui/mapper/style/StylerMapper.h b/include/cru/ui/mapper/style/StylerMapper.h new file mode 100644 index 00000000..569684ab --- /dev/null +++ b/include/cru/ui/mapper/style/StylerMapper.h @@ -0,0 +1,39 @@ +#pragma once +#include "../../Base.h" +#include "cru/base/ClonePtr.h" +#include "cru/base/xml/XmlNode.h" +#include "cru/ui/mapper/Mapper.h" +#include "cru/ui/style/Styler.h" + +namespace cru::ui::mapper::style { +using ui::style::Styler; +using cru::ui::style::ApplyBorderStyleInfo; + +struct CRU_UI_API IStylerMapper : virtual Interface { + virtual bool XmlElementIsOfThisType(xml::XmlElementNode* node) = 0; + virtual ClonePtr<Styler> MapStylerFromXml(xml::XmlElementNode* node) = 0; +}; + +#define CRU_DECLARE_STYLER_MAPPER(styler_name) \ + using ui::style::styler_name##Styler; \ + class CRU_UI_API styler_name##StylerMapper \ + : public BasicClonePtrMapper<styler_name##Styler>, \ + public virtual IStylerMapper { \ + CRU_UI_DECLARE_CAN_MAP_FROM_XML_ELEMENT_TAG(styler_name##Styler, \ + ClonePtr<styler_name##Styler>) \ + \ + ClonePtr<Styler> MapStylerFromXml(xml::XmlElementNode* node) override { \ + return MapFromXml(node); \ + } \ + }; + +CRU_DECLARE_STYLER_MAPPER(Border) +CRU_DECLARE_STYLER_MAPPER(ContentBrush) +CRU_DECLARE_STYLER_MAPPER(Cursor) +CRU_DECLARE_STYLER_MAPPER(Font) +CRU_DECLARE_STYLER_MAPPER(Margin) +CRU_DECLARE_STYLER_MAPPER(Padding) +CRU_DECLARE_STYLER_MAPPER(PreferredSize) + +#undef CRU_DECLARE_STYLER_MAPPER +} // namespace cru::ui::mapper::style |
