aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/common/String.hpp6
-rw-r--r--include/cru/ui/mapper/Mapper.hpp5
-rw-r--r--include/cru/ui/mapper/MapperRegistry.hpp5
-rw-r--r--include/cru/ui/mapper/style/BorderStylerMapper.hpp21
-rw-r--r--include/cru/ui/style/Styler.hpp5
-rw-r--r--src/ui/CMakeLists.txt1
-rw-r--r--src/ui/mapper/style/BorderStylerMapper.cpp34
7 files changed, 76 insertions, 1 deletions
diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp
index 5891e929..22d68980 100644
--- a/include/cru/common/String.hpp
+++ b/include/cru/common/String.hpp
@@ -226,6 +226,9 @@ class CRU_BASE_API String {
int Compare(const String& other) const;
int CaseInsensitiveCompare(const String& other) const;
+ bool CaseInsensitiveEqual(const String& other) const {
+ return CaseInsensitiveCompare(other) == 0;
+ }
private:
static char16_t kEmptyBuffer[1];
@@ -310,6 +313,9 @@ class CRU_BASE_API StringView {
public:
int Compare(const StringView& other) const;
int CaseInsensitiveCompare(const StringView& other) const;
+ bool CaseInsensitiveEqual(const StringView& other) const {
+ return CaseInsensitiveCompare(other) == 0;
+ }
String ToString() const { return String(ptr_, size_); }
diff --git a/include/cru/ui/mapper/Mapper.hpp b/include/cru/ui/mapper/Mapper.hpp
index 4e5499d0..5febb26e 100644
--- a/include/cru/ui/mapper/Mapper.hpp
+++ b/include/cru/ui/mapper/Mapper.hpp
@@ -1,7 +1,7 @@
#pragma once
-
#include "../Base.hpp"
+#include "cru/common/ClonablePtr.hpp"
#include "cru/common/Exception.hpp"
#include "cru/xml/XmlNode.hpp"
@@ -85,4 +85,7 @@ class CRU_UI_API BasicMapper : public MapperBase {
template <typename T>
using BasicRefMapper = BasicMapper<std::shared_ptr<T>>;
+
+template <typename T>
+using BasicPtrMapper = BasicMapper<ClonablePtr<T>>;
} // namespace cru::ui::mapper
diff --git a/include/cru/ui/mapper/MapperRegistry.hpp b/include/cru/ui/mapper/MapperRegistry.hpp
index 55051ba9..c3e5b4c4 100644
--- a/include/cru/ui/mapper/MapperRegistry.hpp
+++ b/include/cru/ui/mapper/MapperRegistry.hpp
@@ -34,6 +34,11 @@ class CRU_UI_API MapperRegistry {
return GetMapper<std::shared_ptr<T>>();
}
+ template <typename T>
+ BasicPtrMapper<T>* GetPtrMapper() const {
+ return GetMapper<ClonablePtr<T>>();
+ }
+
void RegisterMapper(MapperBase* mapper);
void UnregisterMapper(MapperBase* mapper);
diff --git a/include/cru/ui/mapper/style/BorderStylerMapper.hpp b/include/cru/ui/mapper/style/BorderStylerMapper.hpp
new file mode 100644
index 00000000..6c967bed
--- /dev/null
+++ b/include/cru/ui/mapper/style/BorderStylerMapper.hpp
@@ -0,0 +1,21 @@
+#pragma once
+#include "../Mapper.hpp"
+#include "cru/common/ClonablePtr.hpp"
+#include "cru/ui/style/Styler.hpp"
+#include "cru/xml/XmlNode.hpp"
+
+namespace cru::ui::mapper::style {
+class CRU_UI_API BorderStylerMapper
+ : public BasicPtrMapper<ui::style::BorderStyler> {
+ public:
+ CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(BorderStylerMapper)
+
+ public:
+ bool SupportMapFromXml() override { return true; }
+ bool XmlElementIsOfThisType(xml::XmlElementNode* node) override;
+
+ protected:
+ ClonablePtr<ui::style::BorderStyler> DoMapFromXml(
+ xml::XmlElementNode* node) override;
+};
+} // namespace cru::ui::mapper::style
diff --git a/include/cru/ui/style/Styler.hpp b/include/cru/ui/style/Styler.hpp
index 865cbbaf..721a3bfd 100644
--- a/include/cru/ui/style/Styler.hpp
+++ b/include/cru/ui/style/Styler.hpp
@@ -44,10 +44,15 @@ class CompoundStyler : public Styler {
class BorderStyler : public Styler {
public:
+ static ClonablePtr<BorderStyler> Create() {
+ return ClonablePtr<BorderStyler>(new BorderStyler());
+ }
+
static ClonablePtr<BorderStyler> Create(ApplyBorderStyleInfo style) {
return ClonablePtr<BorderStyler>(new BorderStyler(std::move(style)));
}
+ BorderStyler() = default;
explicit BorderStyler(ApplyBorderStyleInfo style);
void Apply(controls::Control* control) const override;
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 4353a541..f13f4983 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -35,6 +35,7 @@ add_library(cru_ui SHARED
mapper/PointMapper.cpp
mapper/SizeMapper.cpp
mapper/ThicknessMapper.cpp
+ mapper/style/BorderStylerMapper.cpp
render/BorderRenderObject.cpp
render/CanvasRenderObject.cpp
render/FlexLayoutRenderObject.cpp
diff --git a/src/ui/mapper/style/BorderStylerMapper.cpp b/src/ui/mapper/style/BorderStylerMapper.cpp
new file mode 100644
index 00000000..8a5df83d
--- /dev/null
+++ b/src/ui/mapper/style/BorderStylerMapper.cpp
@@ -0,0 +1,34 @@
+#include "cru/ui/mapper/style/BorderStylerMapper.hpp"
+#include "cru/common/ClonablePtr.hpp"
+#include "cru/ui/mapper/MapperRegistry.hpp"
+#include "cru/ui/style/ApplyBorderStyleInfo.hpp"
+#include "cru/ui/style/Styler.hpp"
+#include "cru/xml/XmlNode.hpp"
+
+namespace cru::ui::mapper::style {
+using cru::ui::style::ApplyBorderStyleInfo;
+using cru::ui::style::BorderStyler;
+
+bool BorderStylerMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
+ return node->GetTag().CaseInsensitiveEqual(u"BorderStyler");
+}
+
+ClonablePtr<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