aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/base/xml/XmlNode.h4
-rw-r--r--include/cru/ui/mapper/BorderStyleMapper.h29
-rw-r--r--include/cru/ui/mapper/BrushMapper.h26
-rw-r--r--include/cru/ui/mapper/ColorMapper.h17
-rw-r--r--include/cru/ui/mapper/CornerRadiusMapper.h10
-rw-r--r--include/cru/ui/mapper/CursorMapper.h22
-rw-r--r--include/cru/ui/mapper/FontMapper.h16
-rw-r--r--include/cru/ui/mapper/Mapper.h62
-rw-r--r--include/cru/ui/mapper/MeasureLengthMapper.h14
-rw-r--r--include/cru/ui/mapper/PointMapper.h13
-rw-r--r--include/cru/ui/mapper/SizeMapper.h13
-rw-r--r--include/cru/ui/mapper/StringMapper.h13
-rw-r--r--include/cru/ui/mapper/ThicknessMapper.h17
-rw-r--r--include/cru/ui/mapper/style/AndConditionMapper.h25
-rw-r--r--include/cru/ui/mapper/style/BorderStylerMapper.h28
-rw-r--r--include/cru/ui/mapper/style/CheckedConditionMapper.h26
-rw-r--r--include/cru/ui/mapper/style/ClickStateConditionMapper.h26
-rw-r--r--include/cru/ui/mapper/style/ConditionMapper.h41
-rw-r--r--include/cru/ui/mapper/style/ContentBrushStylerMapper.h25
-rw-r--r--include/cru/ui/mapper/style/CursorStylerMapper.h26
-rw-r--r--include/cru/ui/mapper/style/FocusConditionMapper.h26
-rw-r--r--include/cru/ui/mapper/style/FontStylerMapper.h24
-rw-r--r--include/cru/ui/mapper/style/HoverConditionMapper.h26
-rw-r--r--include/cru/ui/mapper/style/IConditionMapper.h17
-rw-r--r--include/cru/ui/mapper/style/IStylerMapper.h17
-rw-r--r--include/cru/ui/mapper/style/MarginStylerMapper.h26
-rw-r--r--include/cru/ui/mapper/style/NoConditionMapper.h29
-rw-r--r--include/cru/ui/mapper/style/OrConditionMapper.h25
-rw-r--r--include/cru/ui/mapper/style/PaddingStylerMapper.h26
-rw-r--r--include/cru/ui/mapper/style/PreferredSizeStylerMapper.h26
-rw-r--r--include/cru/ui/mapper/style/StyleRuleMapper.h23
-rw-r--r--include/cru/ui/mapper/style/StyleRuleSetMapper.h13
-rw-r--r--include/cru/ui/mapper/style/StylerMapper.h39
-rw-r--r--src/base/xml/XmlNode.cpp14
-rw-r--r--src/ui/CMakeLists.txt16
-rw-r--r--src/ui/mapper/BorderStyleMapper.cpp19
-rw-r--r--src/ui/mapper/BrushMapper.cpp36
-rw-r--r--src/ui/mapper/ColorMapper.cpp6
-rw-r--r--src/ui/mapper/CornerRadiusMapper.cpp5
-rw-r--r--src/ui/mapper/CursorMapper.cpp4
-rw-r--r--src/ui/mapper/FontMapper.cpp4
-rw-r--r--src/ui/mapper/Mapper.cpp10
-rw-r--r--src/ui/mapper/MapperRegistry.cpp22
-rw-r--r--src/ui/mapper/MeasureLengthMapper.cpp5
-rw-r--r--src/ui/mapper/PointMapper.cpp4
-rw-r--r--src/ui/mapper/SizeMapper.cpp4
-rw-r--r--src/ui/mapper/StringMapper.cpp4
-rw-r--r--src/ui/mapper/ThicknessMapper.cpp7
-rw-r--r--src/ui/mapper/style/AndConditionMapper.cpp31
-rw-r--r--src/ui/mapper/style/BorderStylerMapper.cpp34
-rw-r--r--src/ui/mapper/style/CheckedConditionMapper.cpp24
-rw-r--r--src/ui/mapper/style/ClickStateConditionMapper.cpp35
-rw-r--r--src/ui/mapper/style/ConditionMapper.cpp107
-rw-r--r--src/ui/mapper/style/ContentBrushStylerMapper.cpp30
-rw-r--r--src/ui/mapper/style/CursorStylerMapper.cpp27
-rw-r--r--src/ui/mapper/style/FocusConditionMapper.cpp24
-rw-r--r--src/ui/mapper/style/FontStylerMapper.cpp25
-rw-r--r--src/ui/mapper/style/HoverConditionMapper.cpp25
-rw-r--r--src/ui/mapper/style/MarginStylerMapper.cpp24
-rw-r--r--src/ui/mapper/style/NoConditionMapper.cpp14
-rw-r--r--src/ui/mapper/style/OrConditionMapper.cpp31
-rw-r--r--src/ui/mapper/style/PaddingStylerMapper.cpp27
-rw-r--r--src/ui/mapper/style/PreferredSizeStylerMapper.cpp31
-rw-r--r--src/ui/mapper/style/StyleRuleMapper.cpp8
-rw-r--r--src/ui/mapper/style/StyleRuleSetMapper.cpp4
-rw-r--r--src/ui/mapper/style/StylerMapper.cpp127
66 files changed, 464 insertions, 1094 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
diff --git a/src/base/xml/XmlNode.cpp b/src/base/xml/XmlNode.cpp
index d3e7369b..a4ce9635 100644
--- a/src/base/xml/XmlNode.cpp
+++ b/src/base/xml/XmlNode.cpp
@@ -5,25 +5,27 @@
namespace cru::xml {
XmlElementNode* XmlNode::AsElement() {
- return static_cast<XmlElementNode*>(this);
+ return IsElementNode() ? static_cast<XmlElementNode*>(this) : nullptr;
}
-XmlTextNode* XmlNode::AsText() { return static_cast<XmlTextNode*>(this); }
+XmlTextNode* XmlNode::AsText() {
+ return IsTextNode() ? static_cast<XmlTextNode*>(this) : nullptr;
+}
XmlCommentNode* XmlNode::AsComment() {
- return static_cast<XmlCommentNode*>(this);
+ return IsCommentNode() ? static_cast<XmlCommentNode*>(this) : nullptr;
}
const XmlElementNode* XmlNode::AsElement() const {
- return static_cast<const XmlElementNode*>(this);
+ return IsElementNode() ? static_cast<const XmlElementNode*>(this) : nullptr;
}
const XmlTextNode* XmlNode::AsText() const {
- return static_cast<const XmlTextNode*>(this);
+ return IsTextNode() ? static_cast<const XmlTextNode*>(this) : nullptr;
}
const XmlCommentNode* XmlNode::AsComment() const {
- return static_cast<const XmlCommentNode*>(this);
+ return IsCommentNode() ? static_cast<const XmlCommentNode*>(this) : nullptr;
}
XmlElementNode::~XmlElementNode() {
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 0dd5bc32..7e0beecd 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -39,20 +39,8 @@ add_library(CruUi
mapper/SizeMapper.cpp
mapper/StringMapper.cpp
mapper/ThicknessMapper.cpp
- mapper/style/AndConditionMapper.cpp
- mapper/style/BorderStylerMapper.cpp
- mapper/style/CheckedConditionMapper.cpp
- mapper/style/ClickStateConditionMapper.cpp
- mapper/style/ContentBrushStylerMapper.cpp
- mapper/style/CursorStylerMapper.cpp
- mapper/style/FocusConditionMapper.cpp
- mapper/style/FontStylerMapper.cpp
- mapper/style/HoverConditionMapper.cpp
- mapper/style/MarginStylerMapper.cpp
- mapper/style/NoConditionMapper.cpp
- mapper/style/OrConditionMapper.cpp
- mapper/style/PaddingStylerMapper.cpp
- mapper/style/PreferredSizeStylerMapper.cpp
+ mapper/style/ConditionMapper.cpp
+ mapper/style/StylerMapper.cpp
mapper/style/StyleRuleMapper.cpp
mapper/style/StyleRuleSetMapper.cpp
render/BorderRenderObject.cpp
diff --git a/src/ui/mapper/BorderStyleMapper.cpp b/src/ui/mapper/BorderStyleMapper.cpp
index d4889457..a49a9ab8 100644
--- a/src/ui/mapper/BorderStyleMapper.cpp
+++ b/src/ui/mapper/BorderStyleMapper.cpp
@@ -1,26 +1,23 @@
#include "cru/ui/mapper/BorderStyleMapper.h"
#include "cru/base/StringUtil.h"
+#include "cru/base/xml/XmlNode.h"
#include "cru/platform/graphics/Brush.h"
#include "cru/ui/mapper/MapperRegistry.h"
#include "cru/ui/style/ApplyBorderStyleInfo.h"
-#include "cru/base/xml/XmlNode.h"
namespace cru::ui::mapper {
using namespace xml;
+using cru::string::CaseInsensitiveCompare;
using ui::style::ApplyBorderStyleInfo;
-bool BorderStyleMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "BorderStyle") ==
- 0;
-}
-
ApplyBorderStyleInfo BorderStyleMapper::DoMapFromXml(
xml::XmlElementNode* node) {
ApplyBorderStyleInfo result;
for (auto child : node->GetChildren()) {
- if (child->GetType() == XmlNode::Type::Text) {
- } else {
+ if (child->IsTextNode()) {
+ throw MapException("BorderStyle can't have text nodes.");
+ } else if (child->IsElementNode()) {
auto c = child->AsElement();
auto thickness_mapper =
MapperRegistry::GetInstance()->GetMapper<Thickness>();
@@ -37,12 +34,12 @@ ApplyBorderStyleInfo BorderStyleMapper::DoMapFromXml(
auto brush = brush_mapper->MapFromXml(c);
auto name = c->GetOptionalAttributeValueCaseInsensitive("name");
if (name) {
- if (cru::string::CaseInsensitiveCompare(*name, "foreground") == 0) {
+ if (CaseInsensitiveCompare(*name, "foreground") == 0) {
result.foreground_brush = std::move(brush);
- } else if (cru::string::CaseInsensitiveCompare(*name, "background") ==
- 0) {
+ } else if (CaseInsensitiveCompare(*name, "background") == 0) {
result.background_brush = std::move(brush);
} else {
+ throw MapException("Invalid name of brush in BorderStyle.");
}
} else {
result.border_brush = std::move(brush);
diff --git a/src/ui/mapper/BrushMapper.cpp b/src/ui/mapper/BrushMapper.cpp
index 6a3d7941..d6fb8e4c 100644
--- a/src/ui/mapper/BrushMapper.cpp
+++ b/src/ui/mapper/BrushMapper.cpp
@@ -1,10 +1,9 @@
#include "cru/ui/mapper/BrushMapper.h"
-#include "cru/base/StringUtil.h"
#include "cru/base/xml/XmlNode.h"
-#include "cru/platform/Color.h"
#include "cru/platform/graphics/Brush.h"
#include "cru/platform/graphics/Factory.h"
#include "cru/platform/gui/UiApplication.h"
+#include "cru/ui/mapper/Mapper.h"
#include "cru/ui/mapper/MapperRegistry.h"
#include <memory>
@@ -12,31 +11,34 @@
namespace cru::ui::mapper {
bool BrushMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
auto color_mapper = MapperRegistry::GetInstance()->GetMapper<Color>();
- return color_mapper->XmlElementIsOfThisType(node) ||
- cru::string::CaseInsensitiveCompare(node->GetTag(), "Brush") == 0;
+ return color_mapper->XmlElementIsOfThisType(node) || node->HasTag("Brush");
}
std::shared_ptr<platform::graphics::IBrush> BrushMapper::DoMapFromXml(
xml::XmlElementNode* node) {
+ auto graphics_factory =
+ platform::gui::IUiApplication::GetInstance()->GetGraphicsFactory();
auto color_mapper = MapperRegistry::GetInstance()->GetMapper<Color>();
- Color color = colors::transparent;
+ try {
+ auto color = color_mapper->MapFromXml(node);
+ return graphics_factory->CreateSolidColorBrush(color);
+ } catch (const MapException&) {
+ }
- if (color_mapper->XmlElementIsOfThisType(node)) {
- color = color_mapper->MapFromXml(node);
- } else {
- for (auto child : node->GetChildren()) {
- if (child->IsElementNode()) {
- auto c = child->AsElement();
- if (color_mapper->XmlElementIsOfThisType(node)) {
- color = color_mapper->MapFromXml(node);
- }
+ for (auto child : node->GetChildren()) {
+ if (auto c = child->AsElement()) {
+ if (color_mapper->XmlElementIsOfThisType(node)) {
+ auto color = color_mapper->MapFromXml(node);
+ return graphics_factory->CreateSolidColorBrush(color);
+ } else {
+ throw MapException("Invalid child element of Brush.");
}
+ } else if (child->IsTextNode()) {
+ throw MapException("Text node is not allowed in Brush.");
}
}
- return platform::gui::IUiApplication::GetInstance()
- ->GetGraphicsFactory()
- ->CreateSolidColorBrush(color);
+ throw MapException("Brush doesn't have content.");
}
} // namespace cru::ui::mapper
diff --git a/src/ui/mapper/ColorMapper.cpp b/src/ui/mapper/ColorMapper.cpp
index 515eba97..9283b828 100644
--- a/src/ui/mapper/ColorMapper.cpp
+++ b/src/ui/mapper/ColorMapper.cpp
@@ -2,14 +2,10 @@
#include "cru/base/StringUtil.h"
namespace cru::ui::mapper {
-bool ColorMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "Color") == 0;
-}
-
Color ColorMapper::DoMapFromString(std::string str) {
auto c = Color::Parse(str);
if (!c) {
- throw Exception("Invalid color value.");
+ throw Exception("Invalid color string.");
}
return *c;
}
diff --git a/src/ui/mapper/CornerRadiusMapper.cpp b/src/ui/mapper/CornerRadiusMapper.cpp
index defb9d21..ca89c186 100644
--- a/src/ui/mapper/CornerRadiusMapper.cpp
+++ b/src/ui/mapper/CornerRadiusMapper.cpp
@@ -2,11 +2,6 @@
#include "cru/ui/mapper/MapperRegistry.h"
namespace cru::ui::mapper {
-bool CornerRadiusMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "CornerRadius") ==
- 0;
-}
-
CornerRadius CornerRadiusMapper::DoMapFromXml(xml::XmlElementNode* node) {
auto point_mapper = MapperRegistry::GetInstance()->GetMapper<Point>();
CornerRadius result;
diff --git a/src/ui/mapper/CursorMapper.cpp b/src/ui/mapper/CursorMapper.cpp
index 6dfa942f..c7a8d4fc 100644
--- a/src/ui/mapper/CursorMapper.cpp
+++ b/src/ui/mapper/CursorMapper.cpp
@@ -6,10 +6,6 @@ namespace cru::ui::mapper {
using cru::platform::gui::ICursor;
using cru::platform::gui::SystemCursorType;
-bool CursorMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "Cursor") == 0;
-}
-
std::shared_ptr<ICursor> CursorMapper::DoMapFromString(std::string str) {
if (str.empty()) return nullptr;
diff --git a/src/ui/mapper/FontMapper.cpp b/src/ui/mapper/FontMapper.cpp
index 8f83116d..7747475d 100644
--- a/src/ui/mapper/FontMapper.cpp
+++ b/src/ui/mapper/FontMapper.cpp
@@ -4,10 +4,6 @@
#include "cru/platform/gui/UiApplication.h"
namespace cru::ui::mapper {
-bool FontMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "font") == 0;
-}
-
std::shared_ptr<platform::graphics::IFont> FontMapper::DoMapFromXml(
xml::XmlElementNode* node) {
auto font_family_attr = node->GetOptionalAttributeValue("family");
diff --git a/src/ui/mapper/Mapper.cpp b/src/ui/mapper/Mapper.cpp
index 47e783c9..40653118 100644
--- a/src/ui/mapper/Mapper.cpp
+++ b/src/ui/mapper/Mapper.cpp
@@ -1,18 +1,8 @@
#include "cru/ui/mapper/Mapper.h"
-#include "cru/base/StringUtil.h"
#include <typeindex>
namespace cru::ui::mapper {
MapperBase::MapperBase(std::type_index type_index)
: type_index_(std::move(type_index)) {}
-
-bool MapperBase::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- for (const auto& tag : allowed_tags_) {
- if (cru::string::CaseInsensitiveCompare(node->GetTag(), tag) == 0) {
- return true;
- }
- }
- return false;
-}
} // namespace cru::ui::mapper
diff --git a/src/ui/mapper/MapperRegistry.cpp b/src/ui/mapper/MapperRegistry.cpp
index d877f14a..34c475bb 100644
--- a/src/ui/mapper/MapperRegistry.cpp
+++ b/src/ui/mapper/MapperRegistry.cpp
@@ -10,25 +10,13 @@
#include "cru/ui/mapper/SizeMapper.h"
#include "cru/ui/mapper/StringMapper.h"
#include "cru/ui/mapper/ThicknessMapper.h"
-#include "cru/ui/mapper/style/AndConditionMapper.h"
-#include "cru/ui/mapper/style/BorderStylerMapper.h"
-#include "cru/ui/mapper/style/CheckedConditionMapper.h"
-#include "cru/ui/mapper/style/ClickStateConditionMapper.h"
-#include "cru/ui/mapper/style/ContentBrushStylerMapper.h"
-#include "cru/ui/mapper/style/CursorStylerMapper.h"
-#include "cru/ui/mapper/style/FocusConditionMapper.h"
-#include "cru/ui/mapper/style/FontStylerMapper.h"
-#include "cru/ui/mapper/style/HoverConditionMapper.h"
-#include "cru/ui/mapper/style/MarginStylerMapper.h"
-#include "cru/ui/mapper/style/NoConditionMapper.h"
-#include "cru/ui/mapper/style/OrConditionMapper.h"
-#include "cru/ui/mapper/style/PaddingStylerMapper.h"
-#include "cru/ui/mapper/style/PreferredSizeStylerMapper.h"
+#include "cru/ui/mapper/style/ConditionMapper.h"
#include "cru/ui/mapper/style/StyleRuleMapper.h"
#include "cru/ui/mapper/style/StyleRuleSetMapper.h"
+#include "cru/ui/mapper/style/StylerMapper.h"
namespace cru::ui::mapper {
-MapperRegistry *MapperRegistry::GetInstance() {
+MapperRegistry* MapperRegistry::GetInstance() {
static MapperRegistry instance;
return &instance;
}
@@ -71,7 +59,7 @@ MapperRegistry::~MapperRegistry() {
}
}
-void MapperRegistry::RegisterMapper(MapperBase *mapper) {
+void MapperRegistry::RegisterMapper(MapperBase* mapper) {
if (std::find(mapper_list_.cbegin(), mapper_list_.cend(), mapper) !=
mapper_list_.cend()) {
throw Exception("This mapper is already registered.");
@@ -80,7 +68,7 @@ void MapperRegistry::RegisterMapper(MapperBase *mapper) {
mapper_list_.push_back(mapper);
}
-void MapperRegistry::UnregisterMapper(MapperBase *mapper) {
+void MapperRegistry::UnregisterMapper(MapperBase* mapper) {
auto it = std::find(mapper_list_.begin(), mapper_list_.end(), mapper);
if (it == mapper_list_.end()) {
throw Exception("This mapper is not registered.");
diff --git a/src/ui/mapper/MeasureLengthMapper.cpp b/src/ui/mapper/MeasureLengthMapper.cpp
index d36afb0e..b695ebae 100644
--- a/src/ui/mapper/MeasureLengthMapper.cpp
+++ b/src/ui/mapper/MeasureLengthMapper.cpp
@@ -3,11 +3,6 @@
#include "cru/ui/render/MeasureRequirement.h"
namespace cru::ui::mapper {
-bool MeasureLengthMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "MeasureLength") ==
- 0;
-}
-
render::MeasureLength MeasureLengthMapper::DoMapFromString(std::string str) {
if (cru::string::CaseInsensitiveCompare(str, "notspecified") == 0) {
return render::MeasureLength::NotSpecified();
diff --git a/src/ui/mapper/PointMapper.cpp b/src/ui/mapper/PointMapper.cpp
index a63e1b9e..3bfe03e2 100644
--- a/src/ui/mapper/PointMapper.cpp
+++ b/src/ui/mapper/PointMapper.cpp
@@ -2,10 +2,6 @@
#include "cru/base/StringUtil.h"
namespace cru::ui::mapper {
-bool PointMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "Point") == 0;
-}
-
Point PointMapper::DoMapFromString(std::string str) {
std::vector<float> values = cru::string::ParseToNumberList<float>(str);
if (values.size() == 2) {
diff --git a/src/ui/mapper/SizeMapper.cpp b/src/ui/mapper/SizeMapper.cpp
index d07d937d..6161f226 100644
--- a/src/ui/mapper/SizeMapper.cpp
+++ b/src/ui/mapper/SizeMapper.cpp
@@ -2,10 +2,6 @@
#include "cru/base/StringUtil.h"
namespace cru::ui::mapper {
-bool SizeMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "Size") == 0;
-}
-
Size SizeMapper::DoMapFromString(std::string str) {
std::vector<float> values = cru::string::ParseToNumberList<float>(str);
if (values.size() == 2) {
diff --git a/src/ui/mapper/StringMapper.cpp b/src/ui/mapper/StringMapper.cpp
index 24b79ff4..a021de3a 100644
--- a/src/ui/mapper/StringMapper.cpp
+++ b/src/ui/mapper/StringMapper.cpp
@@ -2,10 +2,6 @@
#include "cru/base/xml/XmlNode.h"
namespace cru::ui::mapper {
-StringMapper::StringMapper() { SetAllowedTags({"String"}); }
-
-StringMapper::~StringMapper() {}
-
std::string StringMapper::DoMapFromString(std::string str) {
return std::move(str);
}
diff --git a/src/ui/mapper/ThicknessMapper.cpp b/src/ui/mapper/ThicknessMapper.cpp
index 2dc6efdc..ca062ddc 100644
--- a/src/ui/mapper/ThicknessMapper.cpp
+++ b/src/ui/mapper/ThicknessMapper.cpp
@@ -1,12 +1,9 @@
#include "cru/ui/mapper/ThicknessMapper.h"
+#include "cru/base/Base.h"
#include "cru/base/StringUtil.h"
#include "cru/base/xml/XmlNode.h"
namespace cru::ui::mapper {
-bool ThicknessMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "Thickness") == 0;
-}
-
Thickness ThicknessMapper::DoMapFromString(std::string str) {
std::vector<float> values = cru::string::ParseToNumberList<float>(str);
if (values.size() == 4) {
@@ -22,7 +19,7 @@ Thickness ThicknessMapper::DoMapFromString(std::string str) {
Thickness ThicknessMapper::DoMapFromXml(xml::XmlElementNode* node) {
auto value_attr = node->GetOptionalAttributeValueCaseInsensitive("value");
- if (!value_attr) return {};
+ if (!value_attr) throw Exception("Thickness must have a 'value' attribute.");
return DoMapFromString(*value_attr);
}
} // namespace cru::ui::mapper
diff --git a/src/ui/mapper/style/AndConditionMapper.cpp b/src/ui/mapper/style/AndConditionMapper.cpp
deleted file mode 100644
index ad996a4e..00000000
--- a/src/ui/mapper/style/AndConditionMapper.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include "cru/ui/mapper/style/AndConditionMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/ui/mapper/MapperRegistry.h"
-#include "cru/ui/mapper/style/IConditionMapper.h"
-#include "cru/ui/style/Condition.h"
-#include "cru/base/xml/XmlNode.h"
-
-namespace cru::ui::mapper::style {
-bool AndConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode *node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "AndCondition") == 0;
-}
-
-ClonePtr<ui::style::AndCondition> AndConditionMapper::DoMapFromXml(
- xml::XmlElementNode *node) {
- std::vector<ClonePtr<ui::style::Condition>> conditions;
- auto condition_mappers =
- MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>();
- for (auto child : node->GetChildren()) {
- if (child->GetType() == xml::XmlNode::Type::Element) {
- auto c = child->AsElement();
- for (auto mapper : condition_mappers) {
- if (mapper->XmlElementIsOfThisType(c)) {
- conditions.push_back(mapper->MapConditionFromXml(c));
- break;
- }
- }
- }
- }
- return ui::style::AndCondition::Create(std::move(conditions));
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/BorderStylerMapper.cpp b/src/ui/mapper/style/BorderStylerMapper.cpp
deleted file mode 100644
index 33358b28..00000000
--- a/src/ui/mapper/style/BorderStylerMapper.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "cru/ui/mapper/style/BorderStylerMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/ui/mapper/MapperRegistry.h"
-#include "cru/ui/style/ApplyBorderStyleInfo.h"
-#include "cru/ui/style/Styler.h"
-#include "cru/base/xml/XmlNode.h"
-
-namespace cru::ui::mapper::style {
-using cru::ui::style::ApplyBorderStyleInfo;
-using cru::ui::style::BorderStyler;
-
-bool BorderStylerMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "BorderStyler") == 0;
-}
-
-ClonePtr<BorderStyler> BorderStylerMapper::DoMapFromXml(
- xml::XmlElementNode* node) {
- auto border_style_mapper =
- MapperRegistry::GetInstance()->GetMapper<ApplyBorderStyleInfo>();
-
- ApplyBorderStyleInfo border_style;
-
- for (auto child : node->GetChildren()) {
- if (child->GetType() == xml::XmlElementNode::Type::Element) {
- auto child_element = child->AsElement();
- if (border_style_mapper->XmlElementIsOfThisType(child_element)) {
- border_style = border_style_mapper->MapFromXml(child_element);
- }
- }
- }
-
- return BorderStyler::Create(std::move(border_style));
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/CheckedConditionMapper.cpp b/src/ui/mapper/style/CheckedConditionMapper.cpp
deleted file mode 100644
index 9e93cbea..00000000
--- a/src/ui/mapper/style/CheckedConditionMapper.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "cru/ui/mapper/style/CheckedConditionMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/base/StringUtil.h"
-#include "cru/ui/style/Condition.h"
-#include "cru/base/xml/XmlNode.h"
-
-namespace cru::ui::mapper::style {
-bool CheckedConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(),
- "CheckedCondition") == 0;
-}
-
-ClonePtr<ui::style::CheckedCondition> CheckedConditionMapper::DoMapFromXml(
- xml::XmlElementNode* node) {
- auto value = node->GetAttributeValueCaseInsensitive("value");
- if (cru::string::CaseInsensitiveCompare(value, "true") == 0) {
- return ui::style::CheckedCondition::Create(true);
- } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) {
- return ui::style::CheckedCondition::Create(false);
- } else {
- throw Exception("Invalid value for CheckedCondition: " + value);
- }
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/ClickStateConditionMapper.cpp b/src/ui/mapper/style/ClickStateConditionMapper.cpp
deleted file mode 100644
index accfdf0a..00000000
--- a/src/ui/mapper/style/ClickStateConditionMapper.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "cru/ui/mapper/style/ClickStateConditionMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/base/StringUtil.h"
-#include "cru/ui/helper/ClickDetector.h"
-#include "cru/ui/style/Condition.h"
-
-namespace cru::ui::mapper::style {
-bool ClickStateConditionMapper::XmlElementIsOfThisType(
- xml::XmlElementNode *node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(),
- "ClickStateCondition") == 0;
-}
-
-ClonePtr<ui::style::ClickStateCondition>
-ClickStateConditionMapper::DoMapFromXml(xml::XmlElementNode *node) {
- auto state = helper::ClickState::None;
- auto value_attr = node->GetOptionalAttributeValueCaseInsensitive("value");
- if (value_attr) {
- if (cru::string::CaseInsensitiveCompare(*value_attr, "none") == 0) {
- state = helper::ClickState::None;
- } else if (cru::string::CaseInsensitiveCompare(*value_attr, "hover") == 0) {
- state = helper::ClickState::Hover;
- } else if (cru::string::CaseInsensitiveCompare(*value_attr, "press") == 0) {
- state = helper::ClickState::Press;
- } else if (cru::string::CaseInsensitiveCompare(*value_attr,
- "pressinactive") == 0) {
- state = helper::ClickState::PressInactive;
- } else {
- throw Exception("Unknown click state: " + *value_attr);
- }
- }
-
- return ui::style::ClickStateCondition::Create(state);
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/ConditionMapper.cpp b/src/ui/mapper/style/ConditionMapper.cpp
new file mode 100644
index 00000000..ce41a70a
--- /dev/null
+++ b/src/ui/mapper/style/ConditionMapper.cpp
@@ -0,0 +1,107 @@
+#include "cru/ui/mapper/style/ConditionMapper.h"
+#include "cru/base/ClonePtr.h"
+#include "cru/base/xml/XmlNode.h"
+#include "cru/ui/mapper/MapperRegistry.h"
+
+namespace cru::ui::mapper::style {
+ClonePtr<NoCondition> NoConditionMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ return NoCondition::Create();
+}
+
+ClonePtr<AndCondition> AndConditionMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ std::vector<ClonePtr<Condition>> conditions;
+ auto condition_mappers =
+ MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>();
+ for (auto child : node->GetChildren()) {
+ if (child->GetType() == xml::XmlNode::Type::Element) {
+ auto c = child->AsElement();
+ for (auto mapper : condition_mappers) {
+ if (mapper->XmlElementIsOfThisType(c)) {
+ conditions.push_back(mapper->MapConditionFromXml(c));
+ break;
+ }
+ }
+ }
+ }
+ return AndCondition::Create(std::move(conditions));
+}
+
+ClonePtr<OrCondition> OrConditionMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ std::vector<ClonePtr<Condition>> conditions;
+ auto condition_mappers =
+ MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>();
+ for (auto child : node->GetChildren()) {
+ if (child->GetType() == xml::XmlNode::Type::Element) {
+ auto c = child->AsElement();
+ for (auto mapper : condition_mappers) {
+ if (mapper->XmlElementIsOfThisType(c)) {
+ conditions.push_back(mapper->MapConditionFromXml(c));
+ break;
+ }
+ }
+ }
+ }
+ return OrCondition::Create(std::move(conditions));
+}
+
+ClonePtr<ClickStateCondition>
+ClickStateConditionMapper::DoMapFromXml(xml::XmlElementNode* node) {
+ auto state = helper::ClickState::None;
+ auto value_attr = node->GetOptionalAttributeValueCaseInsensitive("value");
+ if (value_attr) {
+ if (cru::string::CaseInsensitiveCompare(*value_attr, "none") == 0) {
+ state = helper::ClickState::None;
+ } else if (cru::string::CaseInsensitiveCompare(*value_attr, "hover") == 0) {
+ state = helper::ClickState::Hover;
+ } else if (cru::string::CaseInsensitiveCompare(*value_attr, "press") == 0) {
+ state = helper::ClickState::Press;
+ } else if (cru::string::CaseInsensitiveCompare(*value_attr,
+ "pressinactive") == 0) {
+ state = helper::ClickState::PressInactive;
+ } else {
+ throw Exception("Unknown click state: " + *value_attr);
+ }
+ }
+
+ return ClickStateCondition::Create(state);
+}
+
+ClonePtr<CheckedCondition> CheckedConditionMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto value = node->GetAttributeValueCaseInsensitive("value");
+ if (cru::string::CaseInsensitiveCompare(value, "true") == 0) {
+ return CheckedCondition::Create(true);
+ } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) {
+ return CheckedCondition::Create(false);
+ } else {
+ throw Exception("Invalid value for CheckedCondition: " + value);
+ }
+}
+
+ClonePtr<FocusCondition> FocusConditionMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto value = node->GetAttributeValueCaseInsensitive("value");
+ if (cru::string::CaseInsensitiveCompare(value, "true") == 0) {
+ return FocusCondition::Create(true);
+ } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) {
+ return FocusCondition::Create(false);
+ } else {
+ throw Exception("Invalid value for FocusCondition: " + value);
+ }
+}
+
+ClonePtr<HoverCondition> HoverConditionMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto value = node->GetAttributeValueCaseInsensitive("value");
+ if (cru::string::CaseInsensitiveCompare(value, "true") == 0) {
+ return HoverCondition::Create(true);
+ } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) {
+ return HoverCondition::Create(false);
+ } else {
+ throw Exception("Invalid value for HoverCondition: " + value);
+ }
+}
+} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/ContentBrushStylerMapper.cpp b/src/ui/mapper/style/ContentBrushStylerMapper.cpp
deleted file mode 100644
index 1ab91be0..00000000
--- a/src/ui/mapper/style/ContentBrushStylerMapper.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "cru/ui/mapper/style/ContentBrushStylerMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/platform/graphics/Brush.h"
-#include "cru/ui/mapper/MapperRegistry.h"
-#include "cru/ui/style/Styler.h"
-#include "cru/base/xml/XmlNode.h"
-
-namespace cru::ui::mapper::style {
-ContentBrushStylerMapper::ContentBrushStylerMapper() {
- SetAllowedTags({"ContentBrushStyler"});
-}
-
-ContentBrushStylerMapper::~ContentBrushStylerMapper() {}
-
-ClonePtr<ui::style::ContentBrushStyler>
-ContentBrushStylerMapper::DoMapFromXml(xml::XmlElementNode* node) {
- auto brush_mapper = MapperRegistry::GetInstance()
- ->GetSharedPtrMapper<platform::graphics::IBrush>();
-
- std::shared_ptr<platform::graphics::IBrush> brush;
-
- for (auto child_node : node->GetChildren()) {
- if (child_node->IsElementNode()) {
- brush = brush_mapper->MapFromXml(child_node->AsElement());
- }
- }
-
- return ui::style::ContentBrushStyler::Create(std::move(brush));
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/CursorStylerMapper.cpp b/src/ui/mapper/style/CursorStylerMapper.cpp
deleted file mode 100644
index e5051ce0..00000000
--- a/src/ui/mapper/style/CursorStylerMapper.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "cru/ui/mapper/style/CursorStylerMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/platform/gui/Cursor.h"
-#include "cru/ui/mapper/MapperRegistry.h"
-#include "cru/ui/style/Styler.h"
-
-namespace cru::ui::mapper::style {
-bool CursorStylerMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "CursorStyler") == 0;
-}
-
-ClonePtr<ui::style::CursorStyler> CursorStylerMapper::DoMapFromXml(
- xml::XmlElementNode* node) {
- auto cursor_mapper =
- MapperRegistry::GetInstance()->GetSharedPtrMapper<platform::gui::ICursor>();
- std::shared_ptr<platform::gui::ICursor> cursor;
-
- for (auto child : node->GetChildren()) {
- if (child->GetType() == xml::XmlNode::Type::Element &&
- cursor_mapper->XmlElementIsOfThisType(child->AsElement())) {
- cursor = cursor_mapper->MapFromXml(child->AsElement());
- }
- }
-
- return ui::style::CursorStyler::Create(cursor);
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/FocusConditionMapper.cpp b/src/ui/mapper/style/FocusConditionMapper.cpp
deleted file mode 100644
index 08d0c992..00000000
--- a/src/ui/mapper/style/FocusConditionMapper.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "cru/ui/mapper/style/FocusConditionMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/base/StringUtil.h"
-#include "cru/ui/style/Condition.h"
-#include "cru/base/xml/XmlNode.h"
-
-namespace cru::ui::mapper::style {
-bool FocusConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(),
- "FocusCondition") == 0;
-}
-
-ClonePtr<ui::style::FocusCondition> FocusConditionMapper::DoMapFromXml(
- xml::XmlElementNode* node) {
- auto value = node->GetAttributeValueCaseInsensitive("value");
- if (cru::string::CaseInsensitiveCompare(value, "true") == 0) {
- return ui::style::FocusCondition::Create(true);
- } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) {
- return ui::style::FocusCondition::Create(false);
- } else {
- throw Exception("Invalid value for FocusCondition: " + value);
- }
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/FontStylerMapper.cpp b/src/ui/mapper/style/FontStylerMapper.cpp
deleted file mode 100644
index ac8051a3..00000000
--- a/src/ui/mapper/style/FontStylerMapper.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "cru/ui/mapper/style/FontStylerMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/ui/mapper/MapperRegistry.h"
-
-namespace cru::ui::mapper::style {
-FontStylerMapper::FontStylerMapper() { SetAllowedTags({"FontStyler"}); }
-
-FontStylerMapper::~FontStylerMapper() {}
-
-ClonePtr<ui::style::FontStyler> FontStylerMapper::DoMapFromXml(
- xml::XmlElementNode* node) {
- auto font_mapper = MapperRegistry::GetInstance()
- ->GetSharedPtrMapper<platform::graphics::IFont>();
-
- std::shared_ptr<platform::graphics::IFont> font;
-
- for (auto child_node : node->GetChildren()) {
- if (child_node->IsElementNode()) {
- font = font_mapper->MapFromXml(child_node->AsElement());
- }
- }
-
- return ui::style::FontStyler::Create(std::move(font));
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/HoverConditionMapper.cpp b/src/ui/mapper/style/HoverConditionMapper.cpp
deleted file mode 100644
index 7797ad7c..00000000
--- a/src/ui/mapper/style/HoverConditionMapper.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "cru/ui/mapper/style/HoverConditionMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/base/StringUtil.h"
-#include "cru/ui/style/Condition.h"
-
-namespace cru::ui::mapper::style {
-using namespace cru::ui::style;
-
-bool HoverConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(),
- "HoverCondition") == 0;
-}
-
-ClonePtr<HoverCondition> HoverConditionMapper::DoMapFromXml(
- xml::XmlElementNode* node) {
- auto value = node->GetAttributeValueCaseInsensitive("value");
- if (cru::string::CaseInsensitiveCompare(value, "true") == 0) {
- return ui::style::HoverCondition::Create(true);
- } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) {
- return ui::style::HoverCondition::Create(false);
- } else {
- throw Exception("Invalid value for HoverCondition: " + value);
- }
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/MarginStylerMapper.cpp b/src/ui/mapper/style/MarginStylerMapper.cpp
deleted file mode 100644
index 2343dd3e..00000000
--- a/src/ui/mapper/style/MarginStylerMapper.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "cru/ui/mapper/style/MarginStylerMapper.h"
-#include "cru/ui/mapper/MapperRegistry.h"
-#include "cru/ui/render/MeasureRequirement.h"
-#include "cru/ui/style/Styler.h"
-
-namespace cru::ui::mapper::style {
-MarginStylerMapper::MarginStylerMapper() { SetAllowedTags({"MarginStyler"}); }
-
-MarginStylerMapper::~MarginStylerMapper() {}
-
-ClonePtr<ui::style::MarginStyler> MarginStylerMapper::DoMapFromXml(
- xml::XmlElementNode* node) {
- Thickness thickness;
-
- auto thickness_mapper = MapperRegistry::GetInstance()->GetMapper<Thickness>();
-
- auto value_attribute = node->GetOptionalAttributeValueCaseInsensitive("value");
- if (value_attribute) {
- thickness = thickness_mapper->MapFromString(*value_attribute);
- }
-
- return ui::style::MarginStyler::Create(thickness);
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/NoConditionMapper.cpp b/src/ui/mapper/style/NoConditionMapper.cpp
deleted file mode 100644
index 3ee9981e..00000000
--- a/src/ui/mapper/style/NoConditionMapper.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "cru/ui/mapper/style/NoConditionMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/base/xml/XmlNode.h"
-
-namespace cru::ui::mapper::style {
-bool NoConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "NoCondition") == 0;
-}
-
-ClonePtr<ui::style::NoCondition> NoConditionMapper::DoMapFromXml(
- xml::XmlElementNode* node) {
- return ui::style::NoCondition::Create();
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/OrConditionMapper.cpp b/src/ui/mapper/style/OrConditionMapper.cpp
deleted file mode 100644
index 5591bab0..00000000
--- a/src/ui/mapper/style/OrConditionMapper.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include "cru/ui/mapper/style/OrConditionMapper.h"
-#include "cru/base/ClonePtr.h"
-#include "cru/ui/mapper/MapperRegistry.h"
-#include "cru/ui/mapper/style/IConditionMapper.h"
-#include "cru/ui/style/Condition.h"
-#include "cru/base/xml/XmlNode.h"
-
-namespace cru::ui::mapper::style {
-bool OrConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode *node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "OrCondition") == 0;
-}
-
-ClonePtr<ui::style::OrCondition> OrConditionMapper::DoMapFromXml(
- xml::XmlElementNode *node) {
- std::vector<ClonePtr<ui::style::Condition>> conditions;
- auto condition_mappers =
- MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>();
- for (auto child : node->GetChildren()) {
- if (child->GetType() == xml::XmlNode::Type::Element) {
- auto c = child->AsElement();
- for (auto mapper : condition_mappers) {
- if (mapper->XmlElementIsOfThisType(c)) {
- conditions.push_back(mapper->MapConditionFromXml(c));
- break;
- }
- }
- }
- }
- return ui::style::OrCondition::Create(std::move(conditions));
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/PaddingStylerMapper.cpp b/src/ui/mapper/style/PaddingStylerMapper.cpp
deleted file mode 100644
index 60c40c3d..00000000
--- a/src/ui/mapper/style/PaddingStylerMapper.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "cru/ui/mapper/style/PaddingStylerMapper.h"
-#include "cru/ui/mapper/MapperRegistry.h"
-#include "cru/ui/render/MeasureRequirement.h"
-#include "cru/ui/style/Styler.h"
-
-namespace cru::ui::mapper::style {
-PaddingStylerMapper::PaddingStylerMapper() {
- SetAllowedTags({"PaddingStyler"});
-}
-
-PaddingStylerMapper::~PaddingStylerMapper() {}
-
-ClonePtr<ui::style::PaddingStyler> PaddingStylerMapper::DoMapFromXml(
- xml::XmlElementNode* node) {
- Thickness thickness;
-
- auto thickness_mapper = MapperRegistry::GetInstance()->GetMapper<Thickness>();
-
- auto value_attribute =
- node->GetOptionalAttributeValueCaseInsensitive("value");
- if (value_attribute) {
- thickness = thickness_mapper->MapFromString(*value_attribute);
- }
-
- return ui::style::PaddingStyler::Create(thickness);
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/PreferredSizeStylerMapper.cpp b/src/ui/mapper/style/PreferredSizeStylerMapper.cpp
deleted file mode 100644
index 0603f5c4..00000000
--- a/src/ui/mapper/style/PreferredSizeStylerMapper.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include "cru/ui/mapper/style/PreferredSizeStylerMapper.h"
-#include "cru/ui/mapper/MapperRegistry.h"
-#include "cru/ui/render/MeasureRequirement.h"
-#include "cru/ui/style/Styler.h"
-
-namespace cru::ui::mapper::style {
-bool PreferredSizeStylerMapper::XmlElementIsOfThisType(
- xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "PreferredSizeStyler") == 0;
-}
-
-ClonePtr<ui::style::PreferredSizeStyler>
-PreferredSizeStylerMapper::DoMapFromXml(xml::XmlElementNode* node) {
- render::MeasureSize size;
-
- auto measure_length_mapper =
- MapperRegistry::GetInstance()->GetMapper<render::MeasureLength>();
-
- auto width_attribute = node->GetOptionalAttributeValueCaseInsensitive("width");
- if (width_attribute) {
- size.width = measure_length_mapper->MapFromString(*width_attribute);
- }
-
- auto height_attribute = node->GetOptionalAttributeValueCaseInsensitive("height");
- if (height_attribute) {
- size.height = measure_length_mapper->MapFromString(*height_attribute);
- }
-
- return ui::style::PreferredSizeStyler::Create(size);
-}
-} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/StyleRuleMapper.cpp b/src/ui/mapper/style/StyleRuleMapper.cpp
index 30fedb16..3c1819a1 100644
--- a/src/ui/mapper/style/StyleRuleMapper.cpp
+++ b/src/ui/mapper/style/StyleRuleMapper.cpp
@@ -1,17 +1,13 @@
#include "cru/ui/mapper/style/StyleRuleMapper.h"
#include "cru/base/ClonePtr.h"
#include "cru/ui/mapper/MapperRegistry.h"
-#include "cru/ui/mapper/style/IConditionMapper.h"
-#include "cru/ui/mapper/style/IStylerMapper.h"
-#include "cru/ui/style/Condition.h"
+#include "cru/ui/mapper/style/ConditionMapper.h"
+#include "cru/ui/mapper/style/StylerMapper.h"
#include "cru/ui/style/StyleRule.h"
#include "cru/ui/style/Styler.h"
namespace cru::ui::mapper::style {
using namespace ui::style;
-bool StyleRuleMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "StyleRule") == 0;
-}
ClonePtr<ui::style::StyleRule> StyleRuleMapper::DoMapFromXml(
xml::XmlElementNode* node) {
diff --git a/src/ui/mapper/style/StyleRuleSetMapper.cpp b/src/ui/mapper/style/StyleRuleSetMapper.cpp
index 19a628ad..f4fd957b 100644
--- a/src/ui/mapper/style/StyleRuleSetMapper.cpp
+++ b/src/ui/mapper/style/StyleRuleSetMapper.cpp
@@ -7,10 +7,6 @@
namespace cru::ui::mapper::style {
using namespace cru::ui::style;
-bool StyleRuleSetMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return cru::string::CaseInsensitiveCompare(node->GetTag(), "StyleRuleSet") == 0;
-}
-
std::shared_ptr<ui::style::StyleRuleSet> StyleRuleSetMapper::DoMapFromXml(
xml::XmlElementNode* node) {
auto style_rule_mapper =
diff --git a/src/ui/mapper/style/StylerMapper.cpp b/src/ui/mapper/style/StylerMapper.cpp
new file mode 100644
index 00000000..f48b4d61
--- /dev/null
+++ b/src/ui/mapper/style/StylerMapper.cpp
@@ -0,0 +1,127 @@
+#include "cru/ui/mapper/style/StylerMapper.h"
+#include "cru/base/ClonePtr.h"
+#include "cru/base/xml/XmlNode.h"
+#include "cru/ui/mapper/MapperRegistry.h"
+#include "cru/ui/style/ApplyBorderStyleInfo.h"
+#include "cru/ui/style/Styler.h"
+
+namespace cru::ui::mapper::style {
+ClonePtr<BorderStyler> BorderStylerMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto border_style_mapper =
+ MapperRegistry::GetInstance()->GetMapper<ApplyBorderStyleInfo>();
+
+ ApplyBorderStyleInfo border_style;
+
+ for (auto child : node->GetChildren()) {
+ if (child->GetType() == xml::XmlElementNode::Type::Element) {
+ auto child_element = child->AsElement();
+ if (border_style_mapper->XmlElementIsOfThisType(child_element)) {
+ border_style = border_style_mapper->MapFromXml(child_element);
+ }
+ }
+ }
+
+ return BorderStyler::Create(std::move(border_style));
+}
+
+ClonePtr<ui::style::ContentBrushStyler> ContentBrushStylerMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto brush_mapper = MapperRegistry::GetInstance()
+ ->GetSharedPtrMapper<platform::graphics::IBrush>();
+
+ std::shared_ptr<platform::graphics::IBrush> brush;
+
+ for (auto child_node : node->GetChildren()) {
+ if (child_node->IsElementNode()) {
+ brush = brush_mapper->MapFromXml(child_node->AsElement());
+ }
+ }
+
+ return ui::style::ContentBrushStyler::Create(std::move(brush));
+}
+
+ClonePtr<ui::style::CursorStyler> CursorStylerMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto cursor_mapper = MapperRegistry::GetInstance()
+ ->GetSharedPtrMapper<platform::gui::ICursor>();
+ std::shared_ptr<platform::gui::ICursor> cursor;
+
+ for (auto child : node->GetChildren()) {
+ if (child->GetType() == xml::XmlNode::Type::Element &&
+ cursor_mapper->XmlElementIsOfThisType(child->AsElement())) {
+ cursor = cursor_mapper->MapFromXml(child->AsElement());
+ }
+ }
+
+ return ui::style::CursorStyler::Create(cursor);
+}
+
+ClonePtr<ui::style::FontStyler> FontStylerMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto font_mapper = MapperRegistry::GetInstance()
+ ->GetSharedPtrMapper<platform::graphics::IFont>();
+
+ std::shared_ptr<platform::graphics::IFont> font;
+
+ for (auto child_node : node->GetChildren()) {
+ if (child_node->IsElementNode()) {
+ font = font_mapper->MapFromXml(child_node->AsElement());
+ }
+ }
+
+ return ui::style::FontStyler::Create(std::move(font));
+}
+
+ClonePtr<ui::style::MarginStyler> MarginStylerMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ Thickness thickness;
+
+ auto thickness_mapper = MapperRegistry::GetInstance()->GetMapper<Thickness>();
+
+ auto value_attribute =
+ node->GetOptionalAttributeValueCaseInsensitive("value");
+ if (value_attribute) {
+ thickness = thickness_mapper->MapFromString(*value_attribute);
+ }
+
+ return ui::style::MarginStyler::Create(thickness);
+}
+
+ClonePtr<ui::style::PaddingStyler> PaddingStylerMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ Thickness thickness;
+
+ auto thickness_mapper = MapperRegistry::GetInstance()->GetMapper<Thickness>();
+
+ auto value_attribute =
+ node->GetOptionalAttributeValueCaseInsensitive("value");
+ if (value_attribute) {
+ thickness = thickness_mapper->MapFromString(*value_attribute);
+ }
+
+ return ui::style::PaddingStyler::Create(thickness);
+}
+
+ClonePtr<ui::style::PreferredSizeStyler>
+PreferredSizeStylerMapper::DoMapFromXml(xml::XmlElementNode* node) {
+ render::MeasureSize size;
+
+ auto measure_length_mapper =
+ MapperRegistry::GetInstance()->GetMapper<render::MeasureLength>();
+
+ auto width_attribute =
+ node->GetOptionalAttributeValueCaseInsensitive("width");
+ if (width_attribute) {
+ size.width = measure_length_mapper->MapFromString(*width_attribute);
+ }
+
+ auto height_attribute =
+ node->GetOptionalAttributeValueCaseInsensitive("height");
+ if (height_attribute) {
+ size.height = measure_length_mapper->MapFromString(*height_attribute);
+ }
+
+ return ui::style::PreferredSizeStyler::Create(size);
+}
+} // namespace cru::ui::mapper::style