aboutsummaryrefslogtreecommitdiff
path: root/src/ui/mapper
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/mapper')
-rw-r--r--src/ui/mapper/ColorMapper.cpp2
-rw-r--r--src/ui/mapper/style/BorderStyleMapper.cpp56
2 files changed, 57 insertions, 1 deletions
diff --git a/src/ui/mapper/ColorMapper.cpp b/src/ui/mapper/ColorMapper.cpp
index be633a86..e17352e1 100644
--- a/src/ui/mapper/ColorMapper.cpp
+++ b/src/ui/mapper/ColorMapper.cpp
@@ -2,7 +2,7 @@
namespace cru::ui::mapper {
bool ColorMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return node->GetTag() == u"color";
+ return node->GetTag() == u"Color";
}
std::unique_ptr<Color> ColorMapper::DoMapFromString(String str) {
diff --git a/src/ui/mapper/style/BorderStyleMapper.cpp b/src/ui/mapper/style/BorderStyleMapper.cpp
new file mode 100644
index 00000000..0dc8a05f
--- /dev/null
+++ b/src/ui/mapper/style/BorderStyleMapper.cpp
@@ -0,0 +1,56 @@
+#include "cru/ui/mapper/style/BorderStyleMapper.hpp"
+#include "../../Helper.hpp"
+#include "cru/common/Logger.hpp"
+#include "cru/platform/graphics/Factory.hpp"
+#include "cru/ui/mapper/MapperRegistry.hpp"
+#include "cru/ui/style/ApplyBorderStyleInfo.hpp"
+#include "cru/xml/XmlNode.hpp"
+
+namespace cru::ui::mapper::style {
+using namespace xml;
+using ui::style::ApplyBorderStyleInfo;
+
+bool BorderStyleMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
+ return node->GetTag() == u"BorderStyle";
+}
+
+std::unique_ptr<ApplyBorderStyleInfo> BorderStyleMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto result = std::make_unique<ApplyBorderStyleInfo>();
+
+ for (auto child : node->GetChildren()) {
+ if (child->GetType() == XmlNode::Type::Text) {
+ log::Debug(u"Ignore text node.");
+ } else {
+ auto c = child->AsElement();
+ auto thickness_mapper =
+ MapperRegistry::GetInstance()->GetMapper<Thickness>();
+ auto corner_radius_mapper =
+ MapperRegistry::GetInstance()->GetMapper<CornerRadius>();
+ auto color_mapper = MapperRegistry::GetInstance()->GetMapper<Color>();
+ if (thickness_mapper->XmlElementIsOfThisType(c)) {
+ result->border_thickness = *thickness_mapper->MapFromXml(c);
+ } else if (corner_radius_mapper->XmlElementIsOfThisType(c)) {
+ result->border_radius = *corner_radius_mapper->MapFromXml(c);
+ } else if (color_mapper->XmlElementIsOfThisType(c)) {
+ auto brush = GetGraphicsFactory()->CreateSolidColorBrush(
+ *color_mapper->MapFromXml(c));
+ auto name = c->GetOptionalAttribute(u"name");
+ if (name) {
+ if (name == u"foreground") {
+ result->foreground_brush = std::move(brush);
+ } else if (name == u"background") {
+ result->background_brush = std::move(brush);
+ } else {
+ log::Debug(u"Unknown brush name: {}", *name);
+ }
+ } else {
+ result->border_brush = std::move(brush);
+ }
+ }
+ }
+ }
+
+ return result;
+}
+} // namespace cru::ui::mapper::style