aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-12-15 21:27:33 +0800
committerYuqian Yang <crupest@crupest.life>2025-12-15 21:27:33 +0800
commitc77072d586bf7aca58e6465ceab3d11a0be0021f (patch)
tree83605be90fd32104ef74bbd1d84d900aaf0271ce /src
parentbc3fa9650699046f3a87a620282ee43f26b2fa75 (diff)
downloadcru-c77072d586bf7aca58e6465ceab3d11a0be0021f.tar.gz
cru-c77072d586bf7aca58e6465ceab3d11a0be0021f.tar.bz2
cru-c77072d586bf7aca58e6465ceab3d11a0be0021f.zip
Clean up mapper codes.
Diffstat (limited to 'src')
-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
33 files changed, 281 insertions, 507 deletions
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