aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/CMakeLists.txt2
-rw-r--r--src/ui/mapper/MapperRegistry.cpp26
-rw-r--r--src/ui/mapper/style/StyleRuleMapper.cpp54
-rw-r--r--src/ui/mapper/style/StyleRuleSetMapper.cpp35
4 files changed, 117 insertions, 0 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index fc2ef76b..47197569 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -42,6 +42,8 @@ add_library(cru_ui SHARED
mapper/style/FocusConditionMapper.cpp
mapper/style/NoConditionMapper.cpp
mapper/style/OrConditionMapper.cpp
+ mapper/style/StyleRuleMapper.cpp
+ mapper/style/StyleRuleSetMapper.cpp
render/BorderRenderObject.cpp
render/CanvasRenderObject.cpp
render/FlexLayoutRenderObject.cpp
diff --git a/src/ui/mapper/MapperRegistry.cpp b/src/ui/mapper/MapperRegistry.cpp
index 206d1d32..d7131e33 100644
--- a/src/ui/mapper/MapperRegistry.cpp
+++ b/src/ui/mapper/MapperRegistry.cpp
@@ -1,17 +1,43 @@
#include "cru/ui/mapper/MapperRegistry.hpp"
+#include "cru/ui/mapper/BorderStyleMapper.hpp"
+#include "cru/ui/mapper/ColorMapper.hpp"
#include "cru/ui/mapper/CornerRadiusMapper.hpp"
+#include "cru/ui/mapper/CursorMapper.hpp"
#include "cru/ui/mapper/PointMapper.hpp"
#include "cru/ui/mapper/SizeMapper.hpp"
#include "cru/ui/mapper/ThicknessMapper.hpp"
+#include "cru/ui/mapper/style/AndConditionMapper.hpp"
+#include "cru/ui/mapper/style/BorderStylerMapper.hpp"
+#include "cru/ui/mapper/style/ClickStateConditionMapper.hpp"
+#include "cru/ui/mapper/style/CursorStylerMapper.hpp"
+#include "cru/ui/mapper/style/FocusConditionMapper.hpp"
+#include "cru/ui/mapper/style/NoConditionMapper.hpp"
+#include "cru/ui/mapper/style/OrConditionMapper.hpp"
+#include "cru/ui/mapper/style/StyleRuleMapper.hpp"
+#include "cru/ui/mapper/style/StyleRuleSetMapper.hpp"
namespace cru::ui::mapper {
MapperRegistry *MapperRegistry::GetInstance() {
static MapperRegistry instance;
+ using namespace style;
+
instance.RegisterMapper(new CornerRadiusMapper());
instance.RegisterMapper(new PointMapper());
instance.RegisterMapper(new SizeMapper());
instance.RegisterMapper(new ThicknessMapper());
+ instance.RegisterMapper(new BorderStyleMapper());
+ instance.RegisterMapper(new ColorMapper());
+ instance.RegisterMapper(new CursorMapper());
+ instance.RegisterMapper(new AndConditionMapper());
+ instance.RegisterMapper(new BorderStylerMapper());
+ instance.RegisterMapper(new ClickStateConditionMapper());
+ instance.RegisterMapper(new CursorStylerMapper());
+ instance.RegisterMapper(new FocusConditionMapper());
+ instance.RegisterMapper(new NoConditionMapper());
+ instance.RegisterMapper(new OrConditionMapper());
+ instance.RegisterMapper(new StyleRuleMapper());
+ instance.RegisterMapper(new StyleRuleSetMapper());
return &instance;
}
diff --git a/src/ui/mapper/style/StyleRuleMapper.cpp b/src/ui/mapper/style/StyleRuleMapper.cpp
new file mode 100644
index 00000000..fea102ed
--- /dev/null
+++ b/src/ui/mapper/style/StyleRuleMapper.cpp
@@ -0,0 +1,54 @@
+#include "cru/ui/mapper/style/StyleRuleMapper.hpp"
+#include "cru/common/ClonablePtr.hpp"
+#include "cru/ui/mapper/MapperRegistry.hpp"
+#include "cru/ui/mapper/style/IConditionMapper.hpp"
+#include "cru/ui/mapper/style/IStylerMapper.hpp"
+#include "cru/ui/style/Condition.hpp"
+#include "cru/ui/style/StyleRule.hpp"
+#include "cru/ui/style/Styler.hpp"
+
+namespace cru::ui::mapper::style {
+using namespace ui::style;
+bool StyleRuleMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
+ return node->GetTag().CaseInsensitiveEqual(u"StyleRule");
+}
+
+ClonablePtr<ui::style::StyleRule> StyleRuleMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ std::vector<IConditionMapper*> condition_mappers =
+ MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>();
+ std::vector<IStylerMapper*> styler_mappers =
+ MapperRegistry::GetInstance()->GetMappersByInterface<IStylerMapper>();
+
+ std::vector<ClonablePtr<Condition>> conditions;
+ std::vector<ClonablePtr<Styler>> stylers;
+
+ for (auto child : node->GetChildren()) {
+ if (child->GetType() == xml::XmlNode::Type::Element) {
+ auto c = child->AsElement();
+
+ bool resolved = false;
+ for (auto condition_mapper : condition_mappers) {
+ if (condition_mapper->XmlElementIsOfThisType(c)) {
+ conditions.push_back(condition_mapper->MapConditionFromXml(c));
+ resolved = true;
+ break;
+ }
+ }
+
+ if (!resolved) {
+ for (auto styler_mapper : styler_mappers) {
+ if (styler_mapper->XmlElementIsOfThisType(c)) {
+ stylers.push_back(styler_mapper->MapStylerFromXml(c));
+ resolved = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ return StyleRule::Create(AndCondition::Create(std::move(conditions)),
+ CompoundStyler::Create(std::move(stylers)));
+}
+} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/StyleRuleSetMapper.cpp b/src/ui/mapper/style/StyleRuleSetMapper.cpp
new file mode 100644
index 00000000..b9199d27
--- /dev/null
+++ b/src/ui/mapper/style/StyleRuleSetMapper.cpp
@@ -0,0 +1,35 @@
+#include "cru/ui/mapper/style/StyleRuleSetMapper.hpp"
+#include <memory>
+#include "cru/ui/mapper/MapperRegistry.hpp"
+#include "cru/ui/style/StyleRule.hpp"
+#include "cru/ui/style/StyleRuleSet.hpp"
+
+namespace cru::ui::mapper::style {
+using namespace cru::ui::style;
+
+bool StyleRuleSetMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
+ return node->GetTag().CaseInsensitiveEqual(u"StyleRuleSet");
+}
+
+std::shared_ptr<ui::style::StyleRuleSet> StyleRuleSetMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto style_rule_mapper =
+ MapperRegistry::GetInstance()->GetPtrMapper<StyleRule>();
+
+ auto result = std::make_shared<StyleRuleSet>();
+
+ for (auto child : node->GetChildren()) {
+ if (child->GetType() == xml::XmlNode::Type::Element) {
+ auto c = child->AsElement();
+ if (style_rule_mapper->XmlElementIsOfThisType(c)) {
+ auto style_rule = style_rule_mapper->MapFromXml(c);
+ result->AddStyleRule(*style_rule);
+ } else {
+ throw Exception(u"StyleRuleSet can only contain StyleRule.");
+ }
+ }
+ }
+
+ return result;
+}
+} // namespace cru::ui::mapper::style