aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/CMakeLists.txt2
-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
-rw-r--r--src/ui/style/Styler.cpp8
6 files changed, 73 insertions, 0 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index e02ad9da..e3819800 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -45,8 +45,10 @@ add_library(cru_ui SHARED
mapper/style/CursorStylerMapper.cpp
mapper/style/FocusConditionMapper.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/StyleRuleMapper.cpp
mapper/style/StyleRuleSetMapper.cpp
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
diff --git a/src/ui/style/Styler.cpp b/src/ui/style/Styler.cpp
index 7085fd3e..44a24462 100644
--- a/src/ui/style/Styler.cpp
+++ b/src/ui/style/Styler.cpp
@@ -30,4 +30,12 @@ void CursorStyler::Apply(controls::Control *control) const {
void PreferredSizeStyler::Apply(controls::Control *control) const {
control->SetPreferredSize(size_);
}
+
+void MarginStyler::Apply(controls::Control *control) const {
+ control->SetMargin(margin_);
+}
+
+void PaddingStyler::Apply(controls::Control *control) const {
+ control->SetPadding(padding_);
+}
} // namespace cru::ui::style