aboutsummaryrefslogtreecommitdiff
path: root/src/ui/mapper
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-02-26 20:12:54 +0800
committercrupest <crupest@outlook.com>2022-02-26 20:12:54 +0800
commit673f1939beb1b477a23d9641a07a2e05fff903b4 (patch)
tree048ba6b4eab749266d8e2ec05df182bedcf3499f /src/ui/mapper
parent65e288c40a593965b41378755f7111c56e123295 (diff)
downloadcru-673f1939beb1b477a23d9641a07a2e05fff903b4.tar.gz
cru-673f1939beb1b477a23d9641a07a2e05fff903b4.tar.bz2
cru-673f1939beb1b477a23d9641a07a2e05fff903b4.zip
...
Diffstat (limited to 'src/ui/mapper')
-rw-r--r--src/ui/mapper/Mapper.cpp9
-rw-r--r--src/ui/mapper/MapperRegistry.cpp4
-rw-r--r--src/ui/mapper/style/MarginStylerMapper.cpp24
-rw-r--r--src/ui/mapper/style/PaddingStylerMapper.cpp26
4 files changed, 63 insertions, 0 deletions
diff --git a/src/ui/mapper/Mapper.cpp b/src/ui/mapper/Mapper.cpp
index 40653118..ebf880a2 100644
--- a/src/ui/mapper/Mapper.cpp
+++ b/src/ui/mapper/Mapper.cpp
@@ -5,4 +5,13 @@
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 (node->GetTag().CaseInsensitiveEqual(tag)) {
+ return true;
+ }
+ }
+ return false;
+}
} // namespace cru::ui::mapper
diff --git a/src/ui/mapper/MapperRegistry.cpp b/src/ui/mapper/MapperRegistry.cpp
index 9ae95a59..ad5b7e8d 100644
--- a/src/ui/mapper/MapperRegistry.cpp
+++ b/src/ui/mapper/MapperRegistry.cpp
@@ -16,8 +16,10 @@
#include "cru/ui/mapper/style/CursorStylerMapper.h"
#include "cru/ui/mapper/style/FocusConditionMapper.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/StyleRuleMapper.h"
#include "cru/ui/mapper/style/StyleRuleSetMapper.h"
@@ -48,8 +50,10 @@ MapperRegistry::MapperRegistry() {
RegisterMapper(new CursorStylerMapper());
RegisterMapper(new FocusConditionMapper());
RegisterMapper(new HoverConditionMapper());
+ RegisterMapper(new MarginStylerMapper());
RegisterMapper(new NoConditionMapper());
RegisterMapper(new OrConditionMapper());
+ RegisterMapper(new PaddingStylerMapper());
RegisterMapper(new PreferredSizeStylerMapper());
RegisterMapper(new StyleRuleMapper());
RegisterMapper(new StyleRuleSetMapper());
diff --git a/src/ui/mapper/style/MarginStylerMapper.cpp b/src/ui/mapper/style/MarginStylerMapper.cpp
new file mode 100644
index 00000000..cb2fd7ee
--- /dev/null
+++ b/src/ui/mapper/style/MarginStylerMapper.cpp
@@ -0,0 +1,24 @@
+#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({u"MarginStyler"}); }
+
+MarginStylerMapper::~MarginStylerMapper() {}
+
+ClonablePtr<ui::style::MarginStyler> MarginStylerMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ Thickness thickness;
+
+ auto thickness_mapper = MapperRegistry::GetInstance()->GetMapper<Thickness>();
+
+ auto value_attribute = node->GetOptionalAttributeCaseInsensitive(u"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/PaddingStylerMapper.cpp b/src/ui/mapper/style/PaddingStylerMapper.cpp
new file mode 100644
index 00000000..cd316cd2
--- /dev/null
+++ b/src/ui/mapper/style/PaddingStylerMapper.cpp
@@ -0,0 +1,26 @@
+#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({u"PaddingStyler"});
+}
+
+PaddingStylerMapper::~PaddingStylerMapper() {}
+
+ClonablePtr<ui::style::PaddingStyler> PaddingStylerMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ Thickness thickness;
+
+ auto thickness_mapper = MapperRegistry::GetInstance()->GetMapper<Thickness>();
+
+ auto value_attribute = node->GetOptionalAttributeCaseInsensitive(u"value");
+ if (value_attribute) {
+ thickness = thickness_mapper->MapFromString(*value_attribute);
+ }
+
+ return ui::style::PaddingStyler::Create(thickness);
+}
+} // namespace cru::ui::mapper::style